How to get the full URL from SPListItem in SharePoint

October 19, 2009

The SPListItem URL property does return the URL for the SPListItem including the List/Documetn Library name, but it doesn’t return the full URL including the server and site names.

To get the full URL, you can either concatenate the SPLIstItem.Web.Url and the SPListItem.URL, or extract the full URL from the SPListItem.XML data like this:

 

foreach (SPListItem item in list.Items)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(item.Xml);
XmlNamespaceManager nsm = new XmlNamespaceManager(xmlDoc.NameTable);
nsm.AddNamespace("z", "#RowsetSchema");
string fullURL = xmlDoc.SelectSingleNode("z:row", nsm).Attributes["ows_EncodedAbsUrl"].Value;
}

 

Of course, you should add the usual error handling and checking.

 


Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • DotNetKicks
  • LinkedIn
  • Reddit
  • Tumblr

tags: ,
posted in Code by InsomniacGeek

Follow comments via the RSS Feed | Leave a comment | Trackback URL

Leave Your Comment

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org