Forum Discussion

Alan Trafford's avatar
Alan Trafford
Brass Contributor
Jan 05, 2017
Solved

Using PnP JS Core: How do I get a list of files from the "Pages" folder of an "Enterprise Wiki"

Hi   Using PnP JS Core, How would I go about getting a list of files from the "Pages" folder of an "Enterprise Wiki" and then getting the properties associated with each file?   Eventually I want...
  • Andrew Koltyakov's avatar
    Jan 07, 2017

    Hi Alan,

     

    First, 'Pages' is not a folder, it's a document library.

    You can query a doc lib by multiple available methods in SharePoint REST API and PnP JS Core REST wrapper, like:

     

    // Get by title
    $pnp.sp.web.lists.getByTitle('Pages').items.get().then(function(item) { console.log(item); });

    or

     

    // Get by list url is more preferable way as list renaming won't crash the logic
    $pnp.sp.web.getList(_spPageContextInfo.webServerRelativeUrl + '/Pages').items.get().then(function(item) { console.log(item); });

    or by querying the real folder objects with `GetFolderByServerRelativeUrl` method like:

     

    $pnp.sp.web
    .getFolderByServerRelativeUrl(_spPageContextInfo.webServerRelativeUrl + '/Pages') // Here comes a folder/subfolder path .files .expand('Files/ListItemAllFields') // For Metadata extraction .select('Title,Name') // Fields to retrieve .get().then(function(item) { console.log(item); });

     

    Cheers

Resources