View Single Post
  #2 (permalink)  
Old March 30th, 2005, 05:52 PM
BrianWren BrianWren is offline
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

You can't actually do this. (Security issue.)
But you can create a link that performs a download. It is a bit complicated, because you cannot force a browser to obey you, and it might try to just display the file instead, depending on the settings of the user's machine.

Using VB 6 and IIS, this is what I do in response to a link click
on <a href="http://MySvr/MyApp.asp?wci=Send_File>Download File</a>

Private Sub Send_File_Respond()

    On Error GoTo Er

    Dim pth    As String
    Dim strDoc As String
    Dim CntTyp As String
    Dim fSize  As String
    Dim oStrm  As ADODB.Stream

    strDoc = "StandardMaterials.txt"
    CntTyp = "text/plain"

    pth = " . . . " ' Whatever you need here
    Set oStrm = New ADODB.Stream
    fSize = GetFileSize(pth & strDoc)

    Response.Buffer = True      ' Turning on buffering & clearing ensures that
    Response.Clear              ' all of the header information will be at the
                                ' top.  Feature of IIS 4 and on.
    oStrm.Type = adTypeBinary
    oStrm.LoadFromFile pth & strDoc

    Response.AddHeader "Content-Disposition", "attachment; filename=" & strDoc
    Response.AddHeader "Content-Length", fSize
    Response.ContentType = CntTyp
    Response.Charset = "UTF-8"

    Response.BinaryWrite oStrm.Read

    Set oStrm = Nothing

Rs: Exit Sub

Er: ' Report or log the error here, if there is one... 
    Resume Rs

End Sub