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.