使用CSOM将托管元数据列添加到列表中

时间:2014-03-19 11:17:26

标签: sharepoint-2013 csom

在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();

该列在我的列表中创建为托管元数据类型列,但我希望用户可以选择的术语集未在设置中填写。任何人都有提示设置托管元数据列的TermSet?

getDefaultTermStoreId()和getTermSetIdByName(string)给我正确的GUID;我查了一下!

非常感谢!

1 个答案:

答案 0 :(得分:0)

我们应该添加

taxField.TargetTemplate = string.Empty; taxField.AnchorId = Guid.Empty;

然后它有效!