Retrieve all web application names from SharePoint farm using server object model in SharePoint 2016

Retrieve all web application names from SharePoint farm using server object model in SharePoint 2016
InfoPath alternatives for form designing SharePoint

Here we will discuss how we can retrieve all web application names using server object model in SharePoint 2016. Here I have shown in a windows application. I have SharePoint 2016 installed on the same machine, so I can add Microsoft.SharePoint.dll into the windows application and can write server-side code inside it.

If you have not yet started with SharePoint 2016, you can check out the installation steps and also few new features of SharePoint 2016.

Below is the full code to retrive all web applications from the local SharePoint server farm.

string s = string.Empty;
SPFarm farm = SPFarm.Local;

SPWebService service = farm.Services.GetValue<SPWebService>(“”);

foreach (SPWebApplication webapp in service.WebApplications)

{

s += “Web App Name: ” + webapp.Name + ” URL:”+ webapp.GetResponseUri(SPUrlZone.Default) +”\n”;

}

label1.Text = s;

Once you will run the code then the web applications name and URL will be populated like below:

Retrieve all web application names from SharePoint farm using server object model in SharePoint 2016
Retrieve all web application names from SharePoint farm using server object model in SharePoint 2016

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply