473,503 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Internet Explorer unable to open Excel stream

2 New Member
I want to export a datagrid to Excel. Here is the code:

[after datagrid databind]


Response.Clear();


Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=FileName.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.No Cache);
System.IO.StringWriter stringWrite = new
System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
HtmlTextWriter(stringWrite);
DataGrid1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();


When I open the page with Internet Explorer I get this:


Internet Explorer cannot download [file name] from [server name]
Internet Explorer was not able to open this Internet site. The
requested site is either unavailable or cannot be found. Please try
again later.


The funny thing: it works with Firefox - no problems at all.
Mime types on IIS are ok.
Mar 11 '08 #1
2 3212
Plater
7,872 Recognized Expert Expert
It's this line:
Response.Cache.SetCacheability(HttpCacheability.No Cache);
that does it.
It took me a looong time to figure that out. (I was doing something similar with PDFs)

I ended up having to remove it, and just used a dummy querystring value (?t=235345 whatever the time value was at the time of page load say) to ensure that the page was not a cached version
Mar 11 '08 #2
cwlarsen
2 New Member
That did it.
Thanks a lot! :)
Mar 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1571
by: Paulina Morchio T. | last post by:
2
2562
by: Neil | last post by:
Hi I'm rendering my datagrid to a HTML stream with a .xls extension to open in Excel however it opens in the browser. Is there a way to programatically force it to open Excel? I know you can...
5
7572
by: jkristia | last post by:
StreamReader throws an exception if I attempt to open a .csv file which is also opened by Excel. I checked this list and found what I though was the solution, first open the file stream in read...
1
4460
by: =?Utf-8?B?aHV3NTM=?= | last post by:
I use vista and internet explorer 7 with a Hp 1210 printer. The system has worked fine, but I have now discovered that I am unable to print from the browser. The page does appear in the preview,...
0
2890
by: Christian W Larsen | last post by:
I want to export a datagrid to Excel. Here is the code: Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");...
1
3089
by: Christian W Larsen | last post by:
I want to export a datagrid to Excel. Here is the code: Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition",
4
2484
by: Kaustubh Budukh | last post by:
I am designing a VB.NET based website I have a hyperlink, upon clicking on it a "File Download" prompt opens which asks me whether I want to "Save" the file, "Open" But I want it to...
1
1347
by: =?Utf-8?B?UGF5cm9sbCBmcnVzdHJhdGVk?= | last post by:
I am on my work computer using Windows XP, I am am using Internet Explorer 7.0 also. I am on a payroll website to do my weekly payroll. I try and view my payroll before processing it so I try and...
1
7425
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/download2.php Whenever I get that page, I get the following error: --------------------- Internet Explorer cannot download download2.php from...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.