Solved

ASP + Launch download

Posted on 2000-05-10
7
248 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to hide hide popup page refresh second time? 10 125
ASP Focus problem 3 62
Select only the top record in a left join 13 37
Button to go back 3 25
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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