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:
Hope this will be helpful.
Download FREE SharePoint 2019 Installation PDF Guide
This FREE PDF contains, Steps by step guide to install SharePoint 2019 Preview, prerequisites, hardware and software new features. First impression to SharePoint Server 2019 new modern site, modern lists and modern document libraries.
You May Also like the Following SharePoint Online Tutorials: