Thursday 9 April 2015

How to access Web Site through SharePoint Client Object Model

You can access WebSite  Properties through SharePoint Client Object Model.
Microsoft.SharePoint.Client should be use.


Code: 
ClientContext clientContext = new ClientContext("Site URL");

NetworkCredential Cred = new NetworkCredential("UserName""Password", "Domain");
clientContext.Credentials = Cred;
Web web = clientContext.Web;

clientContext.Load(web);
clientContext.ExecuteQuery();

Console.WriteLine("Title:" + web.Title);
Console.WriteLine("Description:" + web.Description);
Console.WriteLine("Created:" + web.Created);
onsole.ReadLine();



If you want to access only specific properties from WebSite, it can be achieved using LINQ.

Code:

ClientContext clientContext = new ClientContext("Site URL");

NetworkCredential Cred = new NetworkCredential("UserName""Password""Domain");
clientContext.Credentials = Cred;
Web web = clientContext.Web;

clientContext.Load(web, a => web.Title,
                        a => web.Description,
                        a => web.Created);clientContext.ExecuteQuery();

Console.WriteLine("Title:" + web.Title);
Console.WriteLine("Description:" + web.Description);
Console.WriteLine("Created:" + web.Created);

onsole.ReadLine();

No comments:

Post a Comment

Translate