2Who
2Who

Reputation: 15

How to only load retained list item version of a SharePoint list using CSOM?

My use case is to use CSOM to create all the urls to all the document versions and then to download them with System.Net.WebClient like this: https://myCompany.com/sites/mySite/_vti_history/2561/myLibrary/myDocument.docx

We have a document library with the setting to only keep drafts for 1 major version. But when I load the Versions of the list item via CSOM:

Microsoft.SharePoint.Client.ClientContext _ClientContext = init();

public ListItemVersion[] GetListItemVersions(ListItem ListItem)
{
    ListItemVersionCollection listItemVersionCollection = ListItem.Versions;
    this._ClientContext.Load(listItemVersionCollection);
    this._ClientContext.ExecuteQuery();
    return listItemVersionCollection.ToArray();
}

Then it also returns the older drafts, which shouldn't be retained. This creates urls to document versions which are not retained so the download returns a 400 Bad Request.

Is there a way to only get the retained drafts according to the list version settings? Is is possible to differentiate between retained and unretained versions?

I searched through the properties of the ListItemVersion class and compared the values of a retained version with a version that should not be retained. But I couldn't find a property which defines whether the version is retained or not. Just skipping all 400s while downloading is not a viable option for me, since I don't want to miss any retained version.

Upvotes: 0

Views: 38

Answers (0)

Related Questions