SP2013 CSOM C# 更新列表
SP2013 CSOM C# Update List
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();
工作正常没有错误。但是列表没有得到更新。我在这里做错了什么?
删除最后一个 ctx.Load(项),因为您没有将更新发送到共享点,而是重新加载项值
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();
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.
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();
工作正常没有错误。但是列表没有得到更新。我在这里做错了什么?
删除最后一个 ctx.Load(项),因为您没有将更新发送到共享点,而是重新加载项值
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();
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.