Pnpjs: How to get Author and Editor fields of Files in Document Libraries using PnP JS

Created on 2 Mar 2020  路  5Comments  路  Source: pnp/pnpjs

Hi,

I am working in SPFx with the version of 1.10.0. I am using the below code to get the files and folders of document libraries by passing the relative url. I am able to get the fields like Title, Name, ServerRelativeUrl, TimeCreated, TimeLastModified and so on.

I want to get the fields like Created By (Author), Modified By (Editor) and Checkoutuser. How to get it using PnP JS?

public getFilesFoldersFromList(relativeUrl: string): Observable<any> { return from( sp.web .getFolderByServerRelativeUrl(relativeUrl) .expand("Folders", "Files") .get() ).pipe( map((res: any) => { return res; }) ); }

Please help me.

non-library answered question

All 5 comments

Hi @spvjebaraj,

You can get these from files' item information:

sp.web.lists.getByTitle('Shared Documents')
  .rootFolder.files
  .select('*,listItemAllFields')
  .expand('listItemAllFields')
  .get().then(console.log);

Hi Andrew,
Thanks for your answer to get all the fields for the document library. But I want to get the details of files which is presented inside the folder. For example my relative path should be, "sites/testsite/Media/Folder1".

How to get this?

It's generic, man! :D

sp.web.getFolderByServerRelativeUrl('/sites/testsite/Media/Folder1')
  .files
  .select('*,listItemAllFields')
  .expand('listItemAllFields')
  .get().then(console.log);

Just now I also tried this. It's working. I thought to reply back to you.
But you did it.

Thanks for the solution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simkessy picture simkessy  路  3Comments

simonagren picture simonagren  路  3Comments

AJIXuMuK picture AJIXuMuK  路  3Comments

ITAndy23 picture ITAndy23  路  3Comments

ahsanranjha picture ahsanranjha  路  3Comments