[code lang=”c”]
using System;
using System.Net;
using System.Xml;
using Microsoft.SharePoint.Client;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
ClientContext context = null;
List list = null;
ListItemCollection itemCollection = null;
ListItem item = null;
string userName = string.Empty;
string password = string.Empty;
string dateHistory = string.Empty;
string commentHistory = string.Empty;
string editor = string.Empty;
string loginName = string.Empty;
try
{
using (context = new ClientContext(“http://SourceWebUrl”))
{
userName = “UserName”;
password = “PassWord”;
// Setting credential for the above site
context.Credentials = new NetworkCredential(userName, password);
context.Load(context.Web);
context.ExecuteQuery();
// Getting list by Title
list = context.Web.Lists.GetByTitle(“Custom List”);
context.Load(list, L => L.Id);
// Getting all items from selected list using caml query
itemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
//Loading selected list items
context.Load(itemCollection, IC => IC.Include(I => I.Id, I => I.DisplayName));
context.ExecuteQuery();
if (itemCollection != null && itemCollection.Count > 0)
{
for (int iCount = 0; iCount < itemCollection.Count; iCount++)
{
try
{
item = itemCollection[iCount];
ListService.Lists listService = new ListService.Lists();
listService.Url = context.Url + “/_vti_bin/Lists.asmx”;
listService.Credentials = context.Credentials;
//Getting all item versions from custon list item using List Web Service
XmlNode nodeVersions = listService.GetVersionCollection(list.Id.ToString(), item.Id.ToString(), “_UIVersionString”);
//looping all versions and getting ‘Modified’ and ‘Editor’ property of each version
foreach (XmlNode xNode in nodeVersions)
{
try
{
dateHistory = xNode.Attributes[“Modified”].Value;
dateHistory = FormatDateFromSP(dateHistory);
commentHistory = xNode.Attributes[“_UIVersionString”].Value;
loginName = xNode.Attributes[“Editor”].Value;
}
catch { }
}
}
catch (Exception ex) { }
}
}
}
}
catch (Exception ex) { }
}
private static string FormatDateFromSP(string dateHistory)
{
string result;
result = dateHistory.Replace(“T”, ” “);
result = result.Replace(“Z”, “”);
return result;
}
}
}
[/code]