//Application Management -> Service Applications -> Manage service applications -> Managed Metadata Service
using System;using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint.WebControls;
namespace ECM_CreateTaxonomy.Layouts.ECM_CreateTaxonomy
{public partial class CreateTaxonomy : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void createTaxonomyButton_Click(object sender, EventArgs e)
{SPSite currentSite = SPContext.Current.Site;
TaxonomySession session = new TaxonomySession(currentSite);
TermStore termstore = session.TermStores["Managed Metadata Service"];
Group plantsGroup = termstore.CreateGroup("Plants");
TermSet flowersTermSet = plantsGroup.CreateTermSet("Flowers");
Term tulipsTerm = flowersTermSet.CreateTerm("Tulips", 1033);
Term orchidsTerm = flowersTermSet.CreateTerm("Orchids", 1033);
Term daffodilsTerm = flowersTermSet.CreateTerm("Daffodils", 1033);
Term vanillaTerm = orchidsTerm.CreateTerm("Vanilla", 1033);
vanillaTerm.SetDescription("A common orchid whose pods are used in desserts", 1033);
vanillaTerm.CreateLabel("Vanilla planifolia", 1033, false);
vanillaTerm.CreateLabel("Flat-leaved vanilla", 1033, false);
try
{
termstore.CommitAll();
resultsLabel.Text = "Taxonomy created successfully";
}
catch (Exception ex)
{
resultsLabel.Text = "There was an error: " + ex.Message;
}
}
}
}
-------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment