0

I want to download my file with a specific name from SharePoint library using SPFX react.

<div key={index}><a download="" >{item.name}</a></div> (I am using anchor tag for downloading file)

I used the above code but this doesn't help me. Someone please help me in this.

1 Answer 1

1

You can set following URL in src attribute of anchor tag as https://<yourdomain>.sharepoint.com/sites/<yoursite>/_layouts/download.aspx?SourceUrl=<document-URL>

<a  src="https://<yourdomain>.sharepoint.com/sites/<yoursite>/_layouts/download.aspx?SourceUrl=<document-URL>" >{item.name}</a>
2
  • this code is working for downloading a file but I also want to give a static name to this file. Could you please help me how can I change the name of the file ?
    – Renuka
    Commented Apr 7, 2023 at 11:30
  • Do you mean that downloaded file must have same name doesn't matter what is the name of that file in document library? Commented Apr 7, 2023 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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