I am trying to implement Notepad++ style toggling read-only flag for files in an UWP text editor. I tried using SetFileAttributesFromApp
but it fails with Access to the path is denied
for sensitive file types like Batch files and VBScript files. Then I tried using SetFileInformationByHandle
which requires UWP app to get handle from StorageFile
. I tried using CreateSafeFileHandle
but it only provides read and write access and the only way to modify attribute is to get write access. Getting write access fails if the file has read only flag enabled or file is drag and dropped to editor. I checked answer to this question and the only extra access this method specifies is read attribute and delete access. So my question is can I get FILE_WRITE_ATTRIBUTES
access to the handle created from StorageFile
, if so how do I do that??
Asked
Active
Viewed 230 times
0

Soumya Mahunt
- 2,148
- 12
- 30
-
Could you please tell me if the project you are using is a C# UWP project or a C++/WinRT UWP project? – YanGu Jan 19 '21 at 09:47
-
@YanGu-MSFT Sorry for not clarifying clearly(I thought the usage of `SafeFileHandle` would be obvious), the project is a uwp C# project with P/Invoking some `winapi` methods. – Soumya Mahunt Jan 19 '21 at 09:51
1 Answers
1
There is no such API to support getting FILE_WRITE_ATTRIBUTES
access to the handle created from a StorageFile
when the StorageFile
instance has read only flag.
If you want to edit the dragged file in your UWP text editor, you could copy the dragged file into the LocalFolder. The copied file will have read and write access permission. You could edit the copied file and replace it with the original dragged file with a FileSavePicker
. Note you could delete the copied file in LocalFolder
if you don’t need to save it. In this way, you have no need to change the read only flag of a file.

YanGu
- 3,006
- 1
- 3
- 7