.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Update Managed Metadata field programmatically

Posted By:volvo       Posted Date: December 03, 2013    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Below code blocks explains how to update Multi Value Managed Metadata field programmatically
 

 string[] terms=Terms array;

            SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["Shared Documents"];
            SPListItem item = list.Items[0];
            TaxonomySession taxonomySession = new TaxonomySession(web.Site);
            TaxonomyField taxonomyField = list.Fields[listFieldName] as TaxonomyField;
            TaxonomyFieldValueCollection collection = new TaxonomyFieldValueCollection(taxonomyField);
            
            foreach (string str in terms)
            {
                TermStore termStore = taxonomySession.TermStores["Managed Metadata Service];
                Group group = termStore.Groups["Group name"];
                TermSet termSet = group.TermSets["Term Store name"];
                Term term = termSet.Terms["Term Value"];
                TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(taxonomyField);
                taxonomyFieldValue.TermGuid = term.Id.ToString();
                taxonomyFieldValue.Label = term.Name;
                collection.Add(taxonomyFieldValue);
            }
            

            taxonomyField.SetFieldValue(item,collection);
            item.Update();
?


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend