pnpjs icon indicating copy to clipboard operation
pnpjs copied to clipboard

How to download older version files?

Open gomain opened this issue 2 years ago • 2 comments

Category

  • [ ] Enhancement
  • [ ] Bug
  • [x] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [3.7.0]

Please specify what version(s) of SharePoint you are targeting: [web]

Question

As the title, how do I download the file of older versions.

const firstVersion: IVersion = sp.web.getFileByUrl("path/to/file").versions.getById(512); // first version
# then what?

gomain avatar Oct 10 '22 02:10 gomain

This hack works

const stream = await (<IFile>firstVersion).getStream().then(res => res.body);

Is this reliable?

gomain avatar Oct 10 '22 04:10 gomain

Yes, that should be reliable. Each version points to a "file" so we could expose all the file methods on versions. Will need to do some validation to see if that is 100% true, but I think there is room to improve what we are doing for versions.

patrick-rodgers avatar Oct 10 '22 13:10 patrick-rodgers

Hi +1 for adding the ability to get contents of older versions of files. I have a need to do that in a current project. (And I couldnt get gomains hack to work :-() Russell

russgove avatar Oct 19 '22 20:10 russgove

Added methods for getting content of versions to IVersion as well improved the typing of IVersionInfo to include returned fields.

patrick-rodgers avatar Oct 21 '22 17:10 patrick-rodgers

This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.

github-actions[bot] avatar Oct 24 '22 02:10 github-actions[bot]