Mg Bhadurudeen
Mg Bhadurudeen

Reputation: 1434

How to Delete/Move Storage files when dropped?

I am able to delete/move/copy storage files successfully when I get file objects through filepicker. But, When user drops files from windows file explorer into my app, I am unable to delete/move those files (but it allows me to copy). My code is..

if (e.DataView.Contains(StandardDataFormats.StorageItems) == false) { return; }                          
var files = await e.DataView.GetStorageItemsAsync();
if (files.Count < 0) { return; }

foreach (var file in files) 
{
 await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
 //await file.MoveAsync(folder, Filename, NameCollisionOption.GenerateUniqueName);
}

When I try to delete/move I get the following error. "WinRT information: This file is restricted to read access and may not be modified or deleted". But the file is not read-only. It allows me to add the same file through file picker!

Upvotes: 0

Views: 206

Answers (1)

Xie Steven
Xie Steven

Reputation: 8591

It's by design. You could not delete files when you drop files. UWP apps have direct access only to their own files.

The Picker is completely different from the "drag and drop" operation.

The picker runs with the user’s full privileges, and it can use these privileges on the app’s behalf for locations the app has requested via capabilities, locations requested by the user via file pickers, etc. The StorageItem encapsulates this brokerage procedure so the app doesn’t need to deal with it directly. From Rob's blog.

Upvotes: 1

Related Questions