Thursday, April 16, 2009

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


Now we don’t know how to solve this problem til now
We just share this as we found this scenario. May be is this a bug of sharepoint or we are not able to understand how this functionality works :) ?

5 comments:

Anonymous said...

good work man..
why don't you send it to Microsoft guys.

Anonymous said...

Anybody found a solution yet? I am running into the same problem.

SharePoint Kings said...

nope, not update yet from Microsoft.

We already sent to them.

Majid said...

The time difference might be due to one being in local time.
From documentation: "Unlike all other members in the object model, the indexer for a DateTime field returns values in local time on the site."

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem(v=office.12).aspx

SharePoint Kings said...

Hay Majid,
Thanks a lot.

this will help a lot of people.

Thanks,
SharepointKings Team




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com