0
ClientContext ctx = new ClientContext(Site);
ctx.Credentials = new NetworkCredential(userName, passWord, "dmz");               
List list = ctx.Web.Lists.GetByTitle(SpList);
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items); // loading all the fields              
ctx.ExecuteQuery();
foreach (var item in items)
{
    if (((FieldUrlValue)(item["VideoSetExternalLink"])).Url.ToString() != VideoURL)
    {
        ((FieldUrlValue)(item["VideoSetExternalLink"])).Url = vp.VideoURL;
        item.Update(); 
    }
}
ctx.Load(items);
ctx.ExecuteQuery();

Works Fine NO ERROR. But the list is not getting updated. What am I doing wrong here?

Naveen
  • 6,786
  • 10
  • 37
  • 85

2 Answers2

0

Remove the last ctx.Load(items), because you are not sending the update to sharepoint instead you are reloading the items values

ClientContext ctx = new ClientContext(Site);
ctx.Credentials = new NetworkCredential(userName, passWord, "dmz");               
List list = ctx.Web.Lists.GetByTitle(SpList);
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items); // loading all the fields              
ctx.ExecuteQuery();
foreach (var item in items)
{
    if (((FieldUrlValue)(item["VideoSetExternalLink"])).Url.ToString() != VideoURL)
    {
        ((FieldUrlValue)(item["VideoSetExternalLink"])).Url = vp.VideoURL;
        item.Update(); 
    }
}
ctx.ExecuteQuery();
DeividKamui
  • 362
  • 1
  • 4
  • 14
  • I fixed the issue by creating a FieldUrlValue object and assigning the value then modifying the object then pass it back to item. eg: FieldUrlValue va = ((FieldUrlValue)(item["VideoSetExternalLink"])); va.Url = vp.VideoURL; item["VideoSetExternalLink"] = va; Thanks for your Help though. – Dayan Sivarajah Jan 28 '15 at 00:16
0
ClientContext ctx = new ClientContext(Site);
ctx.Credentials = new NetworkCredential(userName, passWord, "dmz");               
List list = ctx.Web.Lists.GetByTitle(SpList);
ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(items); // loading all the fields              
ctx.ExecuteQuery();
foreach (var item in items)
{
    if (((FieldUrlValue)(item["VideoSetExternalLink"])).Url.ToString() != VideoURL)
    {
        FieldUrlValue va = ((FieldUrlValue)(item["VideoSetExternalLink"]));
        va.Url = vp.VideoURL;
        item["VideoSetExternalLink"] = va;
        item.Update(); 
    }
}
ctx.Load(items);
ctx.ExecuteQuery();

This is how i Fixed the issue.