Introduction: I have created a custom list which contains the following columns I have the following Group, Term Set and Terms in the term store Term Set Settings for TaxonomyField: Steps Involved:
namespace ConsoleApplication4 { class Program { static void Main(string[] args) { using (SPSite site = new SPSite("http://serverName:25374/sites/TeamEng02/")) { using (SPWeb web = site.OpenWeb()) { TaxonomySession taxonomySession=new TaxonomySession (site); TermStore termStore=taxonomySession.TermStores["Metadata Service Application Proxy"]; Group group=termStore.Groups["Group"]; TermSet termSet=group.TermSets["TermSet"]; Term term=termSet.Terms["Term"]; SPList list = web.Lists.TryGetList("Test"); if (list != null) { TaxonomyField taxonomyField = list.Fields["TaxonomyField"] as TaxonomyField; TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(taxonomyField); taxonomyFieldValue.TermGuid = term.Id.ToString(); taxonomyFieldValue.Label = term.Name; SPListItem item = list.Items.Add(); item["Title"] = "Sample"; item["TaxonomyField"] = taxonomyFieldValue; item.Update(); list.Update(); } else { Console.WriteLine(list.Title + " does not exists in the list"); } Console.ReadLine(); } } } }
Conclusion: Thus value is successfully added to the taxonomy field using SharePoint Object Model.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: