Get List Item Versions using CSOM SharePoint 2013 On Premise RRS feed

  • Question

  • Hello,

    We are trying to get the versions data of list items (SPList and not Document Library just to be clear) using CSOM in our console app. We found that we can get the versions data in SharePoint Online and also using JSOM.

    But when we run the console app for SharePoint On Premise site to get the versions data we get the error as: "Field or property "Versions" does not exist."

    List spList = web.Lists.GetByTitle("TestList");
    CamlQuery query = new CamlQuery();
    ListItemCollection items = spList.GetItems(query);
    //clientcontext.Load(items, i => i.IncludeWithDefaultProperties(it => it.Versions));
    if (items != null && items.Count > 0)
    	foreach (var item in items)
    		ListItemVersionCollection lVersions = item.Versions;
    		clientcontext.ExecuteQuery();//This throws the mentioned error

    Could someone help us to know if getting versions data for ListItem works in SharePoint 2013 On Premise?

    We checked this link https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-september-2017 which is for SharePoint Online. Do we have any similar update for SharePoint 2013 on premise?

    • Edited by SuPar Wednesday, March 14, 2018 3:01 PM
    Wednesday, March 14, 2018 1:08 PM


All replies

  • Hi,

    The CSOM doesn’t implement the ListItemVersionCollection as SharePoint online yet, so try to get version history by web service, you could use the help SPServices JS library also.

    Here are links for your reference.



    Best Regards,


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    • Marked as answer by SuPar Thursday, March 15, 2018 10:00 AM
    Thursday, March 15, 2018 2:12 AM
  • Hi

    You can try below code:

    public DataSet GetDoucmentHistory(string siteUrl, string listName, int id) { using (ClientContext ctx = new ClientContext(siteUrl)) { ctx.Credentials = new NetworkCredential(_username, _password, _domain); var file = ctx.Web.Lists.GetByTitle(listName).GetItemById(id).File; var versions = file.Versions; ctx.Load(file); ctx.Load(versions); ctx.Load(versions, vs=>vs.Include(v=>v.CreatedBy)); ctx.ExecuteQuery(); foreach (FileVersion fileVersion in versions) {

    Console.Write(fileVersion.CreatedBy.Title); Console.Write(fileVersion.CheckInComment); Console.Write(fileVersion.VersionLabel); Console.Write(fileVersion.IsCurrentVersion); } } }

    Please remember to mark the replies as answers if they helped.
    Linyu - SharePoint Engineer
    QQ Group: 72637444

    • Proposed as answer by a.boersch Monday, March 25, 2019 9:50 AM
    Thursday, March 15, 2018 5:50 AM
  • Hi,

    Yes we can get the versions, but how do we actually get the content attached to the older versions?

    I'm in a situation where I want to get SPFile instance of previous version and then get the content of property by file.ListItemAllFields["WikiField"].ToString().

    Currently I'm stuck that I am getting content of latest version and not of older versions.

    Has anyone came across such sistuation and got the content sucessfully?


    Friday, September 13, 2019 6:46 AM