• SharePoint: Create managed metadata field programatically


    The following piece of code creates a managed metadata column with internal name "BusinessLocation" and display name "Business Location"

    using (SPSite site = new SPSite("http://intranet.contoso.com/sites/contracts"))
    {
        using (SPWeb web = site.OpenWeb())
        {                 
            TaxonomySession taxonomySession = new TaxonomySession(site);
            TermStore termStore = taxonomySession.TermStores["Managed Metadata Service"];
            Group group = termStore.Groups["Corporate Taxonomy"];
            TermSet termset = group.TermSets["Geography"];
            TaxonomyField taxonomyField = web.Fields.CreateNewField("TaxonomyFieldType", "BusinessLocation") as TaxonomyField;
            taxonomyField.Description = "Loction of business house.";
            taxonomyField.SspId = termStore.Id;
            taxonomyField.TermSetId = termset.Id;
            taxonomyField.AllowMultipleValues = false;
            taxonomyField.Group = "My Content Types";
            web.Fields.Add(taxonomyField);
            TaxonomyField field = site.RootWeb.Fields["BusinessLocation"] as TaxonomyField;
            field.Title = "Business Location";
            field.Update(true);
        }
    }

    来自 <http://www.sharepointnadeem.com/2012/02/create-managed-metadata-field.html

    如果,您认为阅读这篇博客对你有帮助,点击一下左下角的[推荐] 如果,你想了解我的动态,点击一下左下角的[关注我] 因为,你们的支持正是我学习的动力 如需转载,请注明出处 如果对文章有任何问题,都可以再评论中留言,我会尽可能的答复您,谢谢你的阅读
  • 相关阅读:
    SpringMVC+Shiro权限管理(转载)
    面试常见问题(转载)
    JavaScript 五种(非构造方式)继承
    JavaScript 五种(构造方式)继承
    Quartz.Net 基于XML配置启动
    jexus防止产生 *.core文件
    Last-Modified、ETag、Expires和Cache-Control
    正则表达式记录
    C# 操作mongodb子文档
    ASP.NET Core "完整发布,自带运行时" 到jexus
  • 原文地址:https://www.cnblogs.com/stevegp/p/4156434.html
Copyright © 2020-2023  润新知