The primary problem is that you are calling Update()
on the folder
, when you need to call it on the ListItemAllFields
property:
folder.ListItemAllFields["DealStage"] = "7178cede-c689-4b47-853a-88bb8b95e230";
folder.ListItemAllFields.Update();
context.ExecuteQuery();
But, secondarily, you should use TaxonomyFieldValue
(for single-value managed metadata columns) and TaxonomyFieldValueCollection
(for multi-value managed metadata columns). If your currentFilingSystemItem
, then you may have gotten lucky, in most cases, setting a taxonomy field to a raw guid will not update the value correctly. Also note the use of the SetFieldValueByValue
method on the actual Field object, rather than simply setting the field equal to a value. Taxonomy fields are considerably more difficult to code updates for than scalar value fields are. Your code should look more like this:
Folder folder = context.Web.GetFolderByServerRelativeUrl(context.Web.ServerRelativeUrl + "/library3/" + currentFilingSystemItem["DealName"].ToString());
context.Load(folder);
var folderListItem = folder.ListItemAllFields;
context.Load(folderListItem);
var dealStageField = list.Fields.GetByInternalNameOrTitle("DealStage");
context.Load(dealStageField);
context.ExecuteQuery();
var dealStageTaxField = context.CastTo<TaxonomyField>(field);
var dealStageTermValue = new TaxonomyFieldValue();
//dealStageTermValue.Label = "Display Text from the Term"; // Note that if you do not set this value, or you set it to a value that doesn't match what is in the termstore, the value may display incorrectly in list views for several minutes before SharePoint synchronizes from the termstore.
dealStageTermValue.TermGuid = new Guid("7178cede-c689-4b47-853a-88bb8b95e230");
dealStageTermValue.WssId = -1;
dealStageTaxField.SetFieldValueByValue(currentFilingSystemItem, dealStageTermValue);
currentFilingSystemItem.Update();
dealStageTaxField.SetFieldValueByValue(folderListItem, dealStageTermValue);
folderListItem.Update();
context.ExecuteQuery();
DealStage
allow multiple term selections, or is it just Single Value?