Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download window opens twice...

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Hello all,
I have an ASP.NET application that allows users to download excel files. The code used is the following:
Code:
Response.Clear();
Response.ContentType = "application/ms-excel";
string s = "attachment; fileName=\"" + file + "\"";
Response.AddHeader("content-disposition", s);
Response.WriteFile(MapPath(file));
Response.Flush();
Response.Close();
The problem is that when the download window comes up, and the user chooses to Open the file, the download window appears again, and the user is forced to make his choice again. After choosing Open twice, the file opens in Excel.

Note: If the user selects Save, the download window does not reappear.

I have the exact same code running for pdf files. The only difference in the code is that the ContentType is "application/pdf" as opposed to "application/ms-excel". With the pdfs, though, I don't experience this problem.

Does anybody know why the download window opens twice?

Thanks.

JC

_________________________________
I think, therefore I am. [Rene Descartes]
 
how exact;y are you calling this page? via a link???

Known is handfull, Unknown is worldfull
 
Thanks vbkris,

The code above is in the 'Click' event of a button labeled 'Download File'. The page hosting the button is called via a link on a Crystal Report that lives on yet another form. Thus is like this:

1 - Page1 has a Crystal Report
2 - The report has a link (well, quite a few links) that, when clicked, Open Page2, and uses the QueryString to send parameters to Page2.
3 - Page2 contains a 'Download File' button that, when clicked, retrieves the name of the file from the QueryString and runs the code I posted earlier.

Thanks.

JC

_________________________________
I think, therefore I am. [Rene Descartes]
 
hm,

thats strange, that must work, try changing it to PDF again (In the same file)...

Known is handfull, Unknown is worldfull
 
Oh it works fine... It does what it's supposed to do. But you must choose 'Open' twice, and my boss finds that unacceptable.

Just for testing purposes, I changed the code so that it would download a pdf file. Thus, I changed "application/ms-excel" to "application/pdf", and I placed a pdf on the same folder as the excel, and it works like a charm. The pdf file opens on the first try with no problems. And, I'm telling you, everything is exactly the same. The path of the file, the way they're accessed, and so on... it's all the same, yet for the excel file, I have to click 'Open' twice.

I also tried it with a simple notepad file, and with that, I also have to click 'Open' twice. I'm a bit lost. Any ideas?

Thanks.

JC

_________________________________
I think, therefore I am. [Rene Descartes]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top