0

I have a page that generates data. After the data is generated a page is created that lists all the different files that were generated. There are usually 8-12 files. Instead of having my users right-click and save each file I wanted to do it with a button where when the users clicks the button all the files would save to the default browser download location. Within gmail in chrome when I have an attachment and I click download it automatically goes to my download directory. I have to make this work across multiple browsers so if this isn't an option across browsers what would be recommended for the situation I'm in?

Here is the code I have so far:

protected void btnDownloadFile_Click(object sender, EventArgs e)
{
  Download_File("X:\\dnloads\\J2207.sas");      
  Download_File("X:\\dnloads\\J2207.txt");
  Download_File("X:\\dnloads\\J2207_codebook.pdf");
}
private void Download_File(string FilePath)
{
  Response.ContentType = ContentType;
  Response.AppendHeader("Content-Disposition", "attachment; filename=" +       Path.GetFileName(FilePath));
  Response.WriteFile(FilePath);
  Response.End();
}

The problem is once it hits Response.End(); it stops and doesn't go to the next file. Is this an incorrect approach or what can I do to have multiple files downloaded?

This is part of a C#/ASP.NET web site.

Thank you

Jerry Warra
  • 304
  • 1
  • 4
  • 20
  • You want to download all 12 files seperately or as a zipped file? – Vijay Feb 16 '17 at 13:48
  • Seperately but with only one button click. Through my site the user can choose to zip all the files up, but I don't want to do that automatically unless I have no other way of doing it. – Jerry Warra Feb 16 '17 at 13:54
  • You will have to use Window.open in a loop. If you are doing 8-12 then browser might block it as pop up blockers do not like too many window.open. – Vijay Feb 16 '17 at 14:01
  • But with window.open won't it open the file in a window? Some of the files are text files of data. I don't want the uses to see this I just want them to download the data. – Jerry Warra Feb 16 '17 at 14:47
  • http://stackoverflow.com/questions/1066452/easiest-way-to-open-a-download-window-without-navigating-away-from-the-page there are some recommendations here. – Vijay Feb 17 '17 at 04:23
  • 1
    Saw the code you posted. This will work only for one file. There is no way for browser to know there are more than one files coming. A client side approach using Javascript will be better. – Vijay Feb 17 '17 at 04:26

0 Answers0