View version information of SharePoint List Items

There was a request to write code to view the history of a SharePoint List. I was surprised to note that the many didn't even know that a SharePoint List can maintain versions though all are aware that Document Libraries can maintain versions. Here is a screen shot of where you need to go to enable versions for Lists.

MORE...



Of course you can view the version history in the Datasheet View but that is not a straight forward way to display the List history and it also needs Office installed on the PC. Hence I wanted to create a webpart to display the List History in a end user customizable webpart.

I kept it simple. Look at the following screen shot where you configure the webpart.



As you can see, you can enter the name of the List and a column from the List and voila the webpart displays the versions of the listitems and the data in the column (that you configured) for each version. Since I have provided the code too you can add more columns if you want. Also I have enabled the property to set how many items you want displayed on a single page so that you can support pagination.If you were wondering how you would access the above Configuration Screen, have a look at the following image.



Here is the list that I have used in my example. It has four list items.



Here is a screenshot of how the webpart looks. I have 4 list items and the "First Item" has 3 versions and the "Third Item" has 4 versions. The other two items (viz: "Second Item" and "Fourth Item") have no versions.



Also note that I have displayed the webpart twice. Once with pagination enabled and once without pagination all though configuration.

The links to the code is here and you are free to add any further enhancements to it.

In the bin/debug folder of the solution you would find the SHarepoint solution file "ListAuditHistory.wsp". To deploy the solution and enable the associated feature on a web site copy this file and the "setup.bat" file (found in the same folder) to your server. Open the "setup.bat" file and locate the following lines

set DefaultWebUrl=http://
set DefaultSiteUrl=http://
set TargetWebUrl=http://
set TargetSiteUrl=http://

Suffix your web site address in all four lines. Now run the "setup.bat" file and it should do the trick for you. After that you can go to your site and go to "Edit Mode" and add the web part to your page. Here is a screen shot of where it would be located.




BTW: When you look into the code you might ask the question why I haven't used SPGridView and used GridView instead. Well it is to support the AutoGenerateColumns property. If you write code to bind each column to the GridView than you can just change the definition from GridView to SPGridView (just suffix SP in two places) and you would be fine.


Posted by: Ronney on Apr 30, 10 | 2:05 pm | Profile


name
 *
Email
 *
Location
Homepage


 *
Show email   Remember me

Notify me when someone replies to this post?
* required fields