GSCustomMenuSection

Contents for SharePoint, ReactJS, C#, ASP .Net, JavaScript, JQuery, SQL

Thursday, December 17, 2015

Connect to site from different environment/domain

In this blog we will see how to connecting to site from different environment using CSOM with login Credentials

Add two references to your visual studio solution
Microsoft.SharePoint.Client.dll &
Microsoft.SharePoint.Client.Runtime.dll


string webUri = "http://servername/sites/demo";
using (ClientContext context = new ClientContext(webUri))
{
        //By Default it will use windows credentials
        //If want to specify credentials use below line
        context.Credentials = new NetworkCredential(
                             "username",
                             "password",
                             "domain");

        Web web = context.Web;

        //Load the web object 
        context.Load(web); 

        //-----------------------------------------
        //Web rootWeb = context.Site.RootWeb;
        //context.Load(rootWeb);

        //call Execute Query 
        //to get all the loaded object working
        context.ExecuteQuery();

        Console.WriteLine(web.Title);
}

No comments :

Post a Comment