zoukankan      html  css  js  c++  java
  • Working With Taxonomy Field in CSOM

    How to create taxonomy field with CSOM

    If you need to programmatic create a taxonomy field, you need to:

    1. Know the termstore id and termset id that associated with this column
    2. Create a taxonomy field with schema include some basic attributes
    3. Update some essential attributes for the taxonomy field
                //Add field as xml with some basic attribute
                XElement fieldSchema = new XElement("Field");
                fieldSchema.SetAttributeValue("Type", "TaxonomyFieldType");
                fieldSchema.SetAttributeValue("DisplayName", "TestField");
    
                list.Fields.AddFieldAsXml(fieldSchema.ToString(), true, AddFieldOptions.DefaultValue);
    
                context.ExecuteQuery();
    
                //get taxonomy field
                context.Load(list.Fields, fields => fields.IncludeWithDefaultProperties().Where(f => f.Title == "TestField"));
                context.ExecuteQuery();
    
                var taxonomyField = list.Fields[0] as TaxonomyField;
    
                //Update essential attributes for taxonomy field
    
                // Specify the Id of termset associated with the column
                taxonomyField.TermSetId = new Guid("a518b741-e2eb-429a-8dc7-f737945b25a3");
                // Id of the term store 
                taxonomyField.SspId = new Guid("151320eb-50d2-468d-b42e-1531301953a7");
    
                taxonomyField.Update();
    
                context.ExecuteQuery();

    How to update taxonomy field value with CSOM

    If you need to programmatic update taxonomy field value, you need to get the term id and label first. This sample shows how to update taxonomy field with multiple values.

                ListItem item = list.GetItemById(1);
    
                TaxonomyFieldValueCollection col = new TaxonomyFieldValueCollection(context, "", taxonomyField);
                col.PopulateFromLabelGuidPairs("invrev-mel|44c3035c-b84b-4da3-b7fc-1097ab5e07e2;BEE|c0e6e20a-142f-4f07-ac10-3cf1aa692b13;05 Industry Data and News|b4030964-270b-4f80-bedd-0c2d9d7fae22");
    
                taxonomyField.SetFieldValueByValueCollection(item, col);
  • 相关阅读:
    elasticsearch入门 (三 ik 分词器安装)
    elasticsearch入门(二 基础api实例)
    elasticsearch入门(一 基础搭建)
    mysql 错误代码 1045 解决
    信号强度概念
    c语言中,在结构体中如何将void *转存为具体需要的数据类型
    我的论文
    I2C 上拉电阻选择计算公式
    SD卡两种操作模式在项目中应用的比较
    2017 年 年会过后的感想
  • 原文地址:https://www.cnblogs.com/myprogram/p/4593987.html
Copyright © 2011-2022 走看看