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.

  • 1
    Is this a question or an order for a coder? ;) – Robert Lindgren Jun 18 '14 at 17:22
  • Apology if my language is not correct.What else would i have done so it doesnt appear as order. – user13408 Jun 18 '14 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 :) – Robert Lindgren Jun 18 '14 at 17:30
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)

  • Voted Up+ helped me. – user13408 Jun 18 '14 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;
                    }
  • 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. – Supriyo SB Chatterjee Jun 18 '14 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, privacy policy and cookie policy