2

I need to Read the URL from Term sets and term Programmatically, I tried

String taxonomyGroupName = "Test";
                        Group group;
                        TaxonomySession taxonomySession = new TaxonomySession(site);
                        TermStore termstore = taxonomySession.DefaultSiteCollectionTermStore;
                        GroupCollection groupCollection = termstore.Groups;
                        var groupCollectionEnum = groupCollection.GetEnumerator();
                        var termSetURL = SPContext.Current.Web.Url;
                        var termURL = HttpContext.Current.Request.Url;
                        string termSetName = "", termName = "";
                        while (groupCollectionEnum.MoveNext())
                        {
                            var currentGroup = groupCollectionEnum.Current;
                            if (currentGroup.Name == taxonomyGroupName)
                            {
                                group = currentGroup;
                                TermSetCollection termSetCollection = group.TermSets;
                                foreach (TermSet termset in termSetCollection)
                                {
                                    if (termset.CustomProperties["_Sys_Nav_TargetUrl"] == termSetURL.ToString())
                                    {
                                        termSetName = " / &nbsp" + termset.Name;
                                    }
                                }
                                foreach (TermSet termset in termSetCollection)
                                {
                                    TermCollection termCollection = termset.Terms;
                                    foreach (Term term in termCollection)
                                    {
                                        if (term.LocalCustomProperties["_Sys_Nav_SimpleLinkUrl"] == termURL.ToString())
                                        {
                                            var parentTermSet = term.TermSet;
                                            termName = " / &nbsp" + parentTermSet.Name;
                                        }
                                    }
                                }
                            }
                        }
                        if (!String.IsNullOrEmpty(termName))
                        {
                            TestTitle = termName;
                        }
                        else
                        {
                            TestTitle = termSetName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError("Error occured in Test - ", ex.ToString());
                }
            });
        }
    }
}

But I can't, Please suggest me to achieve this

  • LocalCustomProperties["_Sys_Nav_SimpleLinkUrl"] seems to return the simple url properly. perhaps there is something wrong with your validations – Tiago Duarte Nov 18 '16 at 9:42
  • Hi, How can we achieve this @TiagoDuarte – Suriya Nov 19 '16 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.