How to get list item version history of a custom list using Client Object Model

Below code describes how to get the list item version history of a custom list using Client Object Model

  1. Add reference “Microsoft.sharepoint.client.dll” and “Microsoft.sharepoint.client.Runtime.dll”.
  2. 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();

}

}

}

}

Previous Post
Next Post

Comments

Lazaro Creekbaum

This site is absolutely fabulous!

Jenniffer Hastedt

Keep up the great work guyz.

rare earth magnets home depot

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.

false eyelashes walmart

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.

plus size onesies 4x

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.

Leonida Sciotti

I think this internet site has got some rattling superb info for everyone : D.

Leave a Reply

Your email address will not be published. Required fields are marked *