I tried this below code, the audio file is saving but it shows 0 bytes, I tried a lot if any one know about this please help me...
WP8.1 Universal Apps
Code in Mainpage.cs:
private async void pick_Click(object sender, RoutedEventArgs e)
{
string path = @"Assets\Audio\DeviPrasad.mp3";
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await folder.GetFileAsync(path);
var st =await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
var size = st.Size;
FileSavePicker savePicker = new FileSavePicker();
//savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
savePicker.SuggestedSaveFile = file;
savePicker.FileTypeChoices.Add("MP3", new List<string>() { ".mp3" });
savePicker.ContinuationData.Add("SourceSound", path);
savePicker.SuggestedFileName = "DeviPrasad";
savePicker.PickSaveFileAndContinue();
}
internal async void ContinueFileOpenPicker(FileSavePickerContinuationEventArgs e)
{
var file = e.File;
var ff= file.Properties;
if(file!=null)
{
CachedFileManager.DeferUpdates(file);
await FileIO.WriteTextAsync(file, file.Name);
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
}
}
Code In App.xaml.cs:
protected async override void OnActivated(IActivatedEventArgs args)
{
var root = Window.Current.Content as Frame;
var mainPage = root.Content as MainPage;
if (mainPage != null && args is FileSavePickerContinuationEventArgs)
{
mainPage.ContinueFileOpenPicker(args as FileSavePickerContinuationEventArgs);
}
}
The FileSavePicker will not help you to write or copy the content of the file to the destination.
Actually, I think you just simply copy the following code from somewhere but don't exactly know what it is doing.
await FileIO.WriteTextAsync(file, file.Name);
This is to write things to the file, and seems it is from a sample which handles txt file. For your case, we need to do the following things:
Add the source file path to ContinuationData in pick_Click event. Change the code to: savePicker.ContinuationData.Add("SourceSound", file.Path);
Read the source file path and destination file in ContinueFileOpenPicker to write the content as below:
var file = e.File; string soundPath = (string)e.ContinuationData["SourceSound"]; //var ff = file.Properties; if (file != null) { CachedFileManager.DeferUpdates(file); StorageFile srcFile = await StorageFile.GetFileFromPathAsync(soundPath); await srcFile.CopyAndReplaceAsync(file); FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.