Home > Deveploment and Programming, SharePoint Development > Get the list of sharepoint web applications using C#

Get the list of sharepoint web applications using C#

Here there is a function which return the list of all web application in the farm using C#

public DataTable GetAllWebApplication()
{
DataTable dt = new DataTable();
dt.Columns.Add(“URL”);
dt.Columns.Add(“Title”);
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWebServiceCollection webServices = new SPWebServiceCollection(SPFarm.Local);
foreach (SPWebService webService in webServices)
{
foreach (SPWebApplication wa in webService.WebApplications)
{
dt.Rows.Add(new object[] { wa.GetResponseUri(SPUrlZone.Default).AbsoluteUri, wa.Name });
}
}

});

return dt;
}

 

 

Advertisements
  1. 15/06/2015 at 10:49 am

    Nice post.

    Instead of iterating through web service collection we can achieve the same using
    SPFarm farm = SPFarm.Local;
    SPWebService service = farm.Services.GetValue(string.Empty);
    foreach(SPWebApplication webapp in service.WebApplications)
    {
    //do operations here
    }

  1. 02/01/2015 at 2:28 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: