I am trying to create taxonomies in my central administration.
I am trying to do like this.
When it comes to TermStore class, it is giving this exception. How to resolve this. Is there any mistake in giving the URL of site?
Need to activate any services other than Managed MetaData Service
I am adding my complete code here
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Office;
using Microsoft.SharePoint.Taxonomy;
namespace TaxonomiesEx
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://sp2010:8080/personal/Home"))
{
try
{
//instantiate a new taxonomy session for the current site.
TaxonomySession ts = new TaxonomySession(site);
//instantiates the name "Managed Metadata Service Connection" for the current session.
TermStore termstore = ts.TermStores["Managed Metadata Service Connection"];
//create a group object
Group group1 = termstore.CreateGroup("Group1");
TermSet termset1 = group1.CreateTermSet("TermSet1");
Term term1 = termset1.CreateTerm("Hello", 1033);
Term term2 = termset1.CreateTerm("Hi", 1033);
Term term3 = termset1.CreateTerm("Glad to meet you", 1033);
Term term1a = term1.CreateTerm("How are you", 1033);
termstore.CommitAll();
term1.SetDescription("This is first One", 1033);
term1.CreateLabel("First Term", 1033, false);
term1.CreateLabel("TermOne", 1033, false);
termstore.CommitAll();
Console.WriteLine("Success....");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Error Occured \n {0}",e.Message);
Console.ReadLine();
}
}
}
}
}