Tuesday, July 17, 2012

Strange behavior of SharePoint list versioning

Recently we are facing problem with SharePoint list versioning.
List item version is retrieving different (wrong) value.

We have a scenario where we have to compare two version of same list item.
So we think we will use object model and show user what item changed.
But when we had done that we are not able to understand what happen.
We are getting strange behavior in date time field and User (people picker) field.
We are not changing date field but when we are fetching previous version then we are getting around 7 hours different time and sometime because of this it will change the date also.

So for demo I had created a list with two columns
1) “Customuser”
2) “CustomDate”

Then unable the versioning on that list.
Then add item in that list.
Then change the title only, do not change other field what I found is here.
First Version


Second Version



Below is the code to check
ColumnName = "CustomDate";
CurrentVersion = item[ColumnName].ToString();
OldVersion = item.Versions.GetVersionFromLabel("2.0")[ColumnName].ToString();
Values
Currentversion = 4/16/2009 12:00:00 AM
Old version = 4/16/2009 7:00:00 AM



ColumnName = "CustomUser";
CurrentVersion = item[ColumnName].ToString();
OldVersion = item.Versions.GetVersionFromLabel("2.0")[ColumnName].ToString();

Values
CurrentVersion = 7;#SPVM\parth
Old version = 7;#SPVM\parth,#SPVM\parth,#,#,#SPVM\parth


We gor shocked when we checked Created and Created by (Auther) column.
And that column also gives some strange detail.

ColumnName = "Created";
CurrentVersion = item[ColumnName].ToString();
OldVersion = item.Versions.GetVersionFromLabel("2.0")[ColumnName].ToString();
CurrentVersion = 4/16/2009 9:42:41 AM
Old version = 4/16/2009 4:42:41 PM

ColumnName = "Created By";
CurrentVersion = item[ColumnName].ToString();
OldVersion = item.Versions.GetVersionFromLabel("2.0")[ColumnName].ToString();
CurrentVersion = 1;#SPVM\administrator
OldVersion = 1;#SPVM\administrator,#SPVM\administrator,#administrator@sharepoint.local,#,#SPVM\administrator

No comments:

Post a Comment