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

Azure OpenAI Chat in C# and Python

Azure OpenAI Chat in C#: // Install the .NET library via NuGet: dotnet add package Azure.AI.OpenAI --version 1.0.0-beta.5   using System; u...

Popular posts