473,748 Members | 5,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Double "Open/Save/Cancel/More Info" dialog when downloading text file from ASP.NET

How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.Write File" method to download a file to IE

I've asked about this before and didn't get a satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again.

The app I've written has three ASPX pages. One is a combined page which writes a little text file to the "LocalApplicati onData" directory in the "Page_Load" method and then when you click a "Download" button, it uses the inherited Response object to write the file. The other two pages work together. The first page of that pair writes the text file and contains two "Download" buttons. One button is part of a form which uses old HTML technology to Post to the second page which does the download and the other button does a "Response.Redir ect" to go to the other page to do the download. The other page has no HTML--just code in its Page_Load method to figure out the name of the file it is supposed to download and then it calls a "Download" method to use the Response object to write the file

Essentially, the pages try three methods for doing the download. Only one works properly (the last one mentioned, above--using the Response.Redire ct from one page to get to the other.) The other methods give the double-open dialog

I've submitted a zip file to the "GotDotNet" website and got the message that it will take 72 hours for me to find out if they've accepted it. I can also email it or post it somewhere else (suggestions?)

Oh yeah. One more thing. I thought of doing it these different ways when I noticed that some earlier VB code I'd written had worked the way I wanted. It turns out it was using the last method. So i did an experiment. I wrote the code in C# using the three methods and then did it again in VB. I get the same results with both languages (as I would have expected.

Any ideas on getting the other methods to work properly

The "download" part of the code looks like the following (in C#)

protected void Download(

string sNameOnly

sNameOnly = sFullPath.Subst ring(sFullPath. LastIndexOf('\\ ') + 1)

System.IO.FileI nfo fi = new System.IO.FileI nfo(sFullPath)
String sFileLength = fi.Length.ToStr ing()
Response.ClearH eaders()
Response.Clear( )
Response.Conten tType = "text/plain"
Response.Charse t = ""
Response.AddHea der("Content-Disposition", "attachment;fil ename=" + sFileName)
Response.AddHea der("Content-Length", sFileLength)
Response.WriteF ile(sFullPath)
Response.Flush( )
Response.Close( )
}
Nov 18 '05 #1
7 3705
Hi,

From your description, the problem you met (the file download dialog popup
twice sometimes when using REsponse.WriteF ile to write a certain file to
the Response Stream so as to let the user download) seems to be a known
issue of IE. And the following KB has mentioned this for IE 4.X,5.X

#PRB: Three GET Requests Are Sent When You Retrieve Plug-in Served Content
http://support.microsoft.com/?id=293792

In IE6, the problem also remains , the browser will send the get request
twice when retrieving a certain plug-in served Content.

And from my test , when we use Response.WriteF ile to write a certain
filestream into the response and let the client download the file. The
popup dialog appears twice when we do the "download" in the postback
request , if we do in the first time the page is loaded(in Page_Load), it
will only popup the dialog once. For example:

I test using a excel file, when I try the following code, the dialog popup
twice:
private void Page_Load(objec t sender, System.EventArg s e)
{
if(IsPostBack)
{
Response.ClearH eaders();
Response.ClearC ontent();
Response.Clear( );
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("Content-Disposition", "attachment;fil ename=demo.xls" );
Response.WriteF ile(Server.MapP ath("./demo.xls"));
//Response.End();
Response.Flush( );
}
}

If change to this(the page first time loaded), the dialog only popup once:
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
Response.ClearH eaders();
Response.ClearC ontent();
Response.Clear( );
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("Content-Disposition", "attachment;fil ename=demo.xls" );
Response.WriteF ile(Server.MapP ath("./demo.xls"));
//Response.End();
Response.Flush( );
}
}

So I think this also confirm your finding that your third method which use
Response.Redire ct to forward to another page which perform the "download"
in Page_Load will work, and other means ( in button's click event or other
post back event) will not work properly. Currently I also haven't found any
other means to avoid the behavior. Do you think its ok that we use the
workaround that in button' click use Response.Redire ct to forward to
another page which is used to perform the download operation in its
Page_load event?
Any way, please feel free to let me know if you have any other concerns and
thanks for posting here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Nov 18 '05 #2
Nope, that didn't work. (Didn't change anything.

After looking at your post and following the link to the KB article, I tried checking the Request.Content type. That didn't work because the ContentType that came through wasn't "contype" as stated in the KB article, but rather "applicatio n/x-www-form-urlencoded" and also, the "Page_Load" function only ran once so adding in the "Postback" condition as you suggest made no difference. I checked my server log and realized that the request that was working properly was a "GET" and the one that wasn't was a "POST". (Contrary to what the KB article APPEARED to be saying, there was only ONE request for the page. So, I changed the form that wasn't working to a "GET" form rather than a "POST" form. THAT WORKED!!

