I have created a standard SharePoint Links list, using Managed Client Object Model (for Silverlight). Here's the code:

ClientContext clientContext = new ClientContext(sitePath);
clientContext.ExecuteQueryAsync(OnSucceeded, OnFailed);

ListCreationInformation lci = new ListCreationInformation();
lci.Title = "My Links";
lci.Description = string.Empty;
lci.TemplateType = ListTemplateType.Links;
List list = clientContext.Web.Lists.Add(lci);
clientContext.ExecuteQueryAsync(OnSucceeded, OnFailed);

I want to be able to add items to this list programmatically, but I am stuck. Normally, I'd add a new list item in the following manner:

ListItemCreationInformation lici = new ListItemCreationInformation();
ListItem item = list.AddItem(lici);
item.ParseAndSetFieldValue("Some field name", "Some field value");
item.ParseAndSetFieldValue("Some other field name", "Some other field value"); 
clientContext.ExecuteQueryAsync(OnSucceeded, OnFailed);

The problem is that I don't know which field I should target for the link's URL and Title fields. Help please. Thank you.


I found a way. There is a class FieldUrlValue in the Client Ojbect Model for this type of situations. Here's how I implemented it:

ListItemCreationInformation lici = new ListItemCreationInformation(); 
ListItem item = list.AddItem(lici);

FieldUrlValue link = new FieldUrlValue();
link.Url = "http://some-address";
link.Description = "Some Address Title";
item["URL"] = link; 

item.["Some other field name"] = "Some other field value";  
clientContext.ExecuteQueryAsync(OnSucceeded, OnFailed); 

I hope the others will benefit from my find. Cheers!


If you go to the settings page of the Links list you will see the names of the field you are after - URL

There is no separate address and tile filed - just enter it as HTML.

<a href="http://someaddress">Some Title</a>
  • Ryan, thank you for helping me out. If I use the line you have suggested, I get the following exception message: [Microsoft.SharePoint.Client.ServerException] = {Microsoft.SharePoint.Client.ServerException: Invalid URL: <a href="http://www.google.com">Google</a>. at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.Sha... Do you know perhaps what am I doing wrong? Thanks. – Boris Nov 9 '11 at 10:28
  • I've solved the problem and posted the solution. – Boris Nov 9 '11 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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