Domanda

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?

È stato utile?

Soluzione

Try using below code

var service = SPFarm.Local.Services.GetValue<SPWebService>(string.Empty);
foreach (SPWebApplication webApplication in service.WebApplications)
{
    //GetAllSitesFromWebApplication(webApplication.Sites);
}

Altri suggerimenti

Find one similar question
Try this

Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb =
SPAdministrationWebApplication.Local;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top