Monday, July 23, 2012

ECM(Enterprise Content Management) Create Taxonomy Programatically in SharePoint 2010




//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

Featured Post

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management

Protect an API by using OAuth 2.0 with Azure Active Directory and API Management https://docs.microsoft.com/en-us/azure/api-management/api-...

Popular posts