ASP function similar to Response.WriteFile() in .N

Results 1 to 2 of 2

Thread: ASP function similar to Response.WriteFile() in .N

  1. #1
    Join Date
    Dec 1969

    Default ASP function similar to Response.WriteFile() in .N

    I am trying to prompt the user for a download when they click on a link instead of simply going to it. How can I read a file, no matter if it&#039;s binary or text and then stream it appropriately to the user? Here&#039;s what I have:<BR><BR>&#060;%<BR>Option Explicit<BR>Dim strPath<BR>strPath = Request.QueryString("file")<BR>If strPath &#060;&#062; "" Then<BR>&nbsp;&nbsp;Call DownloadFile(strPath)<BR>Else<BR>&nbsp;&nbsp;Respo nse.Write("no file specified.")<BR>End If<BR><BR>Private Sub DownloadFile(file)<BR>&nbsp;&nbsp;Dim strAbsFile<BR>&nbsp;&nbsp;Dim objFSO<BR>&nbsp;&nbsp;Dim objFile<BR>&nbsp;&nbsp;strAbsFile = Server.MapPath(file)<BR>&nbsp;&nbsp;Set objFSO = Server.CreateoBject("Scripting.FileSystemObject")< BR>&nbsp;&nbsp;&nbsp;&nbsp;If objFSO.FileExists(strAbsFile) Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set objFile = objFSO.GetFile(strAbsFile)<BR>&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;Response.Clear<BR>&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Respon se.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;Response.AddHeader "Content-Length", objFile.Size<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;Response.ContentType = "application/octet-stream"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&#039;**** Code to stream contents ****<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set objFile = Nothing<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;Set objFSO = Nothing<BR>End Sub<BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: ASP function similar to Response.WriteFile() i

    open it with ADODB.Stream instead.<BR><BR><BR><BR><BR>j

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts