Forum Discussion
Using PnP JS Core: How do I get a list of files from the "Pages" folder of an "Enterprise Wiki"
- 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
- Alan TraffordJan 07, 2017Brass Contributor
Deleted, thanks for the reply.
If possible, I really want to do this in JavaScript. As you say, I could create an add-in and have that do the work. I'm new to SharePoint development it looks like the JavaScript way is simpler, in that I don't have to host it externally.
Also, if this was successful, a follow on project would be to create an enhanced left hand menu. It seems that the easiest way to do this, without creating/editing templates or page layouts, is with JavaScript embedding.
I'm using the judgement, feel free to correct me, that add-ins are for users to add to pages they create. Whereas, JavaScript embedding can be used to make changes to all pages.
BTW I never used Azure, have beginners skills in JavaScript, average skills in C#. I've spent most of the last 5 years or so doing PowerShell and Transact-SQL. I have good skills on both of these.