在我的应用程序中,我正在创建用于从硬盘归档旧内容的文件夹。
创建新文件夹时,我必须将所有 NTFS 权限(组/用户)从源文件夹复制到新创建的目标文件夹。
这是我到目前为止写的:
FileSecurity fileSecurity =
File.GetAccessControl(filenameSource, AccessControlSections.All);
FileAttributes fileAttributes = File.GetAttributes(filenameSource);
File.SetAccessControl(filenameDest, fileSecurity);
File.SetAttributes(filenameDest, fileAttributes);
这真的是我应该做的全部吗?还是我错过了一些重要的事情?
最佳答案
如果这是一个文件夹,那么您可能需要检查 Directory.SetAccessControl()
方法。您可能想调用 DirectorySecurity.SetAccessRuleProtection(isProtected/*true*/,preserveInheritance /*false*/)
如果要阻止文件继承 ACL 规则,请在调用 Directory.SetAccessControl() 之前;
关于c# - 创建新文件夹时如何复制安全信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2722335/