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)?

1 Answer 1


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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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