0

I'm using Managed navigation (Taxonomy Navigation) feature of SharePoint Server 2013. I've setup variation for 2 languages (en and fr).

Using the code below, I managed to get the relative url of the peer site:

  string url = Variations.GetPeerUrl(SPContext.Current.Web, currentUrl, label.Title);

For example when I'm in http://www.sample.com/en/Demo , using the code above I get /fr/Pages/Demo.aspx

What I wants is the managed navigation term or friendly url for it which is something like http://www.sample.com/fr/Demo

How can achieve that, what is the correct api that I should use here.

Thanks

1 Answer 1

1

Agamand,

First from the complete URL you should get the List Item, using SPWeb.GetListItem

See example here:
get SPListItem reference from a url

Than you can use following snippet to get Terms for the Page:

//retrieve the terms used for the navigation (this can be multiple terms)
IList<NavigationTerm> terms = TaxonomyNavigation.GetFriendlyUrlsForListItem(item, false);

string url = string.Empty;

//check if the pages has terms associated with it
if (terms.Count > 0) {
    //use the GetResolvedDisplayUrl to retrieve the page friendly urls
    url = terms[0].GetResolvedDisplayUrl(string.Empty);

    //Or you can use GetWebRelativeFriendlyUrl
} else {
    //if the page does not have any terms get the normal url
    url = item.File.Url;
}

I hope this helps

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.