Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer

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:

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();
                                    dt.Rows.Add(row);
                                }
                            }                                                                
                        }   
share|improve this answer
add comment

Your Answer

 
discard

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.