As Im still very much a beginner, Im having some trouble trying to get the FileSavePicker to work. Essentially, I don't see how you code the source of your file. Ive downloaded a sample, but the sample doesnt contain a real example...its not coded to save an actual file. So its not helping me much. Ive obtain a little help from MSDN, but still stuck. The Save To option comes up in my app, but when I save the file, its basically blank. Shows as 0 bytes.
So obviously I am not coding the source of the file to be saved correctly. The bold parts below is where I thought id put the code for the file source but its not right at all
So obviously I am not coding the source of the file to be saved correctly. The bold parts below is where I thought id put the code for the file source but its not right at all
Code:
namespace xxxxxx.ViewModels
{
public class SoundData : ViewModelBase
{
public string Title { get; set; }
public string FilePath { get; set; }
public RelayCommand<string> SaveSoundAs { get; set; }
private void ExecuteSaveSoundAs(string soundPath)
{
App.Current.RootVisual.Dispatcher.BeginInvoke(() =>
{
FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation = PickerLocationId.Downloads;
savePicker.FileTypeChoices.Add("MP3", new List<string>() { ".mp3" });
[B]savePicker.ContinuationData.Add("appdata:/x.mp3", soundPath);[/B]
savePicker.PickSaveFileAndContinue();
}
);
}
public async void ContinueFileSavePicker(FileSavePickerContinuationEventArgs args)
{
[B]string soundPath = (string)args.ContinuationData["SourceSound"];[/B]
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);
}
}
}