2013-01-09 85 views
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) 
+0

你能否進一步解釋你有什麼問題?告訴我們這是在第八行是沒有太大的起飛。你有沒有設置斷點? – Codexer

回答

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 

給這是一個鏡頭,讓我知道它是如何解決你的?

謝謝!