kamagra how much to take

Get A Field Value And Ensure For TaxonomyFieldValue

When working with generic field calls it is neccesary to compenstate for TaxonomyFieldValue since it is subject to the nasty SharePoint delimitors. In the below example, you can see how to do this in a semicolon delimited list, well I am just returning an object type but you get the idea:

  1. public object GetFieldValue(SPListItem item)
  2. {
  3. object fieldValue = null;
  4. if (item == null)
  5. {
  6. return fieldValue;
  7. }
  8. SPField fieldByInternalName = item.Fields.GetFieldByInternalName(InternalName);
  9. if (fieldByInternalName == null)
  10. {
  11. return fieldValue;
  12. }
  13. fieldValue = item[fieldByInternalName.Title];
  14. TaxonomyFieldValue taxonomyFieldValue = fieldValue as TaxonomyFieldValue;
  15. if (taxonomyFieldValue != null)
  16. {
  17. return (taxonomyFieldValue).Label;
  18. }
  19. if (!(fieldValue is TaxonomyFieldValueCollection))
  20. {
  21. return fieldValue;
  22. }
  23. StringBuilder builder = new StringBuilder();
  24. foreach (TaxonomyFieldValue value in (TaxonomyFieldValueCollection) fieldValue)
  25. {
  26. builder.Append(value.Label);
  27. builder.Append("; ");
  28. }
  29. return builder.ToString().TrimEnd(new[] {' '}).TrimEnd(new[] {';'});
  30. }
Share

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>