1

I need to get the folder name within a document library, within the ListCommand spfx extension. Is there a way to do that with REST ? can I use @pnp/sp ?

I have imported the project with :

import { sp } from "@pnp/sp";
0

You can use below PnPjs code to get all folders from a library and print name and url:

import { sp } from "@pnp/sp";

sp.web.lists.getByTitle("Documents").items.filter('FSObjType eq 1').select('FileLeafRef', 'FileRef').get()
.then(folders => {
    folders.forEach(f => {
        console.log('Folder name: ' + f.FileLeafRef);
        console.log('Folder url: ' + f.FileRef);

    })
}) 

FSObjType (display name Item Type) is a built-in field, values are based on this enumeration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.