Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2005, 07:40 AM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default save a file on client machine

Hi

   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...

 
Old March 30th, 2005, 05:52 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

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>


Code:
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.Open
    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
    Response.Flush

    oStrm.Close
    Set oStrm = Nothing

Rs: Exit Sub

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

End Sub




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save files on client machine. Udi ASP.NET 1.0 and 1.1 Professional 3 January 22nd, 2007 11:26 AM
Saving DataSet data on client machine in .csv file balesh ASP.NET 1.0 and 1.1 Professional 0 October 25th, 2006 06:17 AM
Saving file on client machine balesh ASP.NET 1.0 and 1.1 Professional 1 September 18th, 2006 07:49 AM
Can't able to Open Word File in Client Machine senthilavs Classic ASP Basics 1 June 10th, 2006 01:02 PM
wirting file to web client machine from webserver paranthaman .NET Framework 2.0 0 February 25th, 2006 01:44 AM





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