Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Hwo to get the label of a term from managed metadata using c#

$
0
0
Hi I am trying to get the label  of a term in a term set in managed metadata. if the term has two labels i am picking the second label. 
i have written this but it doesn't give me anything.
    private List<String> throwresultss(String s)
        {
            List<String> tags = new List<string>();
            try
            {
                TaxonomySession taxSession = new TaxonomySession(SPContext.Current.Site);
                TermSetCollection TermSet = taxSession.GetTermSets("Ourtermname"], int.Parse(ConfigurationManager.AppSettings["LCID"]));
                if (TermSet != null && TermSet.Count > 0)
                {
                    for (int i = 0; i < objects.Count; i++)
                    {
                        foreach (Term t in TermSet.ElementAt(0).Terms)
                        {
                            if (t.Labels.ToString().Contains(s))
                            {
                                if (t.Labels.Count > 1)
                                {
                                    tags.Add(t.Labels[1].ToString());

                                }

                                else
                                {
                                    tags.Add(t.Labels[0].ToString());

                                }


                            }


                        }
                    }

                }
            }

            catch { }

                      

            return tags;

        }


any help please

I am comparing if the term contains the string i am passing. if it contains then it checks the labels present. if there are mulitple labels for that term then it picks the second placed one that is number 2.  

kukdai



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>