Retrieve a URL value from Hyperlink Field in SharePoint using C#

In this hint, I elaborates How to retrieve a URL value from Hyperlink Field in SharePoint using C# SharePoint Server Object Model.

Suppose your custom list contains a column of type Hyperlink or Picture. And suppose you want to retrieve the list items through  SharePoint 2010 object model , as shown 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 retrieve the value of URL which is of type Hyperlink or Picture

The above approach you returns the URL and the Description.To overcome the above issue you can use the SPFieldUrlValue SharePoint Object model Class by using the following code

SPFieldUrlValue value = new SPFieldUrlValue(item[“URL”].ToString());
string acturlURL = value.Url;

Also you can check some SharePoint 2010 Object Model articles here.

Enjoy 🙂

Advertisements

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