Get URL Value of SharePoint Hyperlink Field

12 10 2009

I needed to get the value of a SharePoint hyperlink field in a custom list the other day so I simply tried to access the value of the field directly in the object model:

SPListItem item = list.GetItemById(1);

string URL = item[“URL”].ToString();

The only problem with this is whilst it gets the value, you end up with two URL’s separated by a comma. This is because one is the actual display text for the field and the other is the value (the actual URL itself).

In order to get just the URL value, you need to use the following object model code:

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

string URL = value.Url;

You can also use value.Description to get the actual display text for the field.

Simples! Hope this helps 🙂




One response

2 03 2010

Is there a way to extract a hyperlink description in SharePoint Designer so I can use workflow to write that description value to a separate text field that I can use in other ways?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: