3

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

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, privacy policy and cookie policy

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