2

As the Site Collection Administrator, I don't have access to the servers to write server side code to get a listing of all sites in my site collection. I can write sandbox solutions in SP2010 to get a listing of all sites by using the SPSite AllWebs like this,

        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        {
            SPWebCollection webs = site.AllWebs;
            foreach (SPWeb thisWeb in webs)
            {
                //Do something
            }
        }

but AllWebs doesn't exist in the Client Object Model. So, how can I get a listing of all sites recursively without having to manually walk each parent site? As the SCA, it's necessary for me to know who's creating what and how often sites are used, etc.

Thanks

1

did you try this one:

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)
        {

        }


    }

Source: http://chennaisharepointtraining.blogspot.in/2011/11/get-all-subwebs-using-client-object.html

Web Class:

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web(v=office.14).aspx

  • I want to know if this can be achieved through REST API? FYI: I am using the APP Only Token (anonymous access) The reason of telling you this is because I have come across various answers that say you can do a search query in STS_Site. That doesn't work for App Only Token (Client Credentials Flow) Is there a way? Much appreciated! – Syed Mauze Rehan Aug 8 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.