0

I want to have a common usable function which can return Term object.

I thought of

public static TaxonomyTerm GetTaxonomyTerms(this SPSite site, string groupName, string  termSetName)
{

}

TaxonomyTerm is class of having property id,name. Structure of TaxonomyTerm

public class TaxonomyTerm
{
 public TaxonomyTerm()
{
    this.Terms = new List<TaxonomyTerm>();
}
public Guid Id { get; set; }
public string Name { get; set; }
public List<TaxonomyTerm> Terms { get; set; }
}

I need help to write this to return the instance of this class. Thanks.

3
  • 1
    Is this a question or an order for a coder? ;) Commented Jun 18, 2014 at 17:22
  • Apology if my language is not correct.What else would i have done so it doesnt appear as order.
    – user13408
    Commented Jun 18, 2014 at 17:27
  • For me it's not really to language, it is more the lack of information about what you have tried so far, different codes you have tried and so on :) Commented Jun 18, 2014 at 17:30

3 Answers 3

0

This post covers the basics of accessing taxonomies in PowerShell - in steps -

  1. Connect to target site's Metadata service.
  2. Access termstore group & termset
  3. Iterate through termset items

(Since it's in PowerShell - it can be translated into other languages)

1
  • Voted Up+ helped me.
    – user13408
    Commented Jun 18, 2014 at 18:29
0

Thanks Supriyo for guidance.I was also trying with similar other resources and finally could get on right track. Here it looks like what I accumulated.

                    {
                    var session = new TaxonomySession(SPSite object);
                    var store = session.TermStores[MyConstants.StoreName];
                    var group = store.Groups[groupName];

                    var termSet = group.TermSets.FirstOrDefault(t => t.Name.Trim().ToLower() == termSetName.Trim().ToLower());

                    if (termSet != null)
                    {
                        taxonomy = new TaxonomyTerm { Id = termSet.Id, Name = termSet.Name };
                    }
          return taxonomy;
                    }
1
  • I think changing the name 'TaxonomyTerm' to 'TaxonomyTerms' may help in reading the code (it's returning a list). I find 'prototyping' in PowerShell a much faster way of developing solutions since most of the complexity calls are to the SharePoint object model itself. Commented Jun 18, 2014 at 18:54
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
namespace EMM
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://servcerName:10/"))
            {
                TaxonomySession taxonomySession = new TaxonomySession(site);
                TermStore termStore = taxonomySession.TermStores["MMS"];
                Group group = termStore.Groups["SharePoint Group"];
                TermSet termSet = group.TermSets["BCS"];
                TermCollection termCol = termSet.Terms;
                foreach (Term term in termCol)
                {
                    Console.WriteLine(term.Name);
                }
                Console.ReadLine();
            }
        }
    }
}

Original Post: http://www.c-sharpcorner.com/uploadfile/anavijai/taxonomy-term-in-sharepoint-2010/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.