SPWebApplication Url


I was trying to get the url of a SharePoint web application, but I couldn’t find a Url property for that class. Trying out several properties, I finally found an easy way to get the Url:

string webUrl = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri;

where webApp is a reference to an object of type SPWebApplication. For example, here is a sample code that displays all web urls in the Farm (except for Central Admin WebApp).

foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
{
    string webUrl = webApp.GetResponseUri(SPUrlZone.Default).AbsoluteUri;
    Console.WriteLine(webUrl);
}

14 thoughts on “SPWebApplication Url

  1. Thanks for this post. I’ve spent a lot of time trying to get the SPContext of a timer job. Referencing the AbsouteUri was far from thought. This solved my problem. πŸ™‚

    Thanks,
    Rick

  2. I had been wondering if you ever considered modifying the design of your blog? Its well written; I really like what you have got to state. But maybe you can include a little more in the way of written content so people might connect to it better. Youve got an awful lot of wording for only having one or two photos. Maybe you can space it out better?

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s