SharePoint / PnP-JS-Core

Code moved to https://github.com/pnp/pnpjs. This repository is archived.
Other
379 stars 231 forks source link

Get File Name of a file in document library #778

Closed mame13fr closed 6 years ago

mame13fr commented 6 years ago

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

koltyakov commented 6 years ago

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) 
patrick-rodgers commented 6 years ago

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