18
C#测试用户是否具有对文件夹的写权限
我需要在实际尝试之前测试用户是否可以写入文件夹。 我已经实现了以下方法(在C#2.0中),该方法尝试使用Directory.GetAccessControl()方法检索文件夹的安全权限。 private bool hasWriteAccessToFolder(string folderPath) { try { // Attempt to get a list of security permissions from the folder. // This will raise an exception if the path is read only or do not have access to view the permissions. System.Security.AccessControl.DirectorySecurity ds = Directory.GetAccessControl(folderPath); return true; } catch …
187
c#
permissions
directory