Post

How to get the full URL from SPListItem in SharePoint

The SPListItem URL property does return the URL for the SPListItem including the List/Document 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:

1
2
3
4
5
6
7
8
9
    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.

This post is licensed under CC BY 4.0 by the author.