Question

How would I programmatically get the port 80 Web Application Default URL for the Farm?

Was it helpful?

Solution

var webService = SPFarm.Local.Services.OfType<SPWebService>().FirstOrDefault();
if (webService != null)
{
    var webApp = webService.WebApplications.FirstOrDefault(wa => wa.GetResponseUri(SPUrlZone.Default).Port == 80);
    if (webApp != null)
    {
        Uri webAppUri = new Uri(webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top