Hello HarishKumarBH,
In order to add SharePoint 2010 Tags programmatically, you need to write code like this:
string listItemUrl = null;
using (SPSite site = new SPSite("http://somesite "))
{
using (SPWeb web = site.OpenWeb())
{
SPListItem item = web.Lists["ListName"].GetItemById(1);
listItemUrl = web.Url + "/" + item.Url;
}
}
SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default,
SPSiteSubscriptionIdentifier.Default);
//Create SocialTagManager Object
SocialTagManager stm = new SocialTagManager(context);
//Get the TaxonomySession
TaxonomySession ts = stm.TaxonomySession;
TermSetCollection termSetCollection = ts.DefaultKeywordsTermStore.GetTermSets("Keywords", 1033);
TermSet termSet = termSetCollection["Keywords"];
var result = from t in termSet.Terms where t.Name == "I like it" select t;
//Make sure that the tag name is already existed in the Store
Term term = stm.TaxonomySession.DefaultKeywordsTermStore.KeywordsTermSet.Terms["I like it"];
if(term != null)
//add the tag to item
stm.AddTag(new Uri(listItemUrl), term);
}
Please make sure that this code is run under proper identity. And the Tag Name is already existed in the Term store.
Thanks,
Lambda Zhao
TechNet Community Support
