pnpframework
pnpframework copied to clipboard
FileVersion.IsCurrentVersion is never true
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.