Answered by:
[UWP] "Could not find a part of the path"

Question
-
Hello,
In the following scenario:
StorageFolder folder1 = // from folder picker
StorageFolder fold2 = // from folder picker
await Task.Run(()
{
Directory.Move(folder1.Path, folder2.Path);
// same error if: Directory.Move(folder1.Path, Path.Combine(folder2.Path + @"\NewDir")); // NewDir doesn't exist
});
I always got exception "Could not find a part of the path C:\\xxx" where xxx is the top folder name in folder2.
Any idea why?
Thanks!
- Edited by Rob Caplan [MSFT]Microsoft employee Saturday, September 24, 2016 4:19 AM title tag
Friday, September 23, 2016 11:57 PM
Answers
All replies
-
Use StorageFolder methods instead of Directory.Move. The StorageFolder version goes through the file broker to use the permissions granted by the folder picker. The Directory version uses the app's direct permissions, which it doesn't have for paths outside of its ApplicationData folder. There isn't a direct Move method, but you can build it from the lower level methods.
See my blog entry Skip the path: stick to the StorageFile
- Proposed as answer by Azat Tazayan Saturday, September 24, 2016 7:31 AM
Saturday, September 24, 2016 4:19 AM -
Thanks for your reply!
I checked StorageFolder before but didn't know how to achieve the goal. Just checked your blog still don't know what to do.
What I wanted is to move one folder to another, just as what Directory.Move does.
Could you please tell me how to make it work using StorageFolder version?
Many thanks!
Saturday, September 24, 2016 4:49 PM -
What part are you having trouble with?
StorageFolder doesn't have an explicit "Move", so you'll have to break the option down: Create the new folder then move the contents.
Monday, September 26, 2016 6:27 PM -
The "Move" part.
How to move the content?
Thanks!
Monday, September 26, 2016 8:56 PM -
-
Thanks.
Seems I have to loop through the content.
Monday, September 26, 2016 9:57 PM