Solved

ASP + Launch download

Posted on 2000-05-10
7
250 Views
Last Modified: 2008-03-17
Hi,

I'm trying to create a link like "page.asp?fileid=1", wich will launch a download.

In my asp page, i try to send a buffer which will conatins the file, here i send 'abcdef':
Response.buffer = TRUE
Response.ContentType = "text/plain"

Response.AddHeader "Content-Disposition","attachment; filename=Caca.txt"

Response.AddHeader "Content-Length", 10
Response.BinaryWrite "abcdef"
 
Response.Flush ' Maybe not necessary...

And after that, the browser block and is waiting.

I've tried some things like :
Response.ContentType = "text/HTML"
Response.Write("TEST")  
Response.End  
Response.Redirect("Done.htm")
but anything runs.

Could anybody help me ?

Thanks,
    Serge Olwi
0
Comment
Question by:olwi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 8

Expert Comment

by:xabi
ID: 2796324
This works for me:

<%
sText = "ksjdklfjksdjf"
Response.Buffer = TRUE
Response.ContentType = "text/HTML"
Response.BinaryWrite(sText)
Response.End
%>


xabi
0
 

Author Comment

by:olwi
ID: 2796385
I don't want the text appear in the browser, what I want to send is a zip file. So the buffer was just to simplify the code. I've tried Response.End before ( see message ) and it doesn't work, the browser is waiting.
The problem is that i want to send the file ( it works ) and after write something in the page ( doesn't work...)

But thanks to try...

    Serge
0
 

Expert Comment

by:Putnic
ID: 2796455
The only way I know of doing this is to redirect the browser to the done.htm page, and in that page have a javascript that starts downloading the file.
There is no way of changing the response once you have initialized it to something. You cannot tell the browser to "change its mind".
For example:

<BODY>
Your file is now downloading. Please wait until it is finished then follow the instructions below:
bla
bla
bla
<SCRIPT>
window.open('page.asp?fileid=1', 'download');
</SCRIPT>
</BODY>

Although this was not really what you wanted I think it solves your problem.

/patrik
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:olwi
ID: 2796518
I've think at that but there's still a problem :

I can't do anything after have sent the file, so i can't close the window that have launch the browser.. The mother window can't know when the child have sent all the file.
0
 

Expert Comment

by:Putnic
ID: 2796624
It is not a problem, try it and you'll see that window.open does not open a new window if it is set to a file without the .asp or .htm etc. ending, it just opens the save-dialog box, and that closes itself when done....

/Patrik
0
 

Author Comment

by:olwi
ID: 2799252
Sorry but it still doesn't work !
If you want the code, ask for it but the call to window.open opens a new browser window and then a save-dialog box. The save-dialog box closes itself but not the browser window.


Thanks again,

   Serge
0
 
LVL 3

Accepted Solution

by:
schworak earned 100 total points
ID: 2838946
The problem you are experiencing is the MIME type. You need it to be something that will download not be processed on the fly.

The example below expects it's name to be getfile.asp and that the files are all in the same directory as getfile.asp. You can change that with little effort.

Here is the code I use when I want to do such a thing. The MIME TYPE will not effect the file itself. It will only instruct the browser how to treat the file as it comes in...



<%
  if instr(request.servervariables("HTTP_USER_AGENT"),"MSIE")>0 then
    Response.ContentType = "application/x-download"
  else
    Response.ContentType = "application/octet-stream"
  end if
  response.addheader "Content-disposition", "inline; filename=" & request.querystring(("File"))    
  grabfile = server.mappath(".") & "\" & request.querystring(("File"))
  Set oFM = CreateObject("SoftArtisans.FileManager")
  Set oBS = oFM.OpenBinaryFile( grabfile )
  Response.BinaryWrite( oBS.ReadAll )
%>


A more elaberate version is available at http://home.g-world.com/local/testing/getfile.asp
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question