auto download csv file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don Grover

    auto download csv file

    How can I force a download of a csv file by user clicking on hyperlink.
    Don


  • Greg Griffiths

    #2
    Re: auto download csv file

    try :

    <a href="myCSVFile .csv">click here</a>

    If it opens in the browser then the user needs to amend their settings.

    see http://www.greggriffiths.org/webdev/both/excel/ for some other
    approaches.

    Don Grover wrote:
    [color=blue]
    > How can I force a download of a csv file by user clicking on hyperlink.
    > Don[/color]

    Comment

    • Don Grover

      #3
      Re: auto download csv file

      Thanks Greg.
      Had a look but what I am after, I have a complex qry that financial users
      select data from a web page by submitting a form.
      I am calling an asp page that gets the data format as they require and I
      have it a STRING in csv format.
      The above is working correctly.

      What I want to do is automatically bring up a save as box to prompt them to
      save it, I really dont want to save as file first unless I have too.

      Anyone have any ideas.
      Don

      "Greg Griffiths" <greg2@surfaid. org> wrote in message
      news:3FC68FBF.8 816FB9B@surfaid .org...[color=blue]
      > try :
      >
      > <a href="myCSVFile .csv">click here</a>
      >
      > If it opens in the browser then the user needs to amend their settings.
      >
      > see http://www.greggriffiths.org/webdev/both/excel/ for some other
      > approaches.
      >
      > Don Grover wrote:
      >[color=green]
      > > How can I force a download of a csv file by user clicking on hyperlink.
      > > Don[/color]
      >[/color]


      Comment

      • Chris Barber

        #4
        Re: auto download csv file

        Look at ADODB.Stream


        You can load the object with the CSV and as long as the HTTP headers are set
        correctly thenthe binary output (as Response.Write) will prompt the Save AS
        dialog.

        <%
        'Set the content type to the specific type that you are sending.
        Response.Conten tType = "text/csv"

        Const adTypeText = 2

        'Create Stream object
        Dim pobjStream
        Set pobjStream = Server.CreateOb ject("ADODB.Str eam")

        'Specify stream type - we want To save text/string data.
        pobjStream.Type = adTypeText

        'Open the stream And write binary data To the object
        pobjStream.Open
        pobjStream.Writ eText [YourGeneratedCS VText]

        Response.Binary Write objStream.Read

        pobjStream.Clos e
        Set pobjStream = Nothing
        %>


        **** That might be Response.Write as opposed to BinaryWrite - not sure at
        the moment.

        Chris.

        "Don Grover" <spamfree@assof t.com.au> wrote in message
        news:%23kR87jVt DHA.2440@TK2MSF TNGP12.phx.gbl. ..
        Thanks Greg.
        Had a look but what I am after, I have a complex qry that financial users
        select data from a web page by submitting a form.
        I am calling an asp page that gets the data format as they require and I
        have it a STRING in csv format.
        The above is working correctly.

        What I want to do is automatically bring up a save as box to prompt them to
        save it, I really dont want to save as file first unless I have too.

        Anyone have any ideas.
        Don

        "Greg Griffiths" <greg2@surfaid. org> wrote in message
        news:3FC68FBF.8 816FB9B@surfaid .org...[color=blue]
        > try :
        >
        > <a href="myCSVFile .csv">click here</a>
        >
        > If it opens in the browser then the user needs to amend their settings.
        >
        > see http://www.greggriffiths.org/webdev/both/excel/ for some other
        > approaches.
        >
        > Don Grover wrote:
        >[color=green]
        > > How can I force a download of a csv file by user clicking on hyperlink.
        > > Don[/color]
        >[/color]


        Comment

        • Don Grover

          #5
          Re: auto download csv file

          Thanks Chris
          I can now get it to show a saved as box but it keeps putting in the actual
          asp page as the file saveas file name.
          How can I preload a file name.
          '************** **************
          Heres my Code

          'Set the content type to the specific type that you are sending.
          Response.Conten tType = "text/csv"

          Const adTypeBinary = 1
          Dim strFilePath

          strFilePath = "c:\cokeshopScr ipts\exportdata .csv" 'This is the path to the
          file on disk.

          Set objStream = Server.CreateOb ject("ADODB.Str eam")
          objStream.Open
          objStream.Type = adTypeBinary
          objStream.LoadF romFile strFilePath

          Response.Binary write objStream.Read

          objStream.Close
          Set objStream = Nothing

          '************** *************** *************



          "Chris Barber" <chris@blue-canoe.co.uk.NOS PAM> wrote in message
          news:%23coIWMWt DHA.1884@TK2MSF TNGP10.phx.gbl. ..[color=blue]
          > Look at ADODB.Stream
          >[/color]
          http://support.microsoft.com/default...NoWebContent=1[color=blue]
          >
          > You can load the object with the CSV and as long as the HTTP headers are[/color]
          set[color=blue]
          > correctly thenthe binary output (as Response.Write) will prompt the Save[/color]
          AS[color=blue]
          > dialog.
          >
          > <%
          > 'Set the content type to the specific type that you are sending.
          > Response.Conten tType = "text/csv"
          >
          > Const adTypeText = 2
          >
          > 'Create Stream object
          > Dim pobjStream
          > Set pobjStream = Server.CreateOb ject("ADODB.Str eam")
          >
          > 'Specify stream type - we want To save text/string data.
          > pobjStream.Type = adTypeText
          >
          > 'Open the stream And write binary data To the object
          > pobjStream.Open
          > pobjStream.Writ eText [YourGeneratedCS VText]
          >
          > Response.Binary Write objStream.Read
          >
          > pobjStream.Clos e
          > Set pobjStream = Nothing
          > %>
          >
          >
          > **** That might be Response.Write as opposed to BinaryWrite - not sure at
          > the moment.
          >
          > Chris.
          >
          > "Don Grover" <spamfree@assof t.com.au> wrote in message
          > news:%23kR87jVt DHA.2440@TK2MSF TNGP12.phx.gbl. ..
          > Thanks Greg.
          > Had a look but what I am after, I have a complex qry that financial users
          > select data from a web page by submitting a form.
          > I am calling an asp page that gets the data format as they require and I
          > have it a STRING in csv format.
          > The above is working correctly.
          >
          > What I want to do is automatically bring up a save as box to prompt them[/color]
          to[color=blue]
          > save it, I really dont want to save as file first unless I have too.
          >
          > Anyone have any ideas.
          > Don
          >
          > "Greg Griffiths" <greg2@surfaid. org> wrote in message
          > news:3FC68FBF.8 816FB9B@surfaid .org...[color=green]
          > > try :
          > >
          > > <a href="myCSVFile .csv">click here</a>
          > >
          > > If it opens in the browser then the user needs to amend their settings.
          > >
          > > see http://www.greggriffiths.org/webdev/both/excel/ for some other
          > > approaches.
          > >
          > > Don Grover wrote:
          > >[color=darkred]
          > > > How can I force a download of a csv file by user clicking on[/color][/color][/color]
          hyperlink.[color=blue][color=green][color=darkred]
          > > > Don[/color]
          > >[/color]
          >
          >[/color]


          Comment

          • Chris Barber

            #6
            Re: auto download csv file

            Response.addHea der("content-disposition",
            "attachment;fil ename=somefile. csv")

            Chris.

            "Don Grover" <spamfree@assof t.com.au> wrote in message
            news:%23zFxsCYt DHA.3436@tk2msf tngp13.phx.gbl. ..
            Thanks Chris
            I can now get it to show a saved as box but it keeps putting in the actual
            asp page as the file saveas file name.
            How can I preload a file name.
            '************** **************
            Heres my Code

            'Set the content type to the specific type that you are sending.
            Response.Conten tType = "text/csv"

            Const adTypeBinary = 1
            Dim strFilePath

            strFilePath = "c:\cokeshopScr ipts\exportdata .csv" 'This is the path to the
            file on disk.

            Set objStream = Server.CreateOb ject("ADODB.Str eam")
            objStream.Open
            objStream.Type = adTypeBinary
            objStream.LoadF romFile strFilePath

            Response.Binary write objStream.Read

            objStream.Close
            Set objStream = Nothing

            '************** *************** *************



            "Chris Barber" <chris@blue-canoe.co.uk.NOS PAM> wrote in message
            news:%23coIWMWt DHA.1884@TK2MSF TNGP10.phx.gbl. ..[color=blue]
            > Look at ADODB.Stream
            >[/color]
            http://support.microsoft.com/default...NoWebContent=1[color=blue]
            >
            > You can load the object with the CSV and as long as the HTTP headers are[/color]
            set[color=blue]
            > correctly thenthe binary output (as Response.Write) will prompt the Save[/color]
            AS[color=blue]
            > dialog.
            >
            > <%
            > 'Set the content type to the specific type that you are sending.
            > Response.Conten tType = "text/csv"
            >
            > Const adTypeText = 2
            >
            > 'Create Stream object
            > Dim pobjStream
            > Set pobjStream = Server.CreateOb ject("ADODB.Str eam")
            >
            > 'Specify stream type - we want To save text/string data.
            > pobjStream.Type = adTypeText
            >
            > 'Open the stream And write binary data To the object
            > pobjStream.Open
            > pobjStream.Writ eText [YourGeneratedCS VText]
            >
            > Response.Binary Write objStream.Read
            >
            > pobjStream.Clos e
            > Set pobjStream = Nothing
            > %>
            >
            >
            > **** That might be Response.Write as opposed to BinaryWrite - not sure at
            > the moment.
            >
            > Chris.
            >
            > "Don Grover" <spamfree@assof t.com.au> wrote in message
            > news:%23kR87jVt DHA.2440@TK2MSF TNGP12.phx.gbl. ..
            > Thanks Greg.
            > Had a look but what I am after, I have a complex qry that financial users
            > select data from a web page by submitting a form.
            > I am calling an asp page that gets the data format as they require and I
            > have it a STRING in csv format.
            > The above is working correctly.
            >
            > What I want to do is automatically bring up a save as box to prompt them[/color]
            to[color=blue]
            > save it, I really dont want to save as file first unless I have too.
            >
            > Anyone have any ideas.
            > Don
            >
            > "Greg Griffiths" <greg2@surfaid. org> wrote in message
            > news:3FC68FBF.8 816FB9B@surfaid .org...[color=green]
            > > try :
            > >
            > > <a href="myCSVFile .csv">click here</a>
            > >
            > > If it opens in the browser then the user needs to amend their settings.
            > >
            > > see http://www.greggriffiths.org/webdev/both/excel/ for some other
            > > approaches.
            > >
            > > Don Grover wrote:
            > >[color=darkred]
            > > > How can I force a download of a csv file by user clicking on[/color][/color][/color]
            hyperlink.[color=blue][color=green][color=darkred]
            > > > Don[/color]
            > >[/color]
            >
            >[/color]



            Comment

            • Don Grover

              #7
              Re: auto download csv file

              Thanks chris, works like a dream.

              "Chris Barber" <chris@blue-canoe.co.uk.NOS PAM> wrote in message
              news:eU19CbftDH A.2492@TK2MSFTN GP12.phx.gbl...[color=blue]
              > Response.addHea der("content-disposition",
              > "attachment;fil ename=somefile. csv")
              >
              > Chris.
              >
              > "Don Grover" <spamfree@assof t.com.au> wrote in message
              > news:%23zFxsCYt DHA.3436@tk2msf tngp13.phx.gbl. ..
              > Thanks Chris
              > I can now get it to show a saved as box but it keeps putting in the actual
              > asp page as the file saveas file name.
              > How can I preload a file name.
              > '************** **************
              > Heres my Code
              >
              > 'Set the content type to the specific type that you are sending.
              > Response.Conten tType = "text/csv"
              >
              > Const adTypeBinary = 1
              > Dim strFilePath
              >
              > strFilePath = "c:\cokeshopScr ipts\exportdata .csv" 'This is the path to the
              > file on disk.
              >
              > Set objStream = Server.CreateOb ject("ADODB.Str eam")
              > objStream.Open
              > objStream.Type = adTypeBinary
              > objStream.LoadF romFile strFilePath
              >
              > Response.Binary write objStream.Read
              >
              > objStream.Close
              > Set objStream = Nothing
              >
              > '************** *************** *************
              >
              >
              >
              > "Chris Barber" <chris@blue-canoe.co.uk.NOS PAM> wrote in message
              > news:%23coIWMWt DHA.1884@TK2MSF TNGP10.phx.gbl. ..[color=green]
              > > Look at ADODB.Stream
              > >[/color]
              >[/color]
              http://support.microsoft.com/default...NoWebContent=1[color=blue][color=green]
              > >
              > > You can load the object with the CSV and as long as the HTTP headers are[/color]
              > set[color=green]
              > > correctly thenthe binary output (as Response.Write) will prompt the Save[/color]
              > AS[color=green]
              > > dialog.
              > >
              > > <%
              > > 'Set the content type to the specific type that you are sending.
              > > Response.Conten tType = "text/csv"
              > >
              > > Const adTypeText = 2
              > >
              > > 'Create Stream object
              > > Dim pobjStream
              > > Set pobjStream = Server.CreateOb ject("ADODB.Str eam")
              > >
              > > 'Specify stream type - we want To save text/string data.
              > > pobjStream.Type = adTypeText
              > >
              > > 'Open the stream And write binary data To the object
              > > pobjStream.Open
              > > pobjStream.Writ eText [YourGeneratedCS VText]
              > >
              > > Response.Binary Write objStream.Read
              > >
              > > pobjStream.Clos e
              > > Set pobjStream = Nothing
              > > %>
              > >
              > >
              > > **** That might be Response.Write as opposed to BinaryWrite - not sure[/color][/color]
              at[color=blue][color=green]
              > > the moment.
              > >
              > > Chris.
              > >
              > > "Don Grover" <spamfree@assof t.com.au> wrote in message
              > > news:%23kR87jVt DHA.2440@TK2MSF TNGP12.phx.gbl. ..
              > > Thanks Greg.
              > > Had a look but what I am after, I have a complex qry that financial[/color][/color]
              users[color=blue][color=green]
              > > select data from a web page by submitting a form.
              > > I am calling an asp page that gets the data format as they require and I
              > > have it a STRING in csv format.
              > > The above is working correctly.
              > >
              > > What I want to do is automatically bring up a save as box to prompt them[/color]
              > to[color=green]
              > > save it, I really dont want to save as file first unless I have too.
              > >
              > > Anyone have any ideas.
              > > Don
              > >
              > > "Greg Griffiths" <greg2@surfaid. org> wrote in message
              > > news:3FC68FBF.8 816FB9B@surfaid .org...[color=darkred]
              > > > try :
              > > >
              > > > <a href="myCSVFile .csv">click here</a>
              > > >
              > > > If it opens in the browser then the user needs to amend their[/color][/color][/color]
              settings.[color=blue][color=green][color=darkred]
              > > >
              > > > see http://www.greggriffiths.org/webdev/both/excel/ for some other
              > > > approaches.
              > > >
              > > > Don Grover wrote:
              > > >
              > > > > How can I force a download of a csv file by user clicking on[/color][/color]
              > hyperlink.[color=green][color=darkred]
              > > > > Don
              > > >[/color]
              > >
              > >[/color]
              >
              >
              >[/color]


              Comment

              Working...