The method should save the mp3 file from the installed package to the user folder using FileSavePicker . Previously, as in the examples, I use GetFileAsync , which takes a file path as a parameter in order to specify which file to save. After the method starts, the application stops at:

 StorageFile file = await folder.GetFileAsync(path); 

The error code indicates that the parameter is set incorrectly.

 private async void pause_Click(object sender, RoutedEventArgs e) { string path = "Assets/Sounds/news.mp3"; StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation; StorageFile file = await folder.GetFileAsync(path); var savePicker = new FileSavePicker(); savePicker.SuggestedSaveFile = file; savePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary; savePicker.FileTypeChoices.Add("SoundFile",new List<string>() { ".mp3" }); savePicker.SuggestedFileName = "SoundFile"; StorageFile newRingtone = await savePicker.PickSaveFileAsync(); if (newRingtone !=null) ... } 

I do not quite understand what is wrong with the path to the file. Or do I misunderstand the essence of the tool and need to use some other?

  • one
    Maybe it expects backslash? Or maybe there is no such file. Give an exact exception and information from it. - VladD 4:03 pm
  • 2
    How about "Assets\Sounds\news.mp3" ? - andreycha
  • 2
    @andreycha, forgot @ or escape slashes :) - Grundy
  • 2
    @Grundy would guess. - andreycha
  • one
    Are you sure that in the second case an exception occurs in the same line? Wangoo, that crashes when you try to write a file to the directory where the application is installed (you can't go there, of course, it's like writing to Program Files on the desktop). - VladD

1 answer 1

First of all, if your question is related to an error, you must do the following:

  1. Reproduce the error, i.e. dwell on it in debugging.
  2. Open the Watch debug window and add the following request to it:

    new System.Diagnostics.StackTrace().ToString()

  3. From the Value field, take the result of the execution and offer it to the public; something like this should turn out:

Stack:

 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at AIStorePortableService1.CFileSystemAsyncWrapper.<GetFileAsync>d__5.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine](TStateMachine& stateMachine) at AIStorePortableService1.CFileSystemAsyncWrapper.GetFileAsync(StorageFolder iFolder, String iFileName) at AIStorePortableService1.CStoreFileSystem.AIPortableService2.IFileSystem.FileDataRead(StorageTypesEnum iStorageType, String iPath) at AIPortableService2.CFileSystem.FileDataRead(StorageTypesEnum iStorageType, String iPath) ... 
  1. Open the Output window in Debug mode and in it at the very bottom look for something like:

Description of the error, it must also be presented to the public:

 Exception thrown: 'System.ArgumentException' in mscorlib.dll Additional information: The parameter is incorrect. WinRT information: An item cannot be found with the specified name (Assets/Sounds/news.mp3). 

Then there will be a lot of debugging and localization of trouble, and in the end it will become clear that in WinRT the relative path must be specified as follows:

 string path = @"Assets\Sounds\news.mp3" 

How to check it without resorting to painful debugging? Yes, very simple. See what the code returns:

 string strPath = System.IO.Path.Combine("Assets", "Sounds", "news.mp3"); 

Going further, you write:

If you specify the path as @ "Assets \ Sounds \ news.mp3", then the error message indicates "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

Are you sure that this error occurs on the same line of code? Isn't that the moment when you try to file FileSavePicker on this file? To write something in this place is really impossible.