So, it appears that, at least in IE 6.0, this works for a "GET" but not a "POST". That would explain why a button on a page that posts back to the same page also does not work

So, the question is: Can this work for "POST" as well as "GET"???

Thus, my "ConfigDwnld.as px" page generates the following (only relevant part is shown)

<!-- This WORKS!!! --><form id="Form1" action="Downloa d.aspx" method="get"><i nput type=hidden name="Filename" value="E:\temp\ Test.txt"><inpu t type="submit" value="Download " name="OldDownlo ad"></form><!-- This does NOT WORK!!! Note: only difference is method="post"!! ! --><form id="Form2" action="Downloa d.aspx" method="post">< input type=hidden name="Filename" value="E:\temp\ Test.txt"><inpu t type="submit" value="Download " name="OldDownlo ad"></form

The "Download.aspx. cs" file contains the following (I'm using a text file with a .txt extension for simplicity in my testing.)

private void Page_Load(objec t sender, System.EventArg s e

if ( "contype" == Request.Content Type ) // Not necessary!!
{ // This whole block is not necessary!
Response.ClearH eaders()
Response.Clear( )
Response.Conten tType = "text/plain"
Response.Flush( )
Response.Close( )
}
else

if ( !IsPostBack ) // This condition is not necessary!
{ // The contents of this block are all that is necessary in this function
string sFullPath = Request.Params. Get("Filename")
string sNameOnly = sFullPath.Subst ring(sFullPath. LastIndexOf('\\ ') + 1)

System.IO.FileI nfo fi = new System.IO.FileI nfo(sFullPath)
String sFileLength = fi.Length.ToStr ing()
Response.ClearH eaders()
Response.Clear( )
Response.Conten tType = "text/plain"
Response.Charse t = ""
Response.AddHea der("Content-Disposition", "attachment;fil ename=" + sNameOnly)
Response.AddHea der("Content-Length", sFileLength)
Response.WriteF ile(sFullPath)
Response.Flush( )
Response.Close( )

----- Steven Cheng[MSFT] wrote: ----

Hi

From your description, the problem you met (the file download dialog popup
twice sometimes when using REsponse.WriteF ile to write a certain file to
the Response Stream so as to let the user download) seems to be a known
issue of IE. And the following KB has mentioned this for IE 4.X,5.

#PRB: Three GET Requests Are Sent When You Retrieve Plug-in Served Conten
http://support.microsoft.com/?id=29379

In IE6, the problem also remains , the browser will send the get request
twice when retrieving a certain plug-in served Content

And from my test , when we use Response.WriteF ile to write a certain
filestream into the response and let the client download the file. The
popup dialog appears twice when we do the "download" in the postback
request , if we do in the first time the page is loaded(in Page_Load), it
will only popup the dialog once. For example

I test using a excel file, when I try the following code, the dialog popup
twice
private void Page_Load(objec t sender, System.EventArg s e

if(IsPostBack

Response.ClearH eaders()
Response.ClearC ontent()
Response.Clear( );
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("Content-Disposition", "attachment;fil ename=demo.xls" );
Response.WriteF ile(Server.MapP ath("./demo.xls"));
//Response.End();
Response.Flush( );
}
}

If change to this(the page first time loaded), the dialog only popup once:
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
Response.ClearH eaders();
Response.ClearC ontent();
Response.Clear( );
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("Content-Disposition", "attachment;fil ename=demo.xls" );
Response.WriteF ile(Server.MapP ath("./demo.xls"));
//Response.End();
Response.Flush( );
}
}

So I think this also confirm your finding that your third method which use
Response.Redire ct to forward to another page which perform the "download"
in Page_Load will work, and other means ( in button's click event or other
post back event) will not work properly. Currently I also haven't found any
other means to avoid the behavior. Do you think its ok that we use the
workaround that in button' click use Response.Redire ct to forward to
another page which is used to perform the download operation in its
Page_load event?
Any way, please feel free to let me know if you have any other concerns and
thanks for posting here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Nov 18 '05 #3
See the previous post for updates. You can go to GotDotNet to download a zip file that contains the original code I was working with and update from there. My previous post talked about changing from a "POST" request to a "GET" request to make things work. I still want to know how to make this work with "POST" requests

The zip file can be downloaded from

http://www.gotdotnet.com/Community/U...cb-a894da1ad38

You can also search the "User Samples" of www.gotdotnet.com for "Download ASPX Response" and (at least when I did it, the only one I got was my submission.) The full name of the submissions is

Download file from ASPX to the default app using Response object

Note: I expect HIGH ratings from everyone who downloads it!! :-

You can see the deal with "GET" and "POST" on the "ConfigDwnld.as px" page (which you get to from the "Multi Form" button of the main page). There is a button on that page which is marked as displaying the double-open-dialog. You can make it work properly by changing the HTML code for that button so that the method is "GET" (instead of "POST"). The change is from

<form id="Form1" action="DoDownl oad.aspx" method="post"

changed to

<form id="Form1" action="DoDownl oad.aspx" method="get"

I figured this out after I submitted the code. Once I find out how to make it work for POST requests, I'll probably update the submission (if the site will allow me).
Nov 18 '05 #4
Hi ,

Regarding on the issue, I am consulting some further experts and
finding proper resource to assist you and we will update as soon as
posible. Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)

Nov 18 '05 #5
Thanks Steven!

Lowel

----- Steven Cheng[MSFT] wrote: ----

Hi

Regarding on the issue, I am consulting some further experts and
finding proper resource to assist you and we will update as soon as
posible. Thanks for your understanding

Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.
Nov 18 '05 #6
Hi Lowell,

After further consulting, Unfortunately, I've been confirmed that this is
a known issue of IE and won't be fixed currently. It will be fixed in the
longhorn version and is reported as the following bug.

=============== =============== ==============
IE OE Sustained Eng. 26790 - Prompt User with Two Open or Save Dialog Boxes
when submit with POST.
=============== =============== ==============

Since currently we haven't anymore things on this issue, I'm sorry for the
inconvenience it brings you. Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7
Steven

Thanks for checking. I guess I'll just have to make sure I use GET requests for this purpose until I know my users are all upgraded to Longhorn

Lowel

----- Steven Cheng[MSFT] wrote: ----

Hi Lowell

After further consulting, Unfortunately, I've been confirmed that this is
a known issue of IE and won't be fixed currently. It will be fixed in the
longhorn version and is reported as the following bug

=============== =============== =============
IE OE Sustained Eng. 26790 - Prompt User with Two Open or Save Dialog Boxes
when submit with POST.
=============== =============== =============

Since currently we haven't anymore things on this issue, I'm sorry for the
inconvenience it brings you. Thanks for your understanding

Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Get Preview at ASP.NET whidbe
http://msdn.microsoft.com/asp.net/whidbey/default.asp


Nov 18 '05 #8

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

Similar topics

1
2249
by: Morten Overgaard | last post by:
Hi all Is it possible for a .Net app. to intercept the "open" action on files in a given directory. I want to intercept the "open" action and the perhaps direct the client ( the app. which is trying to open the file ) to another file - or stream another file back to the client in someway??? Any help is appreciated Regards Morten
5
8486
by: Quinn | last post by:
When users clicked a unkown mime type link such as Zip on my website, a "Save/Open/Cancel" dialog box pops up. Is there a way to detect which button users clicked by using ASP? actually I only what to record the "valid" click -- when Open/Save was clicked. Thanks ahead. Quinn
1
1359
by: Keith | last post by:
I have a minor problem with a piece of code I have written to download a CSV file in an ASP.NET application. It works fine except that if the user presses the Open button on the IE6 download dialogue, then the dialogue is presented a second time. Pressing the Open button again works fine. Pressing the save button also works fine. The code (c#) looks like: if (Page.IsPostBack) { Response.Clear();
3
1616
by: Rico | last post by:
Hello, Is there any kind of Browse dialog available? I currently use an Open File dialog which is great for selecting files, but sucks (it's confusing) when you're trying to set a directory (since you have to select a file for a value to register). Is there any alternative? Thanks!
2
4419
by: OutdoorGuy | last post by:
Greetings, I have a "newbie" question in relation to opening files from C#. I have a Windows form where I allow the user to type in a file extension in a text box (e.g., "xls"). I then take that extension and use that as my filter criteria for the File Open dialog. Once the user selects a file with that extension (from the File Open dialog), I simply want to open that file (whether it is an .xls file, .txt file, etc.). I am...
4
7879
by: Wayne | last post by:
How do I get rid of the generic Windows "Open File - Security Warning" that appears when I try to open a database that resides on another PC on my home network? This is not the annoying macro security warning - I have my macro security set to low. The warning I am describing only appears when a database on another machine is opened.
0
2670
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which should decompress, open and then delete nearly 400 files. To do so I use "open FILEPT, "zcat $filename|"". In the beginning the script works fine, but after about 300 files processed I get an error on Open function: “proc: Could not open file...
3
2577
by: anudu | last post by:
hi, I am developing a system with asp.net, c#, and ajax. I have an excel file in server in "Server.MapPath("ExcelFiles/Test.xls")". I want to make it available to save to the disk in client side. I hope save file dialoge box will allow to do this. How can i do this? thanks
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9324
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
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 we have to send another system
3
2215
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.