Programming for metadata in SharePoint 2010

May 31, 2011

Hi all. Today I want to tall about use metadata in SharePoint 2010, so Microsoft.SharePoint.Taxonomy.

If you get list items metadata, you can use Taxonomy Class:

TaxonomySession session = new TaxonomySession(site);

TermStore termStore = session.TermStores[Name service-application metadata];

Group group = termStore.Groups[Group name];

TermSet termSet = group.TermSets[Taxonomy termset name];

Term term = termSet.Terms[Term name];

If you can create new terms, you can use this code:

//Apply current culture

int lcid = CultureInfo.CurrentCulture.LCID;

//If terms don’t open for edit

if (!termSet.IsOpenForTermCreation)


termSet.IsOpenForTermCreation = true;



//Add new terms in list

term = termSet.CreateTerm(New term name, lcid);



Ok, if you use column of  type TaxomyField, you can write this code:

SPListItem oListItem = oList.Items[ID]

TaxonomyField taxField = oList.Fields[Название колонки] as TaxonomyField;

taxField.SetFieldValue(oListItem, term);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: