2

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 = @"----@-----.net";
    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!

3

You are using SharePointOnlineCredentials which is meant to be used when connecting to Office 365 tenants. You should connect to SharePoint 2013 on-premise by other means, depending on the authentication methods available on your server.

Your error message shows that NTLM is likelly to be the authentication mecanism expected by the server, so you should instead assign ClientContext.Credentials with an instance of NetworkCredential, see NetworkCredential on MSDN, but created from a windows user account, not from your "----@-----.net" account.

  • Thank you! now the error message changed to this one: An unhandled exception of type 'Microsoft.SharePoint.Client.ClientRequestException' occurred in Microsoft.SharePoint.Client.dll Additional information: Cannot contact site at the specified URL w2k12spps02/sitios/ColeccionProyectos/default.aspx. The site "/sitios/ColeccionProyectos/default.aspx/_vti_bin/sites.asmx" does not exist. Which URL should I use? I Have tried with some URLs like "w2k12spps02" and "w2k12spps02/sitios" – SuperJMN Jan 19 '17 at 11:27
  • Try w2k12spps02/sitios/ColeccionProyectos – Reego Jan 19 '17 at 11:41
  • I used the full URL to one section in the site and it worked! Thanks! – SuperJMN Jan 19 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.