Getting Raw Field Values From SPListItem Or SPDataSourceViewResultItem

This method is helpful when you are working with the two different types, SPDataSourceViewResultItem providing custom type information:

[csharp]

 public object GetRawFieldValue(SPListItem item)
        {
            object fieldValue = null;
            if (item != null)
            {
                SPField fieldByInternalName = item.Fields.GetFieldByInternalName(InternalName);
                if (fieldByInternalName != null)
                {
                    fieldValue = item[fieldByInternalName.Title];
                }
            }
            return fieldValue;
        }

        public object GetRawFieldValue(T item)
        {
            object rawFieldValue = null;
            if (item is SPListItem)
            {
                SPListItem listItem = item as SPListItem;
                return GetRawFieldValue(listItem);
            }
            if (item is SPDataSourceViewResultItem)
            {
                SPDataSourceViewResultItem dataSourceViewResultItem = item as SPDataSourceViewResultItem;
                rawFieldValue = GetRawFieldValue(dataSourceViewResultItem);
            }
            return rawFieldValue;
        }

        public object GetRawFieldValue(SPDataSourceViewResultItem item)
        {
            object rawFieldValue = null;
            SPListItem spListItem = item.ResultItem as SPListItem;
            if (spListItem != null)
            {
                rawFieldValue = GetRawFieldValue(spListItem);
            }
            return rawFieldValue;
        }

[/csharp]

Share

Leave a Reply

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