我正在尝试使用vb.net windows窗体使用Microsoft.Sharepoint.Client库检索Sharepoint列表数据。
以下是vb.net代码供参考。
Imports Microsoft.SharePoint.Client
Public Class sharepoint_list
Private client_context As ClientContext
Private Sub sharepoint_list_Load(sender As Object, e As EventArgs) Handles MyBase.Load
client_context = New ClientContext("siteurl@user.com")
Dim web_ As Web = client_context.Web
client_context.Credentials = New SharePointOnlineCredentials("user@user.com", GetPassword("user@user.com", "mypass@123"))
client_context.Load(web_)
client_context.ExecuteQuery()
MsgBox(web_.Title)
End Sub
Public Function GetPassword(username As String, password As String) As Security.SecureString
Dim keyinfo As ConsoleKeyInfo
Dim securePass As Security.SecureString
securePass = New Security.SecureString
For Each c As Char In password
securePass.AppendChar(keyinfo.KeyChar)
Next
Return securePass
End Function
End Class
每当我尝试运行这段代码时,它会抛出错误并显示以下消息
'。',十六进制值0x00,是无效字符。
以及控制台上的以下消息
发生了'System.ArgumentException'类型的第一次机会异常 在System.Xml.dll
中
任何帮助都会很明显。
提前致谢。
答案 0 :(得分:0)
修改GetPassword方法,如下所示:
Public Function GetPassword(password As String) As Security.SecureString
Dim securePass As Security.SecureString
securePass = New Security.SecureString
For Each c As Char In password
securePass.AppendChar(c)
Next
Return securePass
End Function
更改
下面的代码行client_context.Credentials = New SharePointOnlineCredentials("user@user.com", GetPassword("user@user.com", "mypass@123"))
到
client_context.Credentials = New SharePointOnlineCredentials("user@user.com", GetPassword("mypass@123"))