문제

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";
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top