如何使文件夹不可删除?

ped*_*ram 0 c#

如何使文件夹无法删除?

或者,我如何请求Windows用户提供删除它的通行证.

问候.

Dea*_*ing 6

您使用Directory.SetAccessControl方法.这个链接上有一个例子,但这里只是以下情况:

public static void AddDirectorySecurity(string FileName, string Account, 
                      FileSystemRights Rights, AccessControlType ControlType)
{
    // Create a new DirectoryInfo object.
    DirectoryInfo dInfo = new DirectoryInfo(FileName);

    // Get a DirectorySecurity object that represents the 
    // current security settings.
    DirectorySecurity dSecurity = dInfo.GetAccessControl();

    // Add the FileSystemAccessRule to the security settings. 
    dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                    Rights,
                                                    ControlType));

    // Set the new access settings.
    dInfo.SetAccessControl(dSecurity);
}
Run Code Online (Sandbox Code Playgroud)