WinRT RemovableDevices: Music folder: Cannot create items within this StorageFolder

242 views Asked by At

I am trying to use WinRT to synchronize my music collection from a NAS system to my Windows Phone device. To create a folder in the Music folder on the phone I use the following snippet:

StorageFolder DeviceFolder = ( await KnownFolders.RemovableDevices.GetFoldersAsync() ).FirstOrDefault( a => a.Name == "zeroskyx-lumia" );
StorageFolder PhoneMusicFolder = await DeviceFolder.GetFolderAsync( @"Phone\Music" );
await DeviceFolder.CreateFolderAsync( @"Phone\Music\Test" );

I expect to get the new folder "Test" created in Phone\Music. However the following exception is thrown:

System.AggregateException: One or more errors occurred. ---> System.Runtime.InteropServices.COMException: Unspecified error Cannot create items within this StorageFolder. This could be encountered if the folder was obtained by creating a query using grouping options.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

When I create a folder in Phone\Music manually and then use the snippet to create a subdirectory in that folder, the operation succeeds (so there is no missing WinRT broker manifest issue).

Has anybody encountered the same issue as well? What am I doing wrong here?

Best regards and thanks in advance

-Simon

1

There are 1 answers

0
hoffmann.matheus On

As far as I know, Windows API does not allow you to issue a folder creation passing a 'full path', eg. "create\all\these\subfolders\for\me" (a "mkdir -p" linux equivalent).

To make your code snippet work, you need to first get the StorageFolder that represents the "Phone/Music" subfolder, and issue the folder creation from there, like:

StorageFolder DeviceFolder = ( await KnownFolders.RemovableDevices.GetFoldersAsync() ).FirstOrDefault( a => a.Name == "zeroskyx-lumia" );
StorageFolder PhoneMusicFolder = await DeviceFolder.GetFolderAsync( @"Phone\Music" );
await PhoneMusicFolder.CreateFolderAsync( "Test" );