Search code examples
sharepointsharepoint-2007

How to loop through from a root web and all its subsites


I came across a issue that I need to solve. I want to loop through a root web and all its subsites, and want to set some properties


Solution

  • using (SPSite oSPsite = SpSecurityHelper.GetElevatedSite(GetSiteCollection(properties)))
            {
                SPWebCollection siteWebs = oSPsite.AllWebs;
                foreach (SPWeb web in siteWebs)
                {
                    try
                    {
                        SPList list = null;
                        try
                        {
                            list = web.Lists["Images"];
                        }
                        catch { }
    
                        if (list != null)
                        {
    
                            list.EnableModeration = isEnabled == false ? false: true;
                            list.Update();
                        }
                    }
                    finally
                    {
                        if (web != null)
                            web.Dispose();
                    }
                }
            }