Sharepoint - How to retrieve taxonomy term friendly URL or simple URL?

You have to use NavigationTerm

To Create Term set:

  NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl,
                    term2Guid);

/// Verify that the NavigationTermSetView is being applied correctly.

 Assert.AreEqual(web.ServerRelativeUrl + "/term-2", term2.GetResolvedDisplayUrl(null).ToString());

In order to add new terms to navigation term set, you can use the following code:

// Obtain navigation term set
NavigationTermSet navigationTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, web, "GlobalNavigationTaxonomyProvider");
// Specify that this term set can be used for site navigation
navigationTermSet.IsNavigationTermSet = true;
// Creates new term pointing to an already existing URL outside of SharePoint
NavigationTerm term = navigationTermSet.CreateTerm("Bing Search", NavigationLinkType.SimpleLink, Guid.NewGuid());
term.SimpleLinkUrl = "http://www.bing.com/";
// Creates new term pointing to an existing SharePoint page
NavigationTerm term2 = navigationTermSet.CreateTerm("Target page", NavigationLinkType.FriendlyUrl, Guid.NewGuid());
term2.TargetUrl.Value = "~site/Pages/TargetPage.aspx";

Hope this helps

http://msdn.microsoft.com/en-us/library/jj163978.aspx


foreach (term in termSet.terms)
{
    string URL = term.LocalCustomProperties["_Sys_Nav_SimpleLinkUrl"];
}

Tags:

Taxonomy