Explore the Experience in SharePoint 2013

Tuesday, October 28, 2014

Get Latest Version of a SharePoint List Item in 2010,2013

No comments

Hi Guys ,

Some times we come across a situation where we need to know the latest list item version .

Please find the method to get the latest list item version using Server object model.


 Public SPListItem TopListItemVersion(SPListItem item) 
            {      
                if ((item.Versions != null) && (item.Versions.Count > 0)) 
                { 
                    SPListItemVersionCollection versions = item.Versions; 
                    SPListItem latestItemversion; 
                    if (item.Versions.Count > 1) 
                        latestItemversion= item.Versions[item.Versions.Count - 1].ListItem; 
                    else 
                        latestItemversion= item.Versions[0].ListItem; 
     
                    return latestItemversion; 
                } 
                else 
                 
                    return item;            
             } 

No comments :

Post a Comment