kamagra how much to take

Getting SharePoint Enumerable Field Values

More a quick tip than anything. In the below are two helper methods that make the process a lot easier. The first method will help to normalize the values for handling things like delimiters:

  1. private static string NormalizeValue(string fieldValue)
  2. {
  3. if (!string.IsNullOrEmpty(fieldValue))
  4. {
  5. var str = fieldValue;
  6. if (str.StartsWith(SPFieldMultiChoiceValue.Delimiter))
  7. {
  8. str = str.Substring(SPFieldMultiChoiceValue.Delimiter.Length);
  9. }
  10. if (str.EndsWith(SPFieldMultiChoiceValue.Delimiter))
  11. {
  12. str = str.Substring(0, str.Length - SPFieldMultiChoiceValue.Delimiter.Length);
  13. }
  14. return str.Replace(SPFieldMultiChoiceValue.Delimiter, ", ");
  15. }
  16. return string.Empty;
  17. }

Secondly, we use the helper method to return the enumerable value in a nice generic format.

  1. public static T ReturnEnumValue<T>(SPListItem listItem, string fieldName, T defaultValue) where T : struct
  2. {
  3. var str = listItem[fieldName] as string;
  4. if ((str == null) || string.IsNullOrEmpty(str))
  5. {
  6. return defaultValue;
  7. }
  8. var normalized = NormalizeValue(str);
  9. return (T) Enum.Parse(typeof (T), normalized);
  10. }
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>