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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。