This code is supposed to be the simplest code for connecting. Like a "Hello World" program:
static void Main(string[] args)
{
var targetSite = new Uri("http://w2k12spps02/sitios/ColeccionProyectos/default.aspx");
var login = @"[email protected]";
var password = "----";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
using (ClientContext clientContext = new ClientContext(targetSite))
{
clientContext.Credentials = onlineCredentials;
Web web = clientContext.Web;
clientContext.Load(web, webSite => webSite.Title);
clientContext.ExecuteQuery();
Console.WriteLine(web.Title);
}
}
However, I'm getting this error in the ExecuteQuery()
line:
An unhandled exception of type 'Microsoft.SharePoint.Client.ClientRequestException' occurred in Microsoft.SharePoint.Client.Runtime.dll
Additional information: The IDCRL response header from server 'http://w2k12spps02/' is not valid. The response header value is 'NTLM'. The response status code is 'Unauthorized'. All response headers are 'SPRequestGuid=dc82cc9d-24ea-c086-5d64-eb854b84146b, request-id=dc82cc9d-24ea-c086-5d64-eb854b84146b, X-FRAME-OPTIONS=SAMEORIGIN, MicrosoftSharePointTeamServices=15.0.0.4420, X-Content-Type-Options=nosniff, X-MS-InvokeApp=1; RequireReadOnly, Content-Length=16, Content-Type=text/plain; charset=utf-8, Date=Thu, 19 Jan 2017 09:13:53 GMT, Server=Microsoft-IIS/8.0, WWW-Authenticate=NTLM, X-Powered-By=ASP.NET'.
What's the problem? I don't know if the URL is wrong, whether the login information is wrong... or the whole piece of code is wrong!