Get All SubWebs using Client Object Model


Get All SubWebs using Client Object Model

static string mainpath = “http://sriram:10“;

static void Main(string[] args)

{

getSubWebs(mainpath);

Console.Read();

}

public static  void  getSubWebs(string path)

{

try

{

ClientContext clientContext = new ClientContext( path );

Web oWebsite = clientContext.Web;

clientContext.Load(oWebsite, website => website.Webs, website => website.Title);

clientContext.ExecuteQuery();

foreach (Web orWebsite in oWebsite.Webs)

{

string newpath = mainpath + orWebsite.ServerRelativeUrl;

getSubWebs(newpath);

Console.WriteLine(newpath + “\n” + orWebsite.Title );

}

}

catch (Exception ex)      {     }

}

Advertisements

About sharepointsriram

9+ Yrs of IT experience
This entry was posted in Sharepoint 2010 Client Object Model. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s