pnpframework icon indicating copy to clipboard operation
pnpframework copied to clipboard

FileVersion.IsCurrentVersion is never true

Open lasyan3 opened this issue 2 years ago • 0 comments

Hi, I created a console app to delete old versions (excluding the current version and versions newer than 3 months ago). The code is:

var file = ctx.Web.GetFileById((Guid)item["UniqueId"]);
ctx.Load(file);
ctx.Load(file.Versions);
ctx.ExecuteQueryRetry();
var lstVersionsToDelete = file.Versions.Where(v => !v.IsCurrentVersion && v.Created <= DateTime.Now.AddMonths(-3)).ToList();
var lstVersion = lstVersionsToDelete.ToList();
foreach (var version in lstVersion)
{
    version.DeleteObject();
}
ctx.ExecuteQueryRetry();

But sometimes I get an error "You cannot delete the current version"! After investigation it seems the IsCurrentVersion property is never set to true. Could this be an issue with the framework? Thanks.

lasyan3 avatar May 23 '23 13:05 lasyan3