Question

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.Load(clientContext.Web);
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"); 
item.Update();
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.

Was it helpful?

Solution

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";  
item.Update(); 
clientContext.ExecuteQueryAsync(OnSucceeded, OnFailed); 

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

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top