我正在使用Sharepoint 2013网站,我需要手动将值添加到库“Drop Off Library”中的元数据列“Network”。我检查文档中是否存在特定单词然后我尝试更新该项目。当我尝试更新“网络”列和其他选择列“PickUp”时。我的元数据列未更新,但选择列已更新。 以下是我的代码。请注意我使用的是CSOM。
foreach (Microsoft.SharePoint.Client.ListItem item in ItemCol)
{
foreach(Term Tstring in termColl)
{
object findText = Tstring.Name;
word.Selection.Find.ClearFormatting();
if (word.Selection.Find.Execute(ref findText,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing))
{
item.File.CheckOut();
item["Network"] = "3;#Cartoon"; //My term:cartoon with 3 as term id(checked in TaxonomyHiddenList)
item["PickUp"] = "Yes";
item.Update();
context.Load(item);
lists.Update();
context.ExecuteQuery();
item.File.CheckIn("Done", CheckinType.MajorCheckIn);
}
}
答案 0 :(得分:0)
我使用下面的代码解决了它
if (word.Selection.Find.Execute(ref findText,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing))
{
item.File.CheckOut();
TaxonomyFieldValue termValue = null;
TaxonomyField txField = context.CastTo<TaxonomyField>(lists.Fields.GetByTitle("Network"));
termValue = new TaxonomyFieldValue();
termValue.Label = Tstring.Name;
termValue.TermGuid = Tstring.Id.ToString();
termValue.WssId = -1;
txField.SetFieldValueByValue(item, termValue);
item["GetMetadata"] = "Yes";
item.Update();
item.File.CheckIn("Done", CheckinType.MajorCheckIn);
context.Load(item);
context.ExecuteQuery();
}