?
Solved

ASP + Launch download

Posted on 2000-05-10
7
Medium Priority
?
258 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
Industry Leaders: 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

839 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