【问题标题】:To retreive sharepoint list data using client context使用客户端上下文检索共享点列表数据
【发布时间】:2018-02-09 05:26:38
【问题描述】:

我正在尝试使用 Microsoft.Sharepoint.Client 库使用 vb.net windows 窗体检索 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 中

任何帮助都将不胜感激。

提前致谢。

【问题讨论】:

    标签: vb.net winforms sharepoint


    【解决方案1】:

    修改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"))
    

    【讨论】:

    • 它给了我以下错误“合作伙伴返回了错误的登录名或密码错误。有关详细信息,请参阅联合错误处理方案。'
    • 检查名称和密码,对于 SharePoint Online,登录名如:test@lz.onmicrosoft.com
    • 我已使用相同的用户名和密码登录 SharePoint Online,但没有成功
    • 如果您使用第三方使用,代码将不起作用。
    猜你喜欢
    • 2013-04-07
    • 1970-01-01
    • 2015-02-10
    • 2013-12-10
    • 1970-01-01
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多