Iterating through all Web Applications,Site Collections,Sites,Lists and Libraries and Items in a SharePoint farm

private void TraversFarm()
        {
            SPFarm farm = SPFarm.Local;
            foreach (SPService curService in farm.Services)
            {
                if (curService is SPWebService)
                {
                    SPWebService webService = (SPWebService)curService;
                    foreach (SPWebApplication webApp in webService.WebApplications)
                    {
                        foreach (SPSite site in webApp.Sites)
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                foreach (SPList list in web.Lists)
                                {
                                    foreach (SPListItem item in list.Items)
                                    {
                                        //DO Something here
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

Comments

Popular Posts

GREYCstoration Oil Paint plugin for Photoshop

Service Bus Gateway service stuck at Starting

PowerApps SubmitForm not clearing People Picker value

Apple iPhone sending SMS automatically 00447786205094

SharePoint online hub navigation not updating for other users