简体   繁体   English

C#应用程序中的文件和文件夹权限

[英]File and Folder permissions in C# application

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? 有什么办法可以解决这个问题?

Adding EveryOne user with Full Permission to product folder at common application path will allow you to delete directly on this drive 将具有完全权限的EveryOne用户添加到公用应用程序路径中的产品文件夹,将允许您直接在此驱动器上删除

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM