Tuesday, June 5, 2012

Get all subsites using client object model in sharepoint

Here i will show how to get all sub sites using client object model in share point.Here we have know why we are using Openweb method.Using this method we can get the websites from web collection .We will get title,description and web for the each website in collection using context query and display the information using loop
ClientContext clc = new ClientContext(url);
sp.Web w = clc.Site.OpenWeb("url/sitename");
clc.Load(w,ws => ws.Webs,ws => website.Title, ws => ws.Description,);
clc.ExecuteQuery();
for (int j = 0; j != w.Webs.Count;j++)
{
Console.WriteLine(ws.Webs[j].Title);
}
Post a Comment

Bel