C#: Remove Read-only attribute from File without Administrative Privilege
10,066
You need to have read/write permission on the file.
I preferably use a method like this:
FileSystemInfo fsi = new FileSystemInfo(pathToFile);
fsi.Attributes = FileAttributes.Normal;
or
File.SetAttributes(pathToFile, FileAttributes.Normal);
But as I've said, this won't be possible without read/write permissions on the specific file.
Author by
Butters
Updated on June 05, 2022Comments
-
Butters almost 2 years
Is there a way to remove read-only attribute of a file if the user is not an administrator?
This works if you're an admin but what if you're not?
FileInfo myFile = new FileInfo(pathToFile); myFile.IsReadOnly = false;
-
Steve about 11 yearsThat works if you have read/write permission on file. The administrator role is not the key.
-
Damien_The_Unbeliever about 11 yearsThis is a permissions issue, not an Admin/non Admin issue, per se. If the user account you're running under has the "Write Attributes" permission on the file, they'll be able to make this change.
-
Butters about 11 yearsThanks. I understand it now.
-