I've been testing my application to see how well it works when run by a non-administrative user, and I have found problems with file handling. I am getting an UnauthorizedAccessException when trying to overwrite a file, if the file was created by and adminstrative user.
When writing out the file I first create the file as a .tmp file, then use File.Copy to overwrite the original. The .tmp file gets created, but File.Copy fails. My files are written to a public directory ("C:\Documents and Settings\All Users\Application Data" in XP).
What can I do so that all users can have full control of the application files?
I've found this:
System.Security.AccessControl.DirectorySecurity sec =
System.IO.Directory.GetAccessControl ( directory );
FileSystemAccessRule accRule = new FileSystemAccessRule ( Globals.userIdentity,
FileSystemRights.FullControl, AccessControlType.Allow );
sec.AddAccessRule ( accRule );
Will doing the above to the directory that all the files are located in solve this problem? Or will I have to do something to each file? If so what is that something?
Edit:
Non-admin users cannot modify files created by an admin user. This is not good. I need for all files to be editable by all users. Is there not some sort of permissions that can be set when the file is originally created that will grant this?