2014-07-09 59 views
0

我正在使用Sharepoint 2013網站,我需要在庫「Drop Off Library」中爲元數據列「Network」手動添加值。我檢查文檔中是否存在特定單詞,然後嘗試更新該項目。當我嘗試更新「網絡」列和其他選擇列「PickUp」。我的元數據列不會更新,但選擇列會更新。 以下是我的代碼。請注意我正在使用CSOM。在Sharepoint 2013中使用客戶端對象模型進行元數據列更新

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

我解決它使用下面的代碼

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(); 
} 
相關問題