Solved

ASP + Launch download

Posted on 2000-05-10
7
242 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
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cleaning xml string 2 47
Visual Project Bridge error 5 56
Help with stored procedure 30 53
Update table value with join syntax 2 46
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now