1

I'm writing a Windows 8.1 store application and am trying to create a subfolder in the ApplicationData.Current.RoamingFolder directory. There is no data currently stored there. However, the following line throws a System.UnauthorizedAccessException saying "Access is Denied".

var folder = await ApplicationData.Current.RoamingFolder.CreateFolderAsync("subfolder", CreationCollisionOption.OpenIfExists);

Strangely enough, if I use LocalFolder instead of RoamingFolder, the operation succeeds.

var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("subfolder", CreationCollisionOption.OpenIfExists);

Why can't I create a subfolder in the roaming folder? I can manually create the folder via Windows Explorer.

The documentation (link) says that there are limitations on what can be placed in the folder, specifically:

"The sync engine has restrictions on the file name conventions that you must follow to ensure the items in the roaming folder can roam. Be sure that your file and folder names do not contain leading whitespace. The sync engine may limit the total size of settings and files that can roam."

However, I don't see anything that would explain the above exception. What am I missing and what other limitations am I missing about the roaming folder?

Interestingly, if I create a brand-new application both lines of code function perfectly. I don't know why that is.

Edit: As mentioned by Nate, the CreateFolderAsync documentation says "If you try to create a subfolder in a virtual folder like a library or a file group, this method may fail." Does anyone know if that applies here? If it does, what limitations does it introduce? The only information I've found on this issue is this question, but it doesn't seem to firmly resolve the issue.

Community
  • 1
  • 1
Kvothe
  • 467
  • 4
  • 13
  • Your code there seems to be calling `CreateFileAsync` instead of `CreateFolderAsync`. Is it possible that in your test application you are creating a file instead of a folder, while in your main application you are properly using `CreateFolderAsync`? Secondly, as conjecture, I think that it's possible the `RoamingFolder` is a `Virtual Folder`, especially based on the `VirtualStore` folder that I believe it links to. The documentation for [CreateFolderAsync](http://msdn.microsoft.com/en-us/library/windows/apps/br227258.aspx) says that it may fail on `Virtual Folders`. – Nate Diamond Mar 07 '14 at 20:27
  • It should also be noted that the link you provided, under the `Examples` section, does not contain examples for `CreateFolderAsync` or lists it as an available API, so I believe that implies that you cannot do this. – Nate Diamond Mar 07 '14 at 20:28
  • I had accidentally typed `CreateFileAsync` in my question. This is corrected now. I have also confirmed that I was in fact calling `CreateFolderAsync` in my code. – Kvothe Mar 07 '14 at 20:35
  • The link did not explicitly mention that method, but it did mention subfolder names and the rest of the file APIs. It's also worth noting that the LocalFolder documentation was worded similarly even though that piece of code did work correctly. – Kvothe Mar 07 '14 at 20:41
  • That is a good point about the LocalFolder documentation. I guess the only possibility left that I can see is that the RoamingFolder is a VirtualFolder. I wonder if there is a way to test this. Possibly via folder properties? – Nate Diamond Mar 07 '14 at 20:54
  • There is nothing preventing you from creating folders in the roaming folder by default. Are you sitting on a domain with restrictions upon the roaming folder? Somehow something has restricted your access to the roaming folder. – Kasper Holdum Mar 23 '14 at 02:57

0 Answers0