I am getting following error
"The remote server returned an error: (401) Unauthorized."
While I'm trying to read a website hosted in SharePoint. I have tried following code to access my SharePoint site via my C#.
String Id="xyz.onmicrosoft.com";
String pass="Password";
SecureString password = new SecureString();
foreach (char ch in pass)
password.AppendChar(ch);
Uri uri = new Uri("https://mydomain.sharepoint.com/sites/parts/");
using (var context = new ClientContext(uri))
{
context.Credentials = new SharePointOnlineCredentials(Id,password);
Web web=context.Web;
context.Load(web, w => w.Title);
context.ExecuteQuery();
System.Console.WriteLine("Web Title");
System.Console.WriteLine(web.Title);
}
I didn't get to know whats wrong with this code. I have tried some forum solutions as well but they didn't worth to resolve this error.