SharePoint ListItem Versioning and Changes in C#

If we need to enable SharePoint list versioning then navigate List Settings–>Versioning settings and then select radio button of create a version each time you edit an item in this list? Section, optionally limit the number of versions to retain is help to reduce DB size, SharePoint list does not support minor version and draft version.

We can also enable SharePoint List versioning using c#

using (SPSite spsite = new SPSite("http://win7/"))
{
SPWeb spweb = spsite.OpenWeb();
SPList list = spweb.Lists["CustomList"];
list.EnableVersioning = true;
list.Update();
}

Retrieve SPListItem versions using c#

using (SPSite spsite = new SPSite("http://win7/"))
{
SPWeb spweb = spsite.OpenWeb();
SPListItemCollection listitems = spweb.GetList("http://win7/Lists/CustomList").Items;

foreach (SPListItem listitem in listitems)
{
//listitem.Versions.RestoreByID(5);
foreach (SPListItemVersion versionItem in listitem.Versions)
{
Console.WriteLine("VersionId :" + versionItem.VersionId);
Console.WriteLine("VersionLabel :" + versionItem.VersionLabel);
Console.WriteLine("IsCurrentVersion :" + versionItem.IsCurrentVersion);
Console.WriteLine("ListItem.Title :" + versionItem.ListItem.Title);
Console.WriteLine("Created :" + versionItem.Created);
Console.WriteLine("CreatedBy :" + versionItem.CreatedBy);
Console.WriteLine("Level :" + versionItem.Level);
}
}
}

Retrieve SPListItem version changes using c#

using (SPSite spsite = new SPSite("http://win7/"))
{
SPWeb spweb = spsite.OpenWeb();
SPListItemCollection listitems = spweb.GetList("http://win7/Lists/CustomList").Items;

foreach (SPListItem listitem in listitems)
{
for (int i = 0; i < listitem.Versions.Count - 1; i++)
{
SPListItemVersion oldVersion = listitem.Versions[i];
SPListItemVersion latestVersion = listitem.Versions[i + 1];
foreach (SPField field in oldVersion.Fields)
{
if (field.ShowInVersionHistory == false)
{
continue;
}

if (latestVersion == null)
{
Console.WriteLine("  > {0} changed to \"{1}\"",
field.StaticName, oldVersion[field.StaticName]);
continue;
}

if (oldVersion[field.StaticName].Equals(latestVersion[field.StaticName]))
{
continue;
}

Console.WriteLine("  > {0} changed from \"{1}\" to \"{2}\"",
field.StaticName, latestVersion[field.StaticName], oldVersion[field.StaticName]);
}
}

}
}
Console.ReadLine();

Debugging SharePoint 2010 Client Object Model Silverlight Application

Step 1

Download and install following Visual Studio 2010 plugins

Visual Studio 2010 SharePoint Power Tools

Silverlight SharePoint Web Parts

Step 2

Create new Silverlight project and then create new Empty SharePoint Project in sandbox Solution

Step 3

Right click SharePoint Project then Click Properties SharePoint tab Check Enable Silverlight Debugging

Step 4

SharePoint Project Create new item of Silverlight webpart

Step 5

Add reference in SharePoint Silverlight OM dll in “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin”
following location

Step 6

Add Following Code in Silverlight Project App.xaml.cs at Application_Startup function
ApplicationContext.Init(e.InitParams, SynchronizationContext.Current);

Step 7

Set as Startup in SharePoint Project, now we can run (f5) then navigate “Site pages” then we can see then new page relevant name of project,We can access the page for debugging.

Restore Deleted Items From Recycle Bin in SharePoint 2010

Step 1

If we need change recycle bin setting then Navigate Central Administration –> Manage Web Application –>Select Web Application then select General Setting –>General Setting
here we can see the recycle bin setting.

Step 2

If we need restore deleted items from recycle bin then navigate Recycle Bin –> Site Collection Recycle Bin –> Deleted from end user Recycle Bin , here we can select and restore the deleted items .