kamagra how much to take

Properly Setting A Managed Metadata Field In CSOM

90% of the bullshit you will read on the net will allude to these messed up delimiters being the solution when trying to set a managed metadata field in Office 365. This is definitely not the way to do it.

  1. string valueTouse = String.Format("-1;#{0}|{1}", term.Name, term.Id);

Not only is this a terrible way to do it through shitty string literals, there are strongly typed means to accomplish the same thing that are better supported and slightly more readable. The appropriate approach looks like the following:

  1. Term item = null;
  2. List<Term> list = new List<Term>();
  3. foreach (Term term in termset.Terms)
  4. {
  5. context.Load(term);
  6. context.ExecuteQuery();
  7. if ([Do some sort of test here maybe?])
  8. {
  9. // don't do this ass crazy approach
  10. string valueTouse = String.Format("-1;#{0}|{1}", term.Name, term.Id);
  11. //rather add to collection
  12. item = term;
  13. }
  14. }
  15. list.Add(item);
  16. }
  17. field.SetFieldValueByCollection(spListItem, new Collection<Term>(list), 1033);
  18. spListItem.Update();
  19. context.ExecuteQuery();

Where in the above, the spListItem variable is a typed ListItem object. Much cleaner and relevant code. You can get the LCID for the SetFieldValueByCollection automagically if you wanted ala reflection or interrogating the relevant SharePoint proxy objects.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>