Below code describes how to get the list item version history of a custom list using Client Object Model
- Add reference “Microsoft.sharepoint.client.dll” and “Microsoft.sharepoint.client.Runtime.dll”.
- Write Below Code.
class Program
{
static void Main(string[] args)
{
using (ClientContext ctx = new ClientContext(“SITE_URL”))
{
CamlQuery camlQuery = new CamlQuery();
Web web = ctx.Web;
ctx.Load(web,
w => w.ServerRelativeUrl,
w => w.Lists);
List list = web.Lists.GetByTitle(“LIST_TITLE”);
ctx.Load(list);
ListItemCollection itemColl = list.GetItems(camlQuery);
ctx.Load(itemColl);
ctx.ExecuteQuery();
foreach (ListItem item in itemColl)
{
File fileVersion = web.GetFileByServerRelativeUrl(web.ServerRelativeUrl + “/Lists/” + list.Title + “/” + item.Id + “_.000”);
ctx.Load(fileVersion);
FileVersionCollection fileVersionCollection = fileVersion.Versions;
ctx.Load(fileVersionCollection);
ctx.ExecuteQuery();
for (int iVersionCount = 0; iVersionCount < fileVersionCollection.Count; iVersionCount++)
{
FileVersion version = fileVersionCollection[iVersionCount];
fileVersionCollection.DeleteByID(version.ID);
}
ctx.ExecuteQuery();
}
}
}
}
This site is absolutely fabulous!
Keep up the great work guyz.
I think the admin of this site is in fact working hard in favor of his site, because here every stuff is quality based data.
Enjoye
I blog quite often and I really thank you for your information. Your article has really peaked my interest. I’m going to take a note of your blog and keep checking for new information about once a week. I opted in for your Feed as well.
Heya i’m for the first time here. I came across this board and I find It really useful & it helped me out much. I hope to give something back and aid others like you helped me.
I think this internet site has got some rattling superb info for everyone : D.