Subject: Re: List down?

rudy:
we've solved all the problems
;o)

Tim:

LOL.  Leave it to rudy to point out the obvious that we've all
overlooked.  :-)  You made my day.

Okay, I'll ask a question, then.  I've been struggling with this for
about a day or so with not much success.  I've got an ASP page that
looks at a specific folder on the server and displays a list of the
files that are in it.  I want to enable the user to click on a filename
to download it, but don't want the file displayed in the browser (i.e.
if it's a file like .gif, .pdf, etc. - I want to force a download for
the file, not display it).  Clients are all IE5/6.  So I have each
filename set up as an HTML anchor (so it's clickable) but not with an
href (so it doesn't try to redirect).  When the user clicks the
filename, I put the filename in a hidden input area and post to another
ASP page to download the file.

Everything's working fine - it downloads both text and binary files,
forces the download dialog, etc.  But I end up with the download ASP
page/window that just sits there after the download is complete, and I
don't know how to close it.  I can't put any JavaScript like
"window.close()" in it or it becomes part of the file download.  Ideally
I'd like to not have to open the window at all, but the only way I can
think of doing that is that when the user clicks a filename it should
post back to itself, but I thought once you start dinking with the
response headers and contenttype that the page won't ever recover.

Here's the code I'm using in the download ASP page (more or less ripped
off one of the dev help sites):

  Dim strAbsFile, strFileExtension, objFSO, objFile, objStream
  strAbsFile = Session("Path") & "\" & Request.Form("filename")    'set
absolute file location
  Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  If objFSO.FileExists(strAbsFile) Then
    Set objFile = objFSO.GetFile(strAbsFile)
    Response.Clear
    Response.AddHeader "Content-Disposition", "attachment; filename=" &
objFile.Name
    Response.AddHeader "Content-Length", objFile.Size
    Response.ContentType = "application/octet-stream"
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = 1    'set to binary
    Response.CharSet = "UTF-8"
    objStream.LoadFromFile(strAbsFile)    'load the file into the stream
    Response.BinaryWrite(objStream.Read)    'send the stream in the
response
    objStream.Close
    Set objStream = Nothing
    Set objFile = Nothing
  Else    'file doesn't exist
    Response.Clear
    Response.Write("No such file exists.")
  End If
  Set objFSO = Nothing

Ideas?  Can I post back to the same page and get a download dialog, and
then have the page re-render as normal?

Tim
___________________________ 
Tim Furry
Web Developer 
Foulston Siefkin LLP 




____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
       Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
    http://wdvl.internet.com/WDVL/Forum/#sub

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to