.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson
Eminent IT

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Versioning in SharePoint

Posted By:Sunil Yadav       Posted Date: October 03, 2010    Points: 50    Category: SharePoint    URL: http://www.dotnetspark.com  

This article explains the basic concept of List or Document item versioning in SharePoint.


When version is enabled one can track, store and restore items in a list and files in a library. At a time current document or item can be up to 3 versions i.e. checked-out version, latest minor or draft version, and the latest published or major version.

SharePoint creates a new copy each time the document is uploaded or item is inserted, updated. For example when a list item is created first time, it creates a version 1.0 and when the same item is edited it again, it creates a new version 2.0 and so on which in turn increases database size. Now let's say we are keeping 100 versions of the single item or document, imagine what will be the database size. SharePoint provides version retain policy which limits the version to keep and helps reduce database size.

To enable version for a list or library go to List Settings and Select Versioning Settings.

Note: Custom list does not provide the feature of Minor or draft version. Library supports major and minor versioning.



Here the demo shows versioning with List items. Once the version is enabled on a list, list creates the version 1.0 of the item highlighted below.

Edit the item to create a new version. Here we modified the Status, % completed and Due Date as shown below. Item version 2.0 gets created.

In the below figure item version 1 is showing VersionNo=512

Edit the item and version 3.0 is created. Item version 2 is showing VersionNo=1024

Viewing, Restoring and recycling list item version using OM

SPSite site = new SPSite("http://localhost");
SPWeb web = site.OpenWeb();

SPList list = web.Lists["Tasks"];

Following code list all the item versions from Tasks list.

            foreach (SPListItem item in list.Items)
                SPListItemVersionCollection vercol = item.Versions;
                Console.WriteLine("Item version for " + item.Title);
                foreach (SPListItemVersion ver in vercol)
                    if (ver.IsCurrentVersion)
                        Console.WriteLine("Current Version " + ver.VersionLabel);
                    Console.WriteLine("Version Label " + ver.VersionLabel);
                    Console.WriteLine("Version ID " + ver.VersionId);

Following code restores item version to 2 (1024 Version Id) and new version is created.

 foreach (SPListItem item in list.Items)
                if (item["Created By"].ToString() == @"mossportal\sunil" && item.Title.ToString() == "Adding user in sharepoint site using powershell")
                  //item.Versions.RestoreByID(1024); //you can also restore item with VersionNo

Below code is used to recycle all the version of item except current.



Happy SharePointing!!!!!

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend