Thursday, June 13, 2013

Read column value for a list item programmatically

While reading list item’s column value using code, we get exception if column is empty/ null. To avoid such exception, we can use this line of code while reading column value.

if (item["ColumnInternalName"] != null && SPEncode.HtmlEncode(item["ColumnInternalName"].ToString()) != string.Empty && !string.IsNullOrEmpty(item["ColumnInternalName"].ToString()))
ImageFieldValue image = (ImageFieldValue)item["ColumnInternalName"];
imageURL = image.ImageUrl;
imageURL = "/_layouts/images/icon.png";

No comments:

Post a Comment