Solved

ASP + Launch download

Posted on 2000-05-10
7
251 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
Technology Partners: 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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