My problem at the moment is that I need my program to able to write to a network drive with certain file and folder permissions, that don’t allow the current users to write, edit or delete directly on this drive as they keep messing up our directories. But I still need those permissions for my app. Is there any way to get around this?
Asked
Active
Viewed 1,133 times
0
-
add permission from security tab to folder which you wants to access. – Rahul Hendawe Jul 04 '16 at 12:42
-
1You need Impersonation : http://stackoverflow.com/questions/125341/how-do-you-do-impersonation-in-net run your app in user, which has access to that directory. – Jul 04 '16 at 12:46
1 Answers
0
Adding EveryOne user with Full Permission to product folder at common application path will allow you to delete directly on this drive
var installationDir = new DirectoryInfo(strInstallationPath);
DirectorySecurity myDirectorySecurity = installationDir.GetAccessControl();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule("EveryOne", FileSystemRights.FullControl, (InheritanceFlags)3, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
installationDir.SetAccessControl(myDirectorySecurity);
FileInfo myFile = installationDir.GetFiles("abc.txt");
myFile.Delete();