Tuesday, September 25, 2012

SharePoint - Get List Item Versions Using Client Object Model


In last few posts I talked about how to work on file versions using web service and using client object model. Those posts described how to play around versions of file in document library. What if I want to get, delete or restore versions of list item?

Obviously, first thing we will do is to find any property related to version for “ListItem” class. But there is no such property available. L

What to do now?

There is a simple way, use methods in my last post and trick is to pass “fileUrl” parameter.

In case of file in document library, I suggested to pass this parameter like:
 

"/sites/prasad/teamsite/MyLibrary/testexcel.xlsx"
 

For list item we have to tweak this and pass “fileUrl” parameter as:
 

"/sites/prasad/teamsite/Lists/MyList/30_.000”
 

Here 30 is item id for item of which I want to get version history.
Yes, we are good to go now. We can play around versions of list items also. Hurray!!!

2 comments:

  1. Nice trick! But after getting the FileVersionCollection is there a way to convert a FileVersion (with limited properties) to a ListItem with all the properties of the item ? Thanks.

    ReplyDelete
  2. You can get a hint in my previous article.

    ReplyDelete