473,480 Members | 4,939 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

CSV File Download from an ASP.NET page issue

I'm using the following code to stream a CSV file download to the client
browser -

HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader( "content-disposition","attachment;
filename=" + filename );
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();

(where <filename> is equal to the filename, eg test.csv; and <bytes> is
equal to a bytearray of the actual CSV data)

Everything is fine and dandy except for one tiny glitch - The "File
Download" dialog box (the one that asks Save, Open, Cancel, More Info)
appears twice in succession when you click on Open. If you click on Save,
the CSV file is saved ok to the clients machine then the user is prompted to
Open the file. If you simply click on Open, the same dialog box immidiately
reappers and you have to click on Open again to display the file in Excel.
Nov 19 '05 #1
1 1693
I've just been trying to solve the same problem when downloading text files
to the client. However, after a couple of hours scouring the net, the
following URL discusses the same problem which appears to be a bug in certain
IE browsers.

Apparently 'longhorn' fixes this.

The article discusses the fact that this works if the method used is GET as
opposed to POST. I have still not found any documentation from Microsoft
detailing this problem - can anyone else enlighten us?

http://www.dotnet247.com/247referenc...48/243943.aspx

Thanks, Claire-Louise

"Bernard Matthews" wrote:
I'm using the following code to stream a CSV file download to the client
browser -

HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader( "content-disposition","attachment;
filename=" + filename );
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();

(where <filename> is equal to the filename, eg test.csv; and <bytes> is
equal to a bytearray of the actual CSV data)

Everything is fine and dandy except for one tiny glitch - The "File
Download" dialog box (the one that asks Save, Open, Cancel, More Info)
appears twice in succession when you click on Open. If you click on Save,
the CSV file is saved ok to the clients machine then the user is prompted to
Open the file. If you simply click on Open, the same dialog box immidiately
reappers and you have to click on Open again to display the file in Excel.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2909
by: RickL | last post by:
I have an ASP application that uploads a specified file to the server. To retrieve the file, I simply assign the filepath and file to a hyperlink on the page. When you click "Save Target As" for...
7
3683
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
1
1335
by: Rukmal Fernando | last post by:
Hi all, I have a file retrieved from a database and I want to return it over a web page. I currently have an ASPX page (Download.aspx) with code similar to the following in Page_Load(): ...
6
3047
by: Divya | last post by:
Hi, I have a web page which generates a CSV file based on some user input. When this file is downloaded by the user, the file is being automatically converted to .xls. Any idea how I can prevent...
5
12266
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
0
7040
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
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
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...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
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
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
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
561
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.