I'm trying to get the value of a field of type "Hyperlink or Image" (currently set to "Hyperlink" in the column settings that is being returned as part of a Sharepoint 2010 ListItem. I'm using the Client Object Model to do this, as I'm building a custom website that is remote to the server where Sharepoint is running. Unfortunately, what I've tried results in a NullReferenceException.

Here's some code to get you going:

ClientContext clientContext = new ClientContext("http://site");
List list = clientContext.Web.Lists.GetByTitle("SP List Name");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>"; // simplest query for now
ListItemCollection listItems = list.GetItems(camlQuery);
  Items => Items.Include(
    item => item["Custom_x0020_URL_x0020_Field_x0020_"]

string liveUrl = string.Empty;

foreach (ListItem listItem in listItems)
  liveUrl = ((FieldUrlValue)(listItem["Custom_x0020_URL_x0020_Field_x0020_"])).Url.ToString();

The "liveUrl =" line has been modified a bunch, trying different ways of getting the value out, but none work. This is just the one that seems to make the most sense, despite still not working. This shouldn't be this hard, right? :P

4 Answers 4


Working solution from StackEchange link

var context = SP.ClientContext.get_current();
var myListItem = context.get_web().get_lists().getByTitle("ListName").getItemById(1);



liveUrl = 

... should work.

Have you tried actually instantiating a new FieldUrlValue object rather than casting? I know you can cast a FieldLookupValue in that manner, but the FieldUrlValue appears to require instantiation (I don't know if that's necessarily accurate)???

Also, see Adding description to sharepoint link URL using the C# CSOM

He had to instantiate rather than cast.


You could try using SPServices instead.

operation: "GetListItems",
async: false,
listName: "SP List Name",
WebURL: "List URL", //not needed if list is on the same site level
CAMLViewFields: "<ViewFields><FieldRef Name='Custom_x0020_URL_x0020_Field_x0020_' /></ViewFields>",
completefunc: function (xData, Status) {

//alert(xData.responseText);  //see if it returns you a value

  $(xData.responseXML).SPFilterNode("z:row").each(function() {

                  var xitem = $(this);
                  var url = xitem.attr('ows_Custom_x0020_URL_x0020_Field_x0020_');



    liveUrl = new SPFieldUrlValue(listItem["Custom_x0020_URL_x0020_Field_x0020_"].ToString()).Url.ToString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.