Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to download multiple file from project folder on button click. my files are place in the folder with following format:-

file_1_12_08_2020.txt
file_1_13_08_2020.txt
file_1_13_08_2020.txt
file_2_12_08_2020.txt
file_2_12_08_2020.txt

in this format i added date also in file name. now if i pass filename value as "file_1" then i want to download all file those name staring with "file_1".

What I have tried:

using (ZipFile zip = new ZipFile())
    {

                string fileName = "file_1_13_08_2020.txt";
                string filePath = Server.MapPath("~/User/JSON_Audit/" + fileName);
                zip.AddFile(filePath, "JSON Files");

        Response.Clear();
        Response.AddHeader("Content-Disposition", "attachment; filename=DownloadedFile.zip");
        Response.ContentType = "application/zip";
        zip.Save(Response.OutputStream);
        Response.End();
    }


i am trying this code to download file. but i enter full name then i able to download file. can any one suggest me the solution.
Posted
Updated 12-Aug-20 23:10pm

1 solution

You can get a list of the matching file names using Directory.GetFiles[^]
C#
string[] files = Directory.GetFiles(Server.MapPath("~User\JSON_Audit"), "file_1*");

You can then zip all of the files, and upload a single ZIP file.
 
Share this answer
 
v2
Comments
TCS54321 13-Aug-20 6:07am    
thank you. it's working fine for me.
OriginalGriff 13-Aug-20 6:32am    
You're weclcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900