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);
  • 相关阅读:
    第5课.异步通知
    第4课.poll机制
    第3课.Linux异常处理体系结构
    第2课.字符设备驱动程序的开发
    第1课.Linux驱动的概述
    [Linux驱动]字符设备驱动学习笔记(二)———实例
    [linux驱动]linux块设备学习笔记(三)——程序设计
    [Linux驱动]字符设备驱动学习笔记(一)
    [linux驱动]proc学习笔记(一)
    [linux驱动][Linux内存]DMA学习笔记一
  • 原文地址:https://www.cnblogs.com/myprogram/p/4593987.html
Copyright © 2011-2022 走看看