I'm trying to query SharePoint list (Office 365) using the code below but I keep getting the following error message
'The remote server returned an error: (403) Forbidden.'
I tried every possible solution I could think of but no luck! Any suggestions or ideas of how to access SharePoint 365 using c#?
using (ClientContext clientContext = new ClientContext("https://test.sharepoint.com/"))
{
SecureString passWord = new SecureString();
foreach (char c in "test123".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("first.last@mytestsite.onmicrosoft.com", passWord);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
Console.WriteLine(web.Title);
Console.ReadLine();
}