Sharepoint 2013 未更新Microsoft office文件的关键字列。

Sharepoint 2013 未更新Microsoft office文件的关键字列。,sharepoint-2013,sharepoint-clientobject,sharepoint-online,Sharepoint 2013,Sharepoint Clientobject,Sharepoint Online,我正在尝试通过客户端对象模型.net托管代码上载SharePoint online站点文档库中的文档。但文档库中的关键字列仅针对microsoft office文件进行更新。它不会抛出任何错误,代码工作正常,但关键字列不会被更新 我正在将以下值传递到关键字列: listItem.File.ListItemAllFields[“TaxKeyword”]=“21;#五个| 850EC37A-71D1-44DE-A175-AF51FBB5AE7E” listItem.File.ListItemAllF

我正在尝试通过客户端对象模型.net托管代码上载SharePoint online站点文档库中的文档。但文档库中的关键字列仅针对microsoft office文件进行更新。它不会抛出任何错误,代码工作正常,但关键字列不会被更新

我正在将以下值传递到关键字列:

listItem.File.ListItemAllFields[“TaxKeyword”]=“21;#五个| 850EC37A-71D1-44DE-A175-AF51FBB5AE7E”

listItem.File.ListItemAllFields[“TaxKeywordTaxHTField”]=“21;#五个| 850EC37A-71D1-44DE-A175-AF51FBB5AE7E”

ofile.ListItemAllFields.Update()

clientContext.ExecuteQuery()

救命啊。 谢谢
Nidhi Mohan

因为
企业关键词
是一种使用
分类字段的方法。SetFieldValueByValueCollection
方法使用SharePoint 2013 CSOM设置分类字段值

如何使用SharePoint CSOM设置企业关键字分类字段值 因为,下面的示例演示了如何设置企业关键字字段值:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;

namespace SharePoint.Client.Taxonomy
{
    /// <summary>
    /// Enterpise Keyword Manager
    /// </summary>
    public class KeywordsManager
    {

        /// <summary>
        /// Set Enterprise Keyword Value
        /// </summary>
        /// <param name="item">List Item</param>
        /// <param name="values">Keyword values</param>
        public static void SetTaxKeywordValue(ListItem item,string[] values)
        {
            var ctx = item.Context;
            var list = item.ParentList;
            var field = list.Fields.GetByInternalNameOrTitle(TaxKeywordFieldName);
            var taxKeywordField = ctx.CastTo<TaxonomyField>(field);
            var keywords = values.Select(value => EnsureKeyword(taxKeywordField, value)).ToList();
            taxKeywordField.SetFieldValueByValueCollection(item, new TaxonomyFieldValueCollection(ctx, GetTermsString(keywords), taxKeywordField));    
        }


        /// <summary>
        /// Ensure Keyword 
        /// </summary>
        /// <param name="taxField"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private static Term EnsureKeyword(TaxonomyField taxField, string name)
        {
            var ctx = taxField.Context;
            var taxSession = TaxonomySession.GetTaxonomySession(ctx);
            var termStore = taxSession.GetDefaultKeywordsTermStore();
            var keywords = termStore.KeywordsTermSet.GetAllTerms();
            var result = ctx.LoadQuery(keywords.Where(k => k.Name == name));
            ctx.ExecuteQuery();
            var keyword = result.FirstOrDefault();
            if (keyword != null)
            {
                return keyword;
            }
            keyword = termStore.KeywordsTermSet.CreateTerm(name, DefaultLanguage, Guid.NewGuid());
            ctx.Load(keyword);
            ctx.ExecuteQuery();
            return keyword;
        }

        /// <summary>
        /// Retrieve formatted Term string
        /// </summary>
        /// <param name="term"></param>
        /// <returns></returns>
        private static string GetTermString(Term term)
        {
            return string.Format("-1;#{0}{1}{2}", term.Name, TaxonomyGuidLabelDelimiter,term.Id);
        }

        private static string GetTermsString(IEnumerable<Term> terms)
        {
            var termsString = terms.Select(GetTermString).ToList();
            return string.Join(";#", termsString);
        }



        private const string TaxKeywordFieldName = "TaxKeyword";

        private const int DefaultLanguage = 1033;

        private const string TaxonomyGuidLabelDelimiter = "|";
    }
}
更多详情请关注帖子

using (var ctx = new ClientContext(webUri))
{
    var list = ctx.Web.Lists.GetByTitle(listTitle);
    var item = list.GetItemById(itemId);
    KeywordsManager.SetTaxKeywordValue(item,new []{"2013","2010"});
    item.Update();
    ctx.ExecuteQuery();
}