3

How can I have the list of all existing SharePoint Web Applications and their site collections from code behind .

2 Answers 2

3
foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
{
    string webUrl = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri;
    SPSiteCollection sites = webApp.Sites;
}
2
SPWebApplicationCollection webAppColl = SPWebService.ContentService.WebApplications;

if (webAppColl != null)
 { 
   foreach (SPWebApplication spWebApp in webAppColl)
   {
        SPSiteCollection sites = spWebApp.Sites;
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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