Reputation: 3830
My WPF app downloads and caches files to the C:\ProgramData\CompanyName\ProductName\Data\
directory.
If another user was logged in when they downloaded (created) the file, I cannot overwrite the file to update it, even though I am an Administrator.
Why do I not have write access when I am also an Admin user?
The screenshot shows the file permissions of a file I cannot overwrite.
I understand that I have to elevate the process to do an 'admin' task (as explained here), but seeing as the other user was an Administrator (and so am I), and the 'Owner' of the file is 'Administrator' - why don't I have write permission on a file where the Owner is in the same group? Why don't we share the same privileges?
Upvotes: 0
Views: 355
Reputation: 128060
After downloading and saving the file you may set full access for all users (or any other appropriate group) by code like this:
var fileSecurity = File.GetAccessControl(path);
fileSecurity.AddAccessRule(
new FileSystemAccessRule(
new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null),
FileSystemRights.FullControl,
AccessControlType.Allow));
File.SetAccessControl(path, fileSecurity);
Upvotes: 1