To download a SharePoint list using TypeScript, you can make use of the SharePoint REST API. Here's an example code snippet to download a SharePoint list in TypeScript:
index.ts985 chars31 lines
In the above code, we first import the sp
object from the @pnp/sp
package. We then specify the web URL and the list name, and get the list using the getList
method of sp.web
.
We then fetch the list items using the select
and get
methods. In the select
method, we specify the fields we want to include in the response (in this case, just the FileRef
field which contains the relative file URL).
For each list item, we initiate the download by fetching the file using the fetch
method and creating a blob from the response. We then create a URL from the blob, add a link element to the DOM, simulate a click on the link to initiate the download, and then remove the link element.
Note that this code assumes that all files in the list have unique names. If this is not the case, you may need to include additional logic to ensure that file names are unique before initiating the download.
gistlibby LogSnag