In my application, I create a zip file for the user to download information about the exported database. A zip file is created when the user clicks the "generate data" button, and I register the request in the database.
On my page, I have a Gridview that shows the Userβs download history, and also offers them the ability to download the last generated file for a certain period of time.
The problem I am facing is when they click the button, I want the page to refresh (thus updating the gridview and showing their last request), and then start downloading the files (IE, call a prompt and let them decide to open / save / cancel it).
I can start the download in the message, but my Gridview is not updated before it starts, so it does not display the newest request in the list. How can I get the gridview to update before the download request starts?
To start the download, use the following:
public void BeginDownload() { FileDownload download = InventoryService.GetLastThreeFileDownloads(this.EmployeeId).First(); FileInfo fi = new FileInfo(Server.MapPath(SERVER_DOWNLOAD_PATH) + download.DownloadFileName); Response.Clear(); Response.ContentType = "application/zip"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + fi.Name); Response.TransmitFile(fi.FullName); Response.Flush(); }
The method is called in the Page_Load event as the last element if the hidden field is set to true (which I set when they click the button to create the file).
I also tried doing this through jQuery / AJAX calls to either refresh the page or start the download with little success. I thought about opening a modal dialog and letting them click the link to start the download, and then refresh the page when the modal closes, but in a pinch if I cannot find another solution.
Any help is much appreciated!
Delebrin
source share