I am totally new to linking Sharepoint Online with vb.net program, any advise would certainly help.
I have added reference for the 2 .dll file, Microsoft.Sharepoint.Client and Microsoft.Sharepoint.Client.Runtime. They are downloaded from the link SharePoint Server 2013 Client Components SDK .
Below will be my code,
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 "pw@12345".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
And the few other classes below 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
The error which I will hit at ExecuteQuery()
is
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.
I understand it is due to authentication issue, and the Sharepoint url is meant for authorized users in the corporate. Assuming the credentials in the code, belongs to an authorized user.
Is it due to wrong coding or it could be due to the corporate IT security policy?