Exporting data to Excel

S

simmonsj_98

I have a pop-up web page that takes a dataset and exports it to Excel. I
have included the code sample below. When I run this on my local environment
I get a file download dialog that recognizes that format is excel and will
open the file. However when I deploy it to our staging environment the
pop-up window opens and then immediately closes. I’m guessing that I need to
change a setting on the staging server, but have no idea what that may be.
Could anyone provide any insight to this problem?


Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=WebReport.xls");
Response.Charset = "";

// Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel";


DataSet dsExport = (DataSet)Session["Reportdata"];

System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dsExport;
dgGrid.DataBind();


// Get the HTML for the control.
dgGrid.RenderControl(hw);

// Write the HTML back to the browser.
Response.Write(tw.ToString());

// End the response.
Response.End();
 
J

Joel

Try adding a wait. had a problem where the program was running so fast it
didn't recognize the prevvious mouse action was released. The code just blew
past the response in a pop up window.



Application.Wait (Now + TimeValue("0:00:1"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top