p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   save a file on client machine (http://p2p.wrox.com/showthread.php?t=27181)

sumsin March 22nd, 2005 07:40 AM

save a file on client machine

   I want to save an XML file on client machine with the facility of browsing the save dialog box. All this happen on the click of a button.

     plz guide me...

BrianWren March 30th, 2005 05:52 PM

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

All times are GMT -4. The time now is 10:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.