473,839 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Download file and a "dead window"

In an aspx page there is the possibility to download a file. I don't
want to give the user a direct link, so I wrote the following code:

.....
try
{
byte[] buff = System.IO.File. ReadAllBytes(pa th);
int filesize = buff.Length;

Response.ClearH eaders();
Response.AddHea der("Content-type", ContentType);
Response.AddHea der("Content-Disposition", "attachment ;
filename=\"" + filename + "\"");
Response.Output Stream.Write(bu ff, 0, filesize);
Response.Output Stream.Flush();
}
catch
{ .....

I have a problem:
- If I put this code in my page, when the postback is executed the
download starts, but the page "dies" (the postback doesn't render
again my page)
- If I put this code in a new page, loaded in a popup, the download
starts but the popup "dies" (I can't write anything in it and I don't
know how I can close it automatically)

Can someone help me? Thank you in advance!
Sep 19 '08 #1
3 1150
ni*********@gma il.com formulated the question :
In an aspx page there is the possibility to download a file. I don't
want to give the user a direct link, so I wrote the following code:

.....
try
{
byte[] buff = System.IO.File. ReadAllBytes(pa th);
int filesize = buff.Length;

Response.ClearH eaders();
Response.AddHea der("Content-type", ContentType);
Response.AddHea der("Content-Disposition", "attachment ;
filename=\"" + filename + "\"");
Response.Output Stream.Write(bu ff, 0, filesize);
Response.Output Stream.Flush();
}
catch
{ .....

I have a problem:
- If I put this code in my page, when the postback is executed the
download starts, but the page "dies" (the postback doesn't render
again my page)
- If I put this code in a new page, loaded in a popup, the download
starts but the popup "dies" (I can't write anything in it and I don't
know how I can close it automatically)

Can someone help me? Thank you in advance!
You might need a Response.Clear( ).
I always end these kind of codeblocks with a Response.End() and have no
problem with "dead" pages.

Note: there is also a Response.WriteF ile(path) which doesn't need to
buffer the entire file.

Hans Kesting
Sep 19 '08 #2
Thank you for your answer, unfortunately my page keeps not working...
but I found a trick to kill the "dead window" with javascript. Thank
you again!
Sep 19 '08 #3
You may want to double check this to solve the problem rather than to cure
its consequences.

AFAIK this is when you actually send something (generally I'm using a link
to a download page). Knowing how it is triggered could help so that we can
try to repro this behavior (if opening a window using js rather than a
link)...

--
Patrice

<ni*********@gm ail.coma écrit dans le message de groupe de discussion :
34************* *************** **...legroups .com...
Thank you for your answer, unfortunately my page keeps not working...
but I found a trick to kill the "dead window" with javascript. Thank
you again!

Sep 19 '08 #4

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

Similar topics

4
4908
by: Paul Schmidinger | last post by:
Hello, I have a windows-IIS-Webserver running PHP 4.3.0. However, there is no GD-Lib, so I tried to install it. What I did is this: - copy the file php_gd2.dll (which I have from another win-webserver with working GD-Lib) to C:\PHP\extensions - set the extensions-folder in php.ini to C:\PHP\extensions - remove the ";" before the php_gd2.dll-inclusion in the php.ini-file
1
2493
by: omission9 | last post by:
An application I have written is, suddenly it seems, throwing the following error after being left in use for several hours. This does not seem to occur with lighter usage. I am not 100% sure what causes this? Anyone have any advice? Seen it before? Traceback (most recent call last): File "PythonCardPrototype\binding.pyo", line 304, in _dispatch File "wxPython\events.pyo", line 23, in GetEventType wxPython.wxc.wxPyAssertionError: C++...
5
1575
by: Brandon Potter | last post by:
Forgive me if this has already been covered... I use dual displays and have 2 - 3 Visual Studio .NET 2003's open at the same time, however, without fail, at some point during my session, the title bar and border of one of the VS.NET's copies 1/2 of its height and 1/2 of its width, so I end up with this floating titlebar and border taking up the lower left corner of my 2nd monitor with an invalidated paint area. Is there a fix?
3
1611
by: Donovan Martin | last post by:
Detecting dead headers is an extremely tiresome and lengthy process. Is there an automated utility available which might do this for me? That is, some utility that will check my .cpp and .h files and determine which headers that are referenced are unnecessary?
24
3885
by: AES/newspost | last post by:
On many web sites or pages (including my own home page) clicking on certain links will start downloading a PDF file, sometimes without the author having provided any warning in the text of the page that this is going to happen (although in some -- all? -- browsers the "next link" line at the bottom of the browser window may show that the next line is a ".pdf" file). I was recently on a page in which clicking on a link brought up a small...
11
2248
by: gg9h0st | last post by:
i saw a code refactorying onload event listener window.onloadListeners=new Array(); window.addOnLoadListener=function(listener) { window.onloadListeners=listener; } why declare the onloadListeners, addOnLoadListener below window?
0
975
by: jgnprt | last post by:
I am converting a doc file to pdf file programmatically using Vb 6.0 but as the program runs it is showing the Save as window .........Can anybody help me in suppresiing this window. I want to save the pdf file with a predefined path and a predefined name through code itself.
2
1845
by: nedu | last post by:
Hi, Since I need to insert a a excel file in the HTML, I used <iframe> tag. But this tag PROMPT me the "File Download" dialog box every time the page got refreshed. Is there any ASP code to block that "File Download" box Regards, Nedu. M
24
8245
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and seems to have a (tiny) amount overhead since window itself points to the global object, hence, a circular reference. (From everything I am reading, window is just a REFERENCE back to the global object, as opposed to a separate object.)
0
9697
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,...
0
10908
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10293
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
7017
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
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4484
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
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3134
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.