1
votes

my code is like below

  try
    {

        string strUserName="abc";
        string strPassword="123";
        ClientContext context = new ClientContext(siteurl);
        var credentials = new NetworkCredential(strUserName, strPassword,"Ext");


        context.Credentials = credentials;
        // The SharePoint web at the URL.
        Web web = context.Web;

        // We want to retrieve the web's properties.
        context.Load(web);

        // Execute the query to the server.
        context.ExecuteQuery();

        // Now, the web's properties are available and we could display 
        // web properties, such as title. 
        System.Console.WriteLine("Web Title");
        System.Console.WriteLine(web.Title);
    }
    catch (Exception ex)
    {
    }

it is giving error "unable to connect remote server"

2
guess your user name doesnot have enough permission to access the site. you can check your detailed error info and its call stack to get a cluePhenix_yu
its having permission and i am able to access with these credential when i access from browser. from c# its giving error "the remote certificate is invalid accoarding to validation process, could not establish trust relationship for the ssl/tls secure channel"Nitu Bansal
there is no sharepoint installed in my pc. you have checked your sharepoint log?this error message may be related to the certificate validation between your client and sharepointPhenix_yu
What is the value of siteurl?H A

2 Answers

1
votes

First thing make sure that the following entities are correctly passed:

  • siteurl
  • strUserName
  • strPassword
  • "Ext"

If you're trying to connect to SharePoint Online 2013 then you have to replace, "NetworkCredential" with "SharePointOnlineCredentials". Here's the code snippet for it:

    string strUserName="abc";
    string strPassword="123";
    SecureString ssPwd = new SecureString();
    strPassword.ToList().ForEach(ssPwd.AppendChar);
    ClientContext context = new ClientContext(siteurl);
    SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(strUserName, ssPwd);

    context.Credentials = credentials;
    // The SharePoint web at the URL.
    Web web = context.Web;

    // We want to retrieve the web's properties.
    context.Load(web);

    // Execute the query to the server.
    context.ExecuteQuery();
0
votes

To accept self signed certificates :

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;