3

我有一个情况,我有一个 Windows 应用程序,如果它不存在,它将在服务器上创建文件夹,然后我会将文件复制到它,但目前我在指定路径上被拒绝访问。这就是我所拥有的。

If (Not System.IO.Directory.Exists(sdPath & "\DONE")) Then
   System.IO.Directory.CreateDirectory(sdPath & "\DONE")
   sdFileInfo.MoveTo(sdPath & "\DONE\" & sdFileName & sdFileInfo.Extension)
Else
   sdFileInfo.MoveTo(sdPath & "\DONE\" & sdFileName & sdFileInfo.Extension)
End If

如何授予完全访问权限?

我有这段测试代码,看看我是否可以获得权限,但似乎不起作用。

txtPath.Text = "\\ServerName\images\dbpics\POLPICS\55\Polpics\Actual\"

Dim sFolderPath As String = txtPath.Text
Dim sUserAccount As String = "(DomainName\Administrator)"

Dim oFolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(sFolderPath)
Dim oFolderAcl As New DirectorySecurity(txtPath.Text, System.Security.AccessControl.AccessControlSections.Access)

oFolderAcl.AddAccessRule(New FileSystemAccessRule(sUserAccount, _
                                                  FileSystemRights.FullControl, _
                                                  AccessControlType.Allow))

oFolderInfo.SetAccessControl(oFolderAcl)

oFolderAcl = Nothing
oFolderInfo = Nothing
enter code here
4

2 回答 2

4

尝试使用:

Imports System.Security.AccessControl


 Dim FolderPath As String = "C:\TestingFolder" 'Specify the folder here
 Dim UserAccount As String = "MYDOMAIN\someuser" 'Specify the user here

 Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
 Dim FolderAcl As New DirectorySecurity
 FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify,      InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
'FolderAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
FolderInfo.SetAccessControl(FolderAcl)

我从这个网址得到它

于 2013-02-13T12:07:27.393 回答
2

您可以将所需的安全性添加到创建它的目录中:

System.IO.Directory.CreateDirectory(sFolderPath, dirSecurity)

您可以在MSDN的CreateDirectoryDirectorySecurity的文档中看到一些权限和示例。

于 2013-02-13T12:16:27.780 回答