SharePoint/PnP-JS-Core

Get File Name of a file in document library

Closed this issue · 2 comments

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the Developer Guide to see if your question is already addressed there. This will help us ensure our documentation covers the most frequent questions.

Category

[ ] Enhancement

[ ] Bug

[X] Question

Hi all,

I try to get the filename of a document in a document library.

I use :
return pnp.sp.web.lists.getById(idList).items.getById(idListItem).get().then((item:any) => {
return item;
}

But item not contains any filename information.

Could you help me please :)

Thanks a lot !!

Best regard

Hi @mame13fr,

You can try expanding File properties like this:

pnp.sp.web.lists.getByTitle(_spPageContextInfo.listTitle)
	.items.getById(6).select('File').expand('File')
	.get().then(console.log) 

which should contain the info you probably need:

image

Or document Name in particular:

item.select('File/Name').expand('File').get().then(console.log) 

Going to close this as answered, please reopen should you need to continue the conversation. Thanks!