Thursday, January 10, 2013

How to get Absolute URL of List using SharePoint object model?

In this post we will discuss how to get absoulte URL of a list using SharePoint object model.

You can also check my previous posts on Get 14 hive file path by using SharePoint 2010 object model [Solution here], Add safe controls programmatically in SharePoint 2010 [Solution here] and Add items to SharePoint list using PowerShell [Solution here].

We can use the SPUtility class to retrieve the absolute or full URL of the SharePoint list.
using (SPSite siteCollection = new SPSite("http://bsahoo3:2500/sites/TestSiteCollection/"))
                using (SPWeb web = siteCollection.OpenWeb())
SPList list = Web.Lists["Employees"];

string listUrl = SPUtility.GetFullUrl(site, list.DefaultDisplayFormUrl);
This will return the DisplayForm Url like below


You can see some SharePoint 2013 articles.