2013-01-09 191 views
0

時出現錯誤使用vb.net設置拒絕訪問特定的文件夾。我附上我的代碼。但我在我的代碼像串隱蔽輸入長收到錯誤無效在設置文件夾權限

code 
----- 
      Dim ds1 As New TdeskTableAdapters.proc_checkuserrightsTableAdapter 
      Dim dt1 As Tdesk.proc_checkuserrightsDataTable = ds1.GetData(ecode) 

      For Each r1 As DataRow In dt1.Rows 
       reqrights = r1("fld_reqrights").ToString 
       approv_rights = r1("fld_approval").ToString 
      Next 

      If approv_rights = "n" Or approv_rights = "N" Then 


       Dim FolderPath As String = "D:\Account\HA\" 'Specify the folder here 

       Dim UserAccount As String = mailid \ pwd 

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

      End If 


getting error in this line 

Dim UserAccount As String = mailid \ pwd error mentioned in the above 

回答

1

所以etiher mailidpwdLong,另一個是String

我認爲mailidLong

Dim UserAccount As String = mailid.ToString() & "\" & pwd 

但是如果你使用&連接字符串也可以省略ToString

另一種可讀的方式是使用String.Format這也隱含轉換爲字符串:

Dim UserAccount As String = String.Format("{0}\{1}", mailid, pwd) 
+0

在另一行 – vps

+0

行「FolderAcl.AddAccessRule geeting錯誤(新澤西FileSystemAccessRule(UserAccount,FileSystemRights.FullControl,InheritanceFlags.ContainerInherit或者InheritanceFlags .ObjectInherit,PropagationFlags.None,AccessControlType.Deny))「顯示錯誤 – vps

+0

錯誤:部分或全部標識引用無法翻譯 – vps