In this article we will discuss about how to get URL value SharePoint hyperlink field SharePoint 2010. Also you can check out my previous posts on:
Here we will discuss how we can retrieve the URL from a SharePoint hyperlink field in SharePoint 2010.
Suppose your custom list contains a column of type Hyperlink or Picture. And suppose you want to retreive the list items through SharePoint 2010 object model, then if you directly try to retrieve like below:
SPListItem item = list.GetItemById(1); //Suppose you want to retrieve the 1st item from the custom list.
string URL = item[“URL”].ToString(); //Trying to retrive the value of URL which is of type Hyperlink or Picture
If you try to get the URL by the above approach you will returned with two times the URL with a comma separated. Why we get this because it returns the URL and the Description.
If you left the description field black while adding the list item you will get two time URL with comma separated.
But if you put something in the description field you will get URL and Description with comma separated.
So to overcome the above issue you can use the SPFieldUrlValue SharePoint Object model Class.
So you can use in the following way.
SPFieldUrlValue value = new SPFieldUrlValue(item[“URL”].ToString());
string acturlURL = value.Url;