在 Sharepoint 2013 中,我尝试使用以下代码以编程方式将托管元数据列添加到列表中:
Field f = list.Fields.AddFieldAsXml("<Field Type='" + columntype + "' Name='" + columnname + "' DisplayName='" + columnname + "' ShowField='Term1033' />", true, AddFieldOptions.AddFieldToDefaultView);
clientContext.Load(f);
clientContext.ExecuteQuery();
TaxonomyField taxField = clientContext.CastTo<TaxonomyField>(f);
taxField.SspId = this.getDefaultTermStoreId();
taxField.TermSetId = getTermSetIdByName("Instanties");
taxField.AllowMultipleValues = false;
taxField.Open = true;
taxField.TargetTemplate = string.Empty;
taxField.AnchorId = Guid.Empty;
taxField.Update();
list.Update();
clientContext.ExecuteQuery();
该列在我的列表中创建为托管元数据类型列,但我希望用户从中选择的术语集未填写在设置中。有人提示设置托管元数据列的术语集吗?
getDefaultTermStoreId() 和 getTermSetIdByName(string) 给了我正确的 GUID;我查过了!
多谢!