I had to print the list of the subwebsites under a sharepoint site using CSOM. i used this code and my server credentials but i go inside a infinite loop at 2nd line of foreach loop. The line is
getSubWebs(newpath);
static string mainpath = "http://triad102:1001";
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)
{
}
}
what code changes has to be made to retrieve the subwebsites?