Monthly Archives

June 2016

C#, SharePoint 2010

Retrieve URL from Picture and Hyperlink Column

In SharePoint lists, you have the option to provide a column for images with descriptions.  When retrieving it using SPQuery for a WebPart or other back end code, it can be confusing as the url and description are in a String format like this :  “url, description”.

A simple solution for retrieving either the URL or the description is to create a new SPFieldUrlValue object using the column returned in your SPQuery and reference the URL and Description individually.

Example:

SPFieldUrlValue imageData = new SPFieldUrlValue(item[“ImageDescFromSPQuery”].ToString(););
String justTheDescription = imageData.Description;
String justTheImageURL = imageData.Url;