Search code examples
c#.netpermissionsuser-accounts

How to give Create, Read and Modify permissions to all users for a file created by my application in C:\ProgramData?


My application basically creates an XML file in C:\ProgramData\MyAppFolder and dumps config settings in it.

I need to allow even standard users to have permission to add or delete settings to these config files. Right now I see that standard users only have read/execute permission but not "Full Control".

I've seen other questions being answered with ways to modify permissions to that particular folder but I don't want to change the default permission level, since it might be reset by a system admin.

If C:\ProgramData can't give that access to all users, is there any folder that best suits the needs of application?

EDIT:

My initial question might be misleading. I don't want to give rights to users, but rather allow the application to modify the XML file when it is run by all users.

DECISION:

I think changing the permissions while creating the folder in ProgramData is the only option.

And if that's not possible, CommonDocuments is the way to go.

Thanks Eve.


Solution

  • I would use a folder in the Environment.SpecialFolder enum.

    Example:

    var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);