Hi, this will be a bit tricky to explain but I'll try my best. Original page: I have a page with a button, which when clicked will generate a spreadsheet and prompt the user to download this spreadsheet. Changes: Now since we didn't want to the page to refresh, and at the same time we didn't want to implement an UpdatePanel to this page, we changed this button to a link which pops-up a new page. New page: The new page simply contains this button and a javascript link to close the window. I did not change the source code of the generate-spreadsheet method. Generate spreadsheet method:
public static void Export(Page webPage)
{
webPage.Response.Clear();
webPage.Response.Buffer = true;
webPage.Response.Charset = "";
webPage.EnableViewState = false;
string filename = "spreadsheet.xls";
webPage.Response.ContentType = "application/vnd.ms-excel";
webPage.Response.ContentEncoding = Encoding.Default;
webPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ";");
string filePath = string.Format("{0}temp\\\\{1}", webPage.Request.PhysicalApplicationPath, fileName);
populate(filePath);
webPage.Response.TransmitFile(filePath);
webPage.Response.Flush();
File.Delete(filePath);
webPage.Response.End();
}
Problem: Now here's my problem, the code works perfectly on my local machine, but does not work when I deployed on the server. On my local, it correctly gives me a download dialog with "spreadsheet.xls" displayed. On the server, it gives me a download dialog, but the URL (http://www.oursite.com/WebForms/WFrmExport.aspx) of the pop-up page is displayed instead. So when I click "Save", it will just give me an error. Additional notes: 1. The same export method is used in the original page and the new pop-up page 2. Both original pages and pop-up pages are webforms (*.aspx) 3. The original page works on the server... meaning it correctly prompts me to download "spreadsheet.xls". The problem only occurs on the pop-up page and only on the server. 4. If I remove the File.Delete(filePath);
statement, I will see the generated spreadsheet.xls in the correct filepath
server directory, which is the same directory used by the original page. What could be the problem?
Rafferty
modified on Friday, February 26, 2010 12:40 AM