Wednesday, June 17, 2015

Get the list of sharepoint web applications 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;
}

No comments:

Post a Comment