Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am creating a menu control that read terms from taxonomy term store. Get termSet and term is straight forward

        using (SPSite siteCollection = new SPSite(siteCollecitonUrl))
        {
            TaxonomySession taxSession = new TaxonomySession(siteCollection);
            TermStore taxStore = taxSession.TermStores[0];
            Group taxGroup = taxStore.GetSiteCollectionGroup(siteCollection);
            TermSet termSet = taxGroup.TermSets[strTermSetsName];

            foreach (term in termSet.terms)
            {
                term.???
            }
        }

but how to retrieve friendly URL or simple url link?

I could not find a property or method.

Thank you.

share|improve this question
add comment

3 Answers 3

up vote 6 down vote accepted

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

share|improve this answer
    
Anuja, thank you for the comment but it did not help. My question is if I have term store setup and simply want to retrieve term properties especially friendly URL and simple link. I do not like to create new terms by using NavigationTerm. –  wming Feb 8 '13 at 17:06
    
Hell Anuja. Your comment did not answer my question but point to the right direction. I managed to retrieve those properties by using NavigationTermSet. –  wming Feb 8 '13 at 18:37
    
Glad that it helps to you –  Anuja Feb 10 '13 at 18:53
add comment

The missing link is the bridge between TermSet and NavigationTermSet. As Anuja correctly stated, the responsible method is

NavigationTermSet.GetAsResolvedByWeb

So, here's my complete example - took me more than a day to figure it out (a different approach was working in an ASPX page but failed in the Web Service I was programming).

using Microsoft.SharePoint.Publishing.Navigation;
using Microsoft.SharePoint.Taxonomy;
using System;

TaxonomySession taxonomySession = new TaxonomySession(site);
StandardNavigationSettings navigationSettings = new WebNavigationSettings(site.RootWeb).CurrentNavigation;
TermStore termStore = taxonomySession.TermStores[navigationSettings.TermStoreId];
TermSet termSet = termStore.GetTermSet(navigationSettings.TermSetId);
NavigationTermSet navigationTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, site.RootWeb, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider);

foreach (NavigationTerm navigationTerm in navigationTerms)
{
    Console.WriteLine("navigationTerm.GetResolvedDisplayUrl(string.Empty): " + navigationTerm.GetResolvedDisplayUrl(string.Empty));
}

Hope that helps...

share|improve this answer
add comment
foreach (term in termSet.terms)
{
    string URL = term.LocalCustomProperties["_Sys_Nav_SimpleLinkUrl"];
}
share|improve this answer
    
This is incorrect –  Eric Herlitz Jan 4 at 12:51
    
@EricHerlitz What is incorrect about this? The solution worked for me when I tried it. –  thm51mb Apr 17 at 13:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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