SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to hook up some Site Columns (TaxonomyFields) to Term Sets in the the local (SiteCollection) term store. In some cases I may need to actually create the term sets and this code will be running as a FeatureReceiver on the Feature that is provisioning the SiteColumns (in CAML). So, I'm able to do this:

var session = new TaxonomySession(site);
var termStore = session.DefaultSiteCollectionTermStore;

But now how do I get the proper taxonomy group (the one private to my site collection) from the termStore.Groups collection? Do I really have to just loop through it looking for "Site Collection - SCHostname-path-to-site" and hope that funky url translation works out and that there are no odd access mappings at play? That seems very sloppy and I have to believe I'm approaching this wrong. Is there a way to find out the current site's "group association" so I can just call termStore.GetGroup(id)?

share|improve this question
up vote 2 down vote accepted

There is a new method in the 2010 SP1 API: Microsoft.SharePoint.Taxonomy.TermStore.GetSiteCollectionGroup(SPSite currentSite)

you can use like this source code:

session = new TaxonomySession(site);

                        //Retrieve all Term stores from site collection
                        termstores = session.TermStores;

                        foreach (TermStore termstore in termstores)
                            foreach (TermSet termSet in termstore.GetSiteCollectionGroup(site).TermSets)
                                foreach (Term term in termSet.Terms)
                                    row[0] = site.Url.ToString();
                                    row[1] = site.RootWeb.ToString();
                                    row[2] = termstore.Name.ToString();
                                    row[3] = termstore.GetSiteCollectionGroup(site).Name.ToString();
                                    row[4] = termSet.Name.ToString();
                                    row[5] = term.Name.ToString();
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.