Adding multiple values for same metatag using client object model
-
Tuesday, April 26, 2011 5:15 PM
I want to add multiple values for same managed metatag using clientobjectmodel. Anybody has ides? Iam able to add single value. This metatag is defined as Allow Multiple values.
All Replies
-
Wednesday, April 27, 2011 12:22 PM
Hi,
For example you have following terms: "Word", "Excel", "Visio" and your multiple managed metadata column name is "MyTag". So the code can be like as follows:
List<string> termValues = new List<string>();
termValues.Add("9;#Word|bbf906b2-4d4c-457a-93bf-c11438dd3f81");
termValues.Add("7;#Excel|bb9ff0f5-5e0f-4b4b-9c63-148ee8e44205");
termValues.Add("6;#Visio|023fa51d-5837-405b-8a7c-f430f2889242");
listItem["MyTag"] = termValues;
listItem["MyTagTaxHTField0"] = "9;#Word|bbf906b2-4d4c-457a-93bf-c11438dd3f81;7;#Excel|bb9ff0f5-5e0f-4b4b-9c63-148ee8e44205;6;#Visio|023fa51d-5837-405b-8a7c-f430f2889242";
listItem.Update();
clientContext.ExecuteQuery();where WssId and termGUID you can get as you do for single managed metadata.
Dmitry
Lightning
Tools Check out our SharePoint tools and web parts
-
Friday, April 29, 2011 4:45 PM
Thanks a lot. It worked.
Sai
-
Monday, August 01, 2011 2:36 PM
Hello Dmitry,
Thanks a lot for your reply - really helped a lot. However - I do still have some problems with your above example. Are there any Sharepoint settings that need to be set for this to work? For example I had to change the columndefinition of my equivalent of MyTagTagHTField0 (in my case its name is just a guid) via Sharepoint Manager.
In my environment updates won't throw errors, but I don't see Terms in Sharepoint unless I save the item once inside Sharepoint...It's working well with just one term (but in this case I don't need to update MyTagTaxHTField0 as well).I'd really appreciate your help or any hints you could provide!
Thanks a lot, Klaus
-
Thursday, May 24, 2012 2:30 PM
Hello Dmitry
From where did you get the ids 9, 7, 6 are they random ? it is the peice missing in my code here si what I wrote :
private void SetTaxonomyFieldMulti (string siteUrl, List CurrentList, ListItem listItem, Field field, string fieldValue)
{string termValueTaxHTField = String.Empty;
List<String> termValues = new List<string>();
List<String> termValueNotes = new List<string>();if (String.IsNullOrEmpty(fieldValue) || String.IsNullOrWhiteSpace(fieldValue)) return;
fieldValue = fieldValue.Trim();
string[] values = fieldValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
int index = 1;
foreach (string value in values)
{
string term = value.Trim();
string termId = GetTermId(siteUrl, field, value);if (!String.IsNullOrEmpty(termId))
{
termValues.Add(String.Format(@"{0};#{1}|{2}", index, term, termId));
termValueNotes.Add(String.Format(@"{0};#{1}|{2}", index, term, termId));
}
index++;
}for (int i = 0; i < termValueNotes.Count; i++)
{
termValueTaxHTField += termValueNotes[i];
if (i < termValueNotes.Count - 1)
{
termValueTaxHTField += ";";
}
}
listItem[field.InternalName] = termValues;
listItem[field.InternalName + "TaxHTField0"] = termValueTaxHTField;
}Thanks
Momo
- Edited by Mohamed Hachem Thursday, May 24, 2012 2:38 PM
- Edited by Mohamed Hachem Thursday, May 24, 2012 2:42 PM
- Edited by Mohamed Hachem Thursday, May 24, 2012 2:53 PM
-
Thursday, May 24, 2012 2:46 PM
Hi,
Here you may find the code how to get Wssid and Guid need wssid and guid of metadata to be able to enter it into a list
Dmitry
Lightning
Tools Check out our SharePoint tools and web parts |
Lightning Tools Blog -
Thursday, May 24, 2012 2:50 PM
Thank You Dmitry
I simulated your solution with the code I have written It works like charm
Merci
Momo

