我是全新的連接Sharepoint Online與vb.net程序,任何建議肯定會有所幫助。使用VB.NET驗證在線Sharepoint的用戶
我已經加入了2 的.dll文件參考,Microsoft.Sharepoint.Client和Microsoft.Sharepoint.Client.Runtime。他們從鏈接SharePoint Server 2013 Client Components SDK 下載。
下面將我的代碼,
Imports Microsoft.SharePoint.Client
Imports Microsoft.SharePoint
Imports Microsoft
Imports System.Net
Imports System.Security
Public Class FilesRetrievalFromSharePoint
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Using ClientContext As New ClientContext("https://sample.sharepoint.com/Home.aspx")
Dim password As New System.Security.SecureString()
For Each c As Char In "[email protected]".ToCharArray()
password.AppendChar(c)
Next
ClientContext.Credentials = New SharePointOnlineCredentials("[email protected]", password)
Dim web As Web = ClientContext.Web
ClientContext.Load(web)
ClientContext.ExecuteQuery()
End Using
End Sub
而其他一些類低於末次
Private Class SharePointOnlineCredentials
Implements ICredentials
Private password As SecureString
Private v As String
Public Sub New(v As String, password As SecureString)
Me.v = v
Me.password = password
End Sub
Public Function GetCredential(uri As Uri, authType As String) As NetworkCredential Implements ICredentials.GetCredential
Throw New NotImplementedException()
End Function
End Class
,我會打在ExecuteQuery()
的錯誤是
An exception of type 'System.Net.WebException' occurred in Microsoft.SharePoint.Client.dll but was not handled in user code
Additional information: The remote server returned an error: (403) Forbidden.
我知道這是由於身份驗證問題,並且Sharepoint網址適用於公司中的授權用戶。假設代碼中的憑證屬於授權用戶。
是由於錯誤的編碼或可能是由於企業的IT安全策略?
hi @Guruparan,謝謝你的回覆。不,不過,它仍然給我403錯誤。 –
@TanStanley,你是否正確地更換了網站的網址? https://sample.sharepoint.com –
用於測試目的我已經使用ClientContext作爲新的ClientContext(「https://sample.sharepoint.com」)。但是,我可以從Web應用程序獲得響應之前發生錯誤。 –