Write to file in uwp that has been drag-dropped from explorer

Viewed 62

If file is dragged and dropped from file explorer it has FileAttributes.ReadOnly flag for StorageFile.Attributes parameter. In that case using StorageFile api to write to file will give error. How to write to file in this case??

1 Answers

In this case PathIO api can be used to write to file (unless file is a system file). Convert data to write into bytes array and then add following code to write to file:

await PathIO.WriteBytesAsync(file.Path, bytes);

This will write to these files without any error. You don't need any additional permission like broadFileSystemAccess for this.

Related