Search code examples
sharepointnavigationmetadatafriendly-url

How to get friendly url of term sharepoint


I use SharePoint 2013, Managed MetaData Service to keep terms and related Navigation Links which are referenced my publishing pages.

For Example,

Page url -> Term -> Friendly URL
  • ~/Pages/Content.aspx?ctx=1 -> Contact -> ~/Summary/Contact
  • ~/Pages/Content.aspx?ctx=2 -> About -> ~/Summary/About
  • ~/Pages/Content.aspx?ctx=2 -> FAQ -> ~/Summary/FAQ

This is my plan and if I navigate the page manually with friendly url everything is fine. But I need to find friendly url by its referenced term something like that.

 string friendlyurl = term.GetFriendlyUrl();

but there is not a property or etc like that to get this.


Solution

  • I solved this problem. Just need to find term under site collection term set like below

    SPSite site = SPSite.Current.Site;
    TaxonomySession servis = new TaxonomySession(site);
    siteNavigationStore = servis.DefaultSiteCollectionTermStore;
    siteNavigationGroup = sitenavigationstore.GetSiteCollectionGroup(site);
    siteNavigationSet = sitenavigationgrup.TermSets["Term Set Name"];
    NavigationTerm navigatedTerm = NavigationTerm.GetAsResolvedByWeb(navigationterm, site.RootWeb, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);
    

    You can find friendlu URL like

    navigatedTerm.GetWebRelativeFriendlyUrl();