Skip to main content

Cloud

Creating a managed metadata field

Creating managed metadata fields is a bit different than creating fields of other types. Managed metadata fields are required to be linked to a term set before they can be used. The two types of taxonomy fields are TaxonomyField and TaxonomyFieldTypeMulti. The TaxonomyFieldTypeMulti is used for a multi valued managed metadata.

TaxonomyField field = new TaxonomyField(web.Fields, “TaxonomyFieldTypeMulti”, name);

TaxonomySession session = new TaxonomySession(site);

if (session.DefaultKeywordsTermStore != null)

{

// get the default metadata service application

TermSetCollection group = session.GetTermSets(strTermSetGroup, 1033);

TermSet termSet = group[strTermSetName];

}

// connect the field to the specified term

field.SspId = termSet.TermStore.Id;

field.TermSetId = termSet.Id;

field.TargetTemplate = string.Empty;

field.AnchorId = Guid.Empty;

field.Group = strGroupName;

field.AllowMultipleValues = true;

web.Fields.Add(field)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.