Tuesday, September 7, 2010

Get URL Value of SharePoint Hyperlink Field « Alex's SharePoint Blog

Get URL Value of SharePoint Hyperlink Field « Alex's SharePoint Blog: "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;"

0 comments: