How can download multiple files at once in such as as zip file, below is the code : which display all documents (it may be 2 documents or more) and i want one button on that button it download all documents,
How can i do?
How can download multiple files at once in such as as zip file, below is the code : which display all documents (it may be 2 documents or more) and i want one button on that button it download all documents,
How can i do?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vishal JoshiPosted Feb 2, 2024, 11:12 AM
Hello Garima,
Try the below code to download multiple files.
Model Class
Thanks
Vishal Joshi
Tuhin PaulPosted Feb 2, 2024, 2:20 PM
To download multiple files as a single zip file in response to a button click, you can follow these general steps using a combination of server-side and client-side code. Below is a basic example using ASP.NET and C#.
Amit MohantyPosted Feb 1, 2024, 7:27 AM
Create a model to store information about each file, such as file name, path, and content type.
In your controller, create an action that prepares the files you want to include in the zip file and make sure you have the
System.IO.Compressionnamespace included in your project.In your view, create a button that triggers the download.
Jayraj ChhayaPosted Feb 1, 2024, 5:54 AM
To download multiple files as a zip in Dot net MVC, you can follow these steps:
First, make sure you have the
System.IO.CompressionandSystem.IO.Compression.FileSystemnamespaces imported in your project.Create a method that takes the file paths of the documents you want to download as parameters. This method will create a zip file and add the documents to it. Here's an example:
DownloadFilesAsZipmethod and pass the file paths of the documents you want to download. Here's an example:Make sure to replace
"ControllerName"with the actual name of your controller.That's it! When the user clicks the "Download All Documents" button, the files will be downloaded as a zip file.