Get All Sub Webs Using Client Object Model in SharePoint 2010


 static string mainpath = "http://SiteURL";
        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)
            {
             
            }
       
         
        }

Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell