pnp / pnp/pnpframework

FileVersion.IsCurrentVersion is never true

Open
#884 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
259
Forks
161
Avg merge
10h 33m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported console-app example using FileVersion.IsCurrentVersion, file.Versions, and ExecuteQueryRetry. Reproduce the version-deletion error and inspect whether IsCurrentVersion is populated correctly for the current item in the loaded collection. Done means the current version is reliably identified and the deletion loop no longer attempts to delete it.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.