Reputation: 133
I saw some people already asking similar questions here, but non of the answers seem to work in my case. I'm creating software as my final assignment that would generate a lot of different project folders and files and I wish to store them in Documents folder so users can access it easily.
I have added the "documents" in the manifest file:
<Capabilities>
<Capability Name="internetClient" />
<uap:Capability Name="documentsLibrary"/>
And so far I was trying to accomplish folder creation with following code:
var appFolder = await KnownFolders.DocumentsLibrary.GetFolderAsync("Project_1");
if (appFolder == null)
{
appFolder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("Project_1");
}
But the debugging tool gives me an error that the Documents folder is possibly read-only.
I guess that when this code would successfully create folder, I can also add slashes to create subfolder of subfolder, right?
Sorry if maybe I'm asking stupid question, I know how to do all these stuff in form / wpf app, but I really wish to see how UWP works and I love the idea of running on multiple devices.
Thanks for all your time and help in advance!
Upvotes: 0
Views: 546
Reputation: 29792
DocumentsLibrary is a very special/restricted capability, also AFAIK you will have to make a special request to publish the app to the store with it. Generally you can access only files that your app has association with (not sure if folder creation is included). Also, your app will have to fulfill special requirements:
To use the documentsLibrary special capability, an app must:
Facilitate cross-platform offline access to specific OneDrive content using valid OneDrive URLs or Resource IDs
Save open files to the user’s OneDrive automatically while offline
Read also more at DocumentsLibrary at MSDN.
Maybe better would be to allow the user to pick a folder first with the picker and then save that in FutureAccessList or MostRecentlyUsed for further access. In such folder you have full privileges as user allows for that (not sure but maybe he can also choose folder in Documents).
As a side note - instead of your code and null check, you can use:
await yourFolder.CreateFolderAsync("Project_1", CreationCollisionOption.OpenIfExists);
Upvotes: 1