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
Post a Comment