In my series of posts about using Taxonomy Fields in SharePoint 2010 I am using code to do all kinds of stuff with Taxonomy Fields and Terms from code. Because I can´t leave those fascinating Taxonomy Fields for what they are, here is yet another post about this subject
This is a follow up on my previous posts on this subject:
Using Taxonomy Fields in SharePoint 2010 - Part I
Using Taxonomy Fields in SharePoint 2010 - Part II
Using Taxonomy Fields in SharePoint 2010 - Part III
This post is meant for those of you that have read the previous posts (or attended one of my sessions on Managed Metadata Fields), and want to know more in order to write better code.
To get the Term Store from code I was using the following code in the Using Taxonomy Fields in SharePoint 2010 series of posts:
// set up the field for my termstore
TaxonomySession session = new TaxonomySession(site);
if (session.TermStores.Count > 0)
{
// get termstore
TermStore ts = session.TermStores[0];
// more code here...
}
This is not very robust code and should not be used in a production environment. The code above gets the first (default) Term Store from the Taxonomy Session. But what if there are multiple Term Stores associated with the Web Application? In this post I will show you how to get the Term Store programmatically the right way More...