0

使用 vb.net 设置拒绝访问特定文件夹。在这里我附上了我的代码。但是在我的代码中出现错误,例如从字符串到类型 long 的隐蔽是无效的

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
4

1 回答 1

1

所以 etiher mailidorpwd是 aLong而另一个是 a String

我假设这mailid是一个Long

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

但是如果你&用来连接字符串,你也可以省略ToString.

另一种可读的方法是使用String.Formatwhich 也隐式转换为字符串:

Dim UserAccount As String = String.Format("{0}\{1}", mailid, pwd)
于 2013-01-09T09:19:44.187 回答