3

I have requirement to create the termGroup in TermStore.

 private void ProvisionTermGroups(SPFarm farm)
            {
                DebugWriter.Write("Started processing of term groups", this);
                foreach (TermGroup termGroup in this.Farm.ManagedMetadata)
                {

                        if (termGroup.Action == Action.Add)
                        {
                            //TODO: Code processing of term groups
                            foreach (TermSet termSet in termGroup.TermSets)
                            {
                                //TODO: Code processing of term sets
                                foreach (Term term in termSet.Terms)
                                {
                                    //TODO: Code processing of term
                                }
                            }
                        }
                  }
        }

My code structure as above.

How can i get the Site collection context of central administration from the FARM object to provision Term Group in Term Store ?

I have tried getting the default server from the local.farm but i am not able to get the Sharepoint Central Administration of the "SpServer" ?

Can i get term-store Object from the Service Instances in farm?

2 Answers 2

2

Try using below code

var service = SPFarm.Local.Services.GetValue<SPWebService>(string.Empty);
foreach (SPWebApplication webApplication in service.WebApplications)
{
    //GetAllSitesFromWebApplication(webApplication.Sites);
}
1
  • Not working as expected. Need something else.
    – User5590
    Sep 1, 2016 at 10:01
0

Find one similar question
Try this

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
SPAdministrationWebApplication.Local;

Your Answer

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

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