I had a problem creating a directory with specific permissions.
//Make sure Tools directory exists DirectoryInfo oMyDirectoryInfo = new DirectoryInfo(oInstance.szToolsPath); if (!oMyDirectoryInfo.Exists) { oMyDirectoryInfo.Create(); DirectorySecurity oDirectorySecurity = oMyDirectoryInfo.GetAccessControl(); oDirectorySecurity.AddAccessRule(new FileSystemAccessRule((Settings.Default.LoginDomain + "\\" + Settings.Default.LoginUsername), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow)); oMyDirectoryInfo.SetAccessControl(oDirectorySecurity); }
Now this creates a directory, and I see that Login has been added to the security tab. However, when I impersonate Login and try to copy files to this directory, I get an Unauthorized Exception. I can create a file (without data), I can create a folder, but I can not write data to files (but I installed FullControl: /)
I dug further to permissions via Windows, and I see that this applies to subfolders, but I would also like to set this to files. How to do this with code?
This is on Windows 7
source share