471,627 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Error downloading excel file

Greetings,

I have the following code that attempts to download an excel file:

System.Web.HttpContext.Current.Response.ContentTyp e =
"application/vnd.ms-excel";

System.Web.HttpContext.Current.Response.AddHeader( "Content-Disposition",
"attachment; filename=\"x.xls\"");

System.Web.HttpContext.Current.Response.Write( "abc" );
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();

But I get the following error when I executed the last statement:

"Internet Explorer was not able to open this internet site..."

I have disabled "Content Expiration" in IIS HTTP Headers and ensured
"no-cache" is not added to the Response Header.

Has anyone seen this and knows what is causing it?

Help is much appreciated,
kr

*** Sent via Developersdex http://www.developersdex.com ***
Jan 11 '06 #1
4 2914
Try Response.End() instead of Response.Close()

--
Andrew Robinson
http://blog.binaryocean.com
"Kevin R." <ka****@riverone.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have the following code that attempts to download an excel file:

System.Web.HttpContext.Current.Response.ContentTyp e =
"application/vnd.ms-excel";

System.Web.HttpContext.Current.Response.AddHeader( "Content-Disposition",
"attachment; filename=\"x.xls\"");

System.Web.HttpContext.Current.Response.Write( "abc" );
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();

But I get the following error when I executed the last statement:

"Internet Explorer was not able to open this internet site..."

I have disabled "Content Expiration" in IIS HTTP Headers and ensured
"no-cache" is not added to the Response Header.

Has anyone seen this and knows what is causing it?

Help is much appreciated,
kr

*** Sent via Developersdex http://www.developersdex.com ***

Jan 11 '06 #2
I got the same error. I tried to download a .csv file and hit the same
problem, so this is not Excel related. It must be either something in my
IE 6.0 or a .NET configuration issue.

Any other ideas?

thx,
kr
*** Sent via Developersdex http://www.developersdex.com ***
Jan 16 '06 #3
Try Response.Clear() before you start adding things to the Response.

http://www.csvreader.com/csv_samples.html
The section marked "Download DataTable to Web Browser as CSV File".

Jan 17 '06 #4

Shriop,

Thanks for your suggestion and the reference URL. It took me one step
closer to the solution. Now, when I click the "Save" button of the "File
Download" dialog it saves the content as a .xls file with no problem.

But, if I choose to open the content by clicking on the "Open" button
and if Excel app is not already open in my desktop, it opens Excel
application with the following error:

'C:\Document and Settings\username\LocalSettings\Temporary Internet
Files\Content.IE5\KV5ZIYV1\myfilename.xls could not be found...'

If however, Excel is already open prior to clicking the "Open" button it
shows the content in Excel with no problem. Is this normal behavior? How
can I make it to launch Excel first and show the content?

your help is much appreciated.

Regards,
kr

*** Sent via Developersdex http://www.developersdex.com ***
Jan 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.