p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_howto thread: Download .txt files


Message #1 by "Benny Olsson" <The_Fog@E...> on Mon, 12 Mar 2001 08:05:51
there are two ways, which were covered about a month ago in this mailing list

The first is the simplest, and probably works better than the second anyways.  I'll give 'em both to
you here.  The first code should work for any type of file (ie .gif, .jpg, .html) except ASP or
exectutable scripts.  Use the second if sending an executable script.


----- 1st solution: set response header as "unknown" and redirect client to page/file
---------------

<%
FileToSend="images/icon.jpg"
' or FileToSend="../UploadDirectory/thisfile.txt"

Response.ContentType = "application/unknown"
Response.AddHeader "Content-Disposition", "filename=WhatEverYouWant.jpg"
server.execute (FileToSend)

' could also use response.redirect, or server.execute.
' Test 'em and use whichever is best for you.
%>


----- 2nd solution: set response header as "unknown", read file using FSO, buffer text stream of
file, send to client when whole file is in buffer.  Works only for text-files, no graphics.
---------------

<%
response.buffer=TRUE
response.ContentType="application/unknown"

Response.AddHeader "Content-Disposition", "filename=demo2.html"
' YourFileName is the filename you want the client to save the file as,
' otherwise the name of this ASP script (download.asp) will show up instead.

  Set fs = createobject("scripting.filesystemobject")
Set thisfile = fs.opentextfile(Server.Mappath("demo2.html"), 1, false)


' loop and write
  Do While Not thisfile.AtEndOfStream
   strLineMLS=thisfile.readline
   response.write strLineMLS & vbcrlf
  Loop

' close everything
  thisfile.close
  set thisfile=nothing
  set fs=nothing

' Flush everything in the buffer, thereby sending the file to the client.
  response.flush
%>



_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com




  Return to Index