Connor S
Connor S

Reputation: 274

Why does getting C:\ with StorageFolder GetFolderFromPathAsync return an exception?

I am using the following code

            StorageFolder folder;
            if (initial) folder = await StorageFolder.GetFolderFromPathAsync(@"C:\");
            else { use folder picker }

and every time i try to get a Storage Drive it returns an error, what i have noticed is that if i use the Folder Picker then it doesnt throw an exception.

I am not sure what is causing this and it seems pretty irritating that my users have to specify the drive instead of my application automatically getting it.

Exception Description "Access is denied.\r\n"

Upvotes: 1

Views: 2766

Answers (2)

lindexi
lindexi

Reputation: 4327

If you want to use the user folder,and you should make he pick the folder.

Windows.Storage.Pickers.FolderPicker folderPicker = new Windows.Storage.Pickers.FolderPicker();
folderPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
folderPicker.FileTypeFilter.Add(".txt");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)           
{                            
     //do            
}

Upvotes: 0

Romasz
Romasz

Reputation: 29792

In UWP you cannot list all the files/drives just like that (with official API) - this is by design, probably for security reasons. Windows Store apps are isolated and the access is only granted to limited resources/locations. In this case you are freely able to access virtual locations like MusicLibray, PicturesLibrary and so on. The list of access permisions you will find at MSDN.

When using the picker you won't get exception, hence the user has granted access to your app.

Upvotes: 2

Related Questions