So Im now told that the FileSavePicker only creates a blank file, and that Ill have to write additional code to then actually write to the file. Ive started a Task WriteToFile after the FileSavePicker but Im unsure how to finish it. With the FileSavePicker, the user selects the folder they wish to save the file to. Where do I point to that in the WriteToFile code and how exactly do I put the file source in it? The files to be saved are all packaged with the app. Im using x.mp3 as an example here.
public class SoundData : ViewModelBase
{
public string Title { get; set; }
public string FilePath { get; set; }
public RelayCommand<string> SaveSoundAs { get; set; }
private async void ExecuteSaveSoundAs(string soundPath)
{
string path = @"appdata:/x.mp3";
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await folder.GetFileAsync(path);
{
FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedSaveFile = file;
savePicker.FileTypeChoices.Add("MP3", new List<string>() { ".mp3" });
savePicker.ContinuationData.Add("SourceSound", soundPath);
savePicker.SuggestedFileName = this.Title;
savePicker.PickSaveFileAndContinue();
}
}
public async void ContinueFileSavePicker(FileSavePickerContinuationEventArgs args)
{
string soundPath = (string)args.ContinuationData["SourceSound"];
StorageFile file = args.File;
if (file != null)
{
// Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
CachedFileManager.DeferUpdates(file);
// write to file
await FileIO.WriteTextAsync(file, file.Name);
// Let Windows know that we're finished changing the file so the other app can update the remote version of the file.
// Completing updates may require Windows to ask for user input.
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
if (status == FileUpdateStatus.Complete) ;
}
}
public SoundData()
{
SaveSoundAs = new RelayCommand<string>(ExecuteSaveSoundAs);
}
}
}