我注意到如果你更改了特定目录的安全设置,你可以在Windows中使该文件夹不再"可浏览".特别是,将管理员的"读取"权限更改为"拒绝"将使该文件夹无法访问.
我现在的问题是,我如何在代码中解决这个问题?我跟着让我接近,但它仍然是不对的:
/// <summary>
/// Takes in a directory and determines if the current user has read access to it (doesn't work for network drives)
/// THIS IS VERY HACKY
/// </summary>
/// <param name="dInfo">directoryInfo object to the directory to examine</param>
/// <returns>true if read access is available, false otherwise</returns>
public static bool IsDirectoryReadable(DirectoryInfo dInfo)
{
try
{
System.Security.AccessControl.DirectorySecurity dirSec = dInfo.GetAccessControl();
System.Security.Principal.WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal selfGroup = new System.Security.Principal.WindowsPrincipal(self);
// Go through each access rule found for the …Run Code Online (Sandbox Code Playgroud)