Tuesday, December 14, 2010

Ways To Migrate SharePoint Metadata Term Store

Share/Save/Bookmark

How to migrate metadata term store in sharepoint 2010?
the next moment i try to get a solution for the above problem i get more questions raised....

is it gonna be on the same farm or different?
will migration maintain the consistency in GUID of termstores/terms?

so lets look what sharepoint 2010 got for us in this relevant.

TaxonomyClientService - This service exposes the methods that can help in migrating the
metdata at group level, on top of it, doesnt accept GUID as parameter.
seems like this is built more of the different purpose than it come in use for developers.

TaxonmySession looks promising in migrating termstores from one sitecollection to other sitecollection(on different webapps) like shown here. But got limitation when migration comes to different farms.

There is no OOB webservice that can get us the SPSite object that can be used in the above code.
So the only possibility i see is to get the termstore info to a defined xml and make this as a base and recreate terms on the other farms. I'm sure same thing can be achieved using powershell as well.
Did you just find a better way of doing this?? then please let me know.



  Subscribe

Monday, December 13, 2010

Migrate Sharepoint 2010 Metadata or Taxonomy

Share/Save/Bookmark

Below is the simple code that migrates metadata or taxonomy from one store(metadata service) to other on same farm.


public class TaxonomyUtility
    {
        public void MigrateTaxonomy(SPSite sourceSite,SPSite destinationSite,string srctermstoreName, string destermStoreName string termGroup, string termSet)
        {
            TaxonomySession srcTSession = new TaxonomySession(sourceSite);
            TaxonomySession desTSession = new TaxonomySession(destinationSite);
            TermStore srcTermStore = srcTSession.TermStores[srctermstoreName];
            TermStore desTermStore = desTSession.TermStores[destermStoreName];

            Group desGroup;
            TermSet desTermSet;
            Term desTerm;
            foreach (Group g in srcTermStore.Groups)
            {
                // Carry permisssions
                //foreach (SPAce groupManager in g.GroupManagers)
                //{
                //}

                desGroup = desTermStore.CreateGroup(g.Name);
                foreach (TermSet tSet in g.TermSets)
                {
                    desTermSet = desGroup.CreateTermSet(tSet.Name, 1033);
                    foreach (Term t in tSet.Terms)
                    {
                        desTerm = desTermSet.CreateTerm(t.Name,1033);
                        getLabels(t,desTerm);
                        getTermsRecursive(t,desTerm);
                    }
                }
            }
            desTermStore.CommitAll();
        }

        public void getTermsRecursive(Term srcTerm, Term destTerm)
        {

            if (srcTerm.Terms.Count > 0)
            {
                foreach (Term sTerm in srcTerm.Terms)
                {
                    destTerm = destTerm.CreateTerm(sTerm.Name, 1033, sTerm.Id);
                    getLabels(sTerm,destTerm);
                    getTermsRecursive(sTerm, destTerm);
                }
            }
            else
            {
                return;
            }
        }

        public void getLabels(Term srcTerm,Term desTerm)
        {
            foreach (Label l in srcTerm.Labels)
            {
                desTerm.CreateLabel(l.Value, 1033, l.IsDefaultForLanguage);
            }
        }
    }
}

Voila ...u did it ;-)
Other ways of migrating metadata term store in sharepoint 2010 and their limitations are discussed here.

  Subscribe