0

出现错误“无法翻译部分或全部身份参考

在第 8 行出现错误

Dim FolderPath As String = "D:\Account\HA\" 'Specify the folder here
Dim UserAccount As String = mailid.ToString() & "\" & pwd
Dim objDirectoryInfo As DirectoryInfo = Nothing
Dim objDirectorySecurity As DirectorySecurity = Nothing
Dim objRule As FileSystemAccessRule = Nothing

objDirectoryInfo = New DirectoryInfo(FolderPath)
objDirectorySecurity = objDirectoryInfo.GetAccessControl
objRule = New FileSystemAccessRule(UserAccount, FileSystemRights.ReadPermissions, AccessControlType.Allow)
objDirectorySecurity.AddAccessRule(objRule)
objDirectoryInfo.SetAccessControl(objDirectorySecurity)
4

1 回答 1

0

试试我为你做的这些改变......

 Public Sub AddDirectorySecurity(ByVal FolderPath As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)


 ' Create a new DirectoryInfoobject.
    Dim objDirectoryInfo As New DirectoryInfo(FolderPath)

    ' Get a DirectorySecurity object that represents the current security settings.
    Dim objDirectorySecurity As DirectorySecurity = objDirectoryInfo.GetAccessControl()

     ' Add the FileSystemAccessRule to the security settings. 
    objDirectorySecurity .AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))

    ' Set the new access settings.
    objDirectoryInfo .SetAccessControl(dSecurity)

 End Sub

试一试,让我知道它对你有用吗?

谢谢!

于 2013-01-10T23:04:33.500 回答