码迷,mamicode.com
首页 > Web开发 > 详细

SharePoint: Create managed metadata field programatically

时间:2014-12-10 22:39:11      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:des   http   io   ar   os   sp   on   div   bs   

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

SharePoint: Create managed metadata field programatically

标签:des   http   io   ar   os   sp   on   div   bs   

原文地址:http://www.cnblogs.com/stevegp/p/4156434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!