This method is helpful when you are working with the two different types, SPDataSourceViewResultItem providing custom type information:
public object GetRawFieldValue(SPListItem item)
object fieldValue = null;
if (item != null)
SPField fieldByInternalName = item.Fields.GetFieldByInternalName(InternalName);
if (fieldByInternalName != null)
fieldValue = item[fieldByInternalName.Title];
public object GetRawFieldValue(T item)
object rawFieldValue = null;
if (item is SPListItem)
SPListItem listItem = item as SPListItem;
if (item is SPDataSourceViewResultItem)
SPDataSourceViewResultItem dataSourceViewResultItem = item as SPDataSourceViewResultItem;
rawFieldValue = GetRawFieldValue(dataSourceViewResultItem);
public object GetRawFieldValue(SPDataSourceViewResultItem item)
object rawFieldValue = null;
SPListItem spListItem = item.ResultItem as SPListItem;
if (spListItem != null)
rawFieldValue = GetRawFieldValue(spListItem);
Just want to the app?
Download here: http://spfielddiff.codeplex.com/
Recently at a client I was charged with investigating an application that dealt with incoming / outgoing requests. The data that built up the request objects was being stored as SPListItem’s within their respective SPList objects. After investigation, I was directed to keep the very loosely coupled and inefficient data storage scheme that was actually composed of three lists, rather than well designed metadata, the same. Since I was going to be augmenting the lists, it was necessary for me to have a utility that would allow me to source a list, and copy the relevant SPField objects regardless of base type to a destination list. As a result, I ended up writing my own little utility to automate this task.
The application itself is simple, one form, very few controls.
Start the application:
Give it a URL, get the lists:
This is my source SPList, it has a example fields of all the built-in types:
This is my destination SPList, it has a whole lot of nothing:
Doing the diff, obviously there are a lot of differences:
Then if you begin the copy operation, it will mimic the source list:
Have fun. The source is available on the codeplex site.
There was a question that was posted in the SharePoint development newsgroups as to how one would go about building the URL properties of SPFile objects into a string array. Here is a solution that seems to work just fine:
int counter = Folder.Files.Count;
string array = new string[counter + 1];
int index = 1;
foreach (SPFile file in Folder.Files)
You can see that we are firstly hydrating an SPFolder object representing the location where the holder of the relevant files are going to be looped through. Secondly, we declare the counter field that is going to take the SPFolder object and start a count on the files so that we can gauge the segments that are going to be built into the string array, incremented by uping the counter by a numeric of 1. Following, we are going to declare a index integer that is going to iterate through the SPFile objects that are in SPFolder.Files, then take the SPFile.URL property and add it to the string array. The result of which you could use for whatever. Obviously the SPFile.Url property could be adjusted to whatever SPFile property that you wanted, it wouldn’t have to be that. You could use it for doing other things like building an array of SPFile property metadata, or the likes if you wanted as well, pretty much whatever you want.
Hope this helps someone else.