Downloading files...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ruskin Hardie

    Downloading files...

    The help is not very informative here, but it says, that it is possible to
    download files, by using the 'a' tag. What I am trying to do, is create a
    link, that the user clicks, which will download a file from the server. This
    works fine for most files, but for things like TXT and HTM, they open in the
    browser window. I want the 'Save As' dialog box to appear, instead...

    If I use;
    Response.Write "<a href='http://mydomain/myfile.txt'>myf ile</a>"
    I get the contents of myfile.txt displayed in the browser window. If I use;
    Response.Write "<a href='http://mydomain/myfile.mdb'>myf ile</a>"
    I get the 'save file as' dialog box appear. How do I force the 'save file
    as' dialog box to appear for ALL files?

    I tried using the 'FileSystemObje ct' and using the 'Copy' method of GetFile.
    But this does not allow you to have a 'user defined' path to save the file
    (which is pretty obvious, as this is the server side)... Is there another
    function that I can use, or is there a property setting of the anchor tag,
    that I need to set?


  • Chet

    #2
    Re: Downloading files...


    "Ruskin Hardie" <RuHardie@xtra. NOSPAM.co.nz> wrote in message
    news:lRc%b.2379 $SZ.74682@news. xtra.co.nz...
    | The help is not very informative here, but it says, that it is
    possible to
    | download files, by using the 'a' tag. What I am trying to do,
    is create a
    | link, that the user clicks, which will download a file from the
    server. This
    | works fine for most files, but for things like TXT and HTM,
    they open in the
    | browser window. I want the 'Save As' dialog box to appear,
    instead...
    |
    | If I use;
    | Response.Write "<a
    href='http://mydomain/myfile.txt'>myf ile</a>"
    | I get the contents of myfile.txt displayed in the browser
    window. If I use;
    | Response.Write "<a
    href='http://mydomain/myfile.mdb'>myf ile</a>"
    | I get the 'save file as' dialog box appear. How do I force the
    'save file
    | as' dialog box to appear for ALL files?
    |
    | I tried using the 'FileSystemObje ct' and using the 'Copy'
    method of GetFile.
    | But this does not allow you to have a 'user defined' path to
    save the file
    | (which is pretty obvious, as this is the server side)... Is
    there another
    | function that I can use, or is there a property setting of the
    anchor tag,
    | that I need to set?
    |

    It's somewhat hard to control your visitor's browsers settings.
    Most browsers are set to display .txt and .htm files. Depending
    on your server, I believe it's possible to configure some servers
    that would send the file different, but then I'm not sure if your
    pages would appear (they're .htm probably). You may want to check
    with your hosting provider.

    One other way is to put the files into a .zip file. Not only will
    this download properly, the file size may be greatly reduced.

    hth
    --
    Chet
    ng2.chet@NOchar terSPAM.net (remove NO.....SPAM)


    Comment

    • jenny mabe

      #3
      Re: Downloading files...

      > The help is not very informative here, but it says, that it is possible [color=blue]
      > to download files, by using the 'a' tag. What I am trying to do, is
      > create a
      > link, that the user clicks, which will download a file from the server..
      > This works fine for most files, but for things like TXT and HTM, they
      > open in the browser window. I want the 'Save As' dialog box to appear,
      > instead...[/color]

      the behaviour of the browser is triggered by the file's
      content-disposition header. if you are, for example, streaming a txt file
      to the user and want to force a download, you can even specify the file to
      save it as by placing this line above all of the other code on the page:

      Response.AddHea der "content-disposition","a ttachment; filename=fname. ext"

      more information on this technique and how to use it statically can be
      found here:



      jenny

      Comment

      • Chet

        #4
        Re: Downloading files...


        "jenny mabe" <news@rabidduck .com> wrote in message
        news:opr3ym3qx8 qafk40@localhos t...
        | > The help is not very informative here, but it says, that it
        is possible
        | > to download files, by using the 'a' tag. What I am trying to
        do, is
        | > create a
        | > link, that the user clicks, which will download a file from
        the server.
        | > This works fine for most files, but for things like TXT and
        HTM, they
        | > open in the browser window. I want the 'Save As' dialog box
        to appear,
        | > instead...
        |
        | the behaviour of the browser is triggered by the file's
        | content-disposition header. if you are, for example, streaming
        a txt file
        | to the user and want to force a download, you can even specify
        the file to
        | save it as by placing this line above all of the other code on
        the page:
        |
        | Response.AddHea der "content-disposition","a ttachment;
        filename=fname. ext"
        |
        | more information on this technique and how to use it statically
        can be
        | found here:
        |
        |http://support.microsoft.com/default...p://support.mi
        crosoft.com:80/support/kb/articles/Q260/5/19.ASP&NoWebCon tent=1
        |
        |
        | jenny

        Jenny

        When you do this dynamically, you would change fname.ext to the
        file you wanted download, correct? And you'd place it as below:

        <%@ Language=VBScri pt %>
        <% Response.AddHea der "content-disposition","a ttachment;
        filename=sample .htm"
        %>
        <!DOCTYPE ...>
        <html>
        <head>
        </head>
        <body>content of htm file to be downloaded
        </body>
        </html>

        A few quick questions,

        1) Could you include asp in the "sample.htm " file (above) that
        would be parsed prior to being sent?

        2) On the page you referenced, it says, "To apply the header
        statically, right-click the document in the Internet Service
        Manager...enter the content-disposition header there."

        I'm learning, what's the Internet Service Manager. I "presume"
        its on the server (IIS)?? I use PWS on Win98SE and haven't ran
        across this. I liked the part about the bug in IE4! (ha)

        3) On the page you referenced, it also says, "When Internet
        Explorer receives the header..." Will this work with other
        browsers? i.e., Mozilla, Netscape, Opera...etc.

        Thanks for the info in your first reply.
        --
        Chet
        ng2.chet@NOchar terSPAM.net (remove NO.....SPAM)


        Comment

        • jenny mabe

          #5
          Re: Downloading files...

          On Wed, 25 Feb 2004 21:33:05 -0800, Chet <ng2.chet@NOcha rterSPAM.net>
          wrote:
          [color=blue]
          > When you do this dynamically, you would change fname.ext to the
          > file you wanted download, correct? And you'd place it as below:
          >
          > <%@ Language=VBScri pt %>
          > <% Response.AddHea der "content-disposition","a ttachment;
          > filename=sample .htm"
          > %>[/color]

          yes, that is correct.
          [color=blue]
          > 1) Could you include asp in the "sample.htm " file (above) that
          > would be parsed prior to being sent?[/color]

          create the asp page to display just as in any other asp page the contents
          you want the user to see when the file is opened -- any asp or html or
          anything else you would normally display. you can really put anything here
          -- plain text for a txt file, an html table for an excel file (excel will
          automatically convert html tables), anything as long as the content-type
          header and the file in the content-disposition header are set correctly
          for the file.
          [color=blue]
          > 2) On the page you referenced, it says, "To apply the header
          > statically, right-click the document in the Internet Service
          > Manager...enter the content-disposition header there."
          > I'm learning, what's the Internet Service Manager. I "presume"
          > its on the server (IIS)?? I use PWS on Win98SE and haven't ran
          > across this. I liked the part about the bug in IE4! (ha)[/color]

          yes, that would be IIS. unfortunately, i dont have a 98 machine to check
          for your operating system -- whatever application or control panel you use
          to designate website properties, directories, etc.
          [color=blue]
          > 3) On the page you referenced, it also says, "When Internet
          > Explorer receives the header..." Will this work with other
          > browsers? i.e., Mozilla, Netscape, Opera...etc.[/color]

          yes, it should. some relevant info is here:
          Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology



          jenny

          Comment

          • Chet

            #6
            Re: Downloading files...

            Thanks Jenny, really appreciate the info.

            --
            Chet
            ng2.chet@NOchar terSPAM.net (remove NO.....SPAM)


            Comment

            • Roy Danon

              #7
              Example

              <%
              strFileName="fo rce_download.as p" 'file to download

              Response.Buffer = True
              strFilePath=ser ver.mappath(str Filename)
              set fso=createobjec t("scripting.fi lesystemobject" )
              set f=fso.getfile(s trfilepath)
              strFileSize = f.size
              set f=nothing: set fso=nothing
              Const adTypeBinary = 1
              Response.Clear
              Set objStream = Server.CreateOb ject("ADODB.Str eam")
              objStream.Open
              objStream.Type = adTypeBinary
              objStream.LoadF romFile strFilePath
              strFileType = "file/asp" ' change to the correct content type for your file
              Response.AddHea der "Content-Disposition", "attachment ; filename=" &
              strFileName
              Response.AddHea der "Content-Length", strFileSize
              Response.Charse t = "UTF-8"
              Response.Conten tType = strFileType
              Response.Binary Write objStream.Read
              Response.Flush
              objStream.Close
              Set objStream = Nothing
              %>


              "Ruskin Hardie" <RuHardie@xtra. NOSPAM.co.nz> wrote in message
              news:lRc%b.2379 $SZ.74682@news. xtra.co.nz...[color=blue]
              > The help is not very informative here, but it says, that it is possible to
              > download files, by using the 'a' tag. What I am trying to do, is create a
              > link, that the user clicks, which will download a file from the server.[/color]
              This[color=blue]
              > works fine for most files, but for things like TXT and HTM, they open in[/color]
              the[color=blue]
              > browser window. I want the 'Save As' dialog box to appear, instead...
              >
              > If I use;
              > Response.Write "<a href='http://mydomain/myfile.txt'>myf ile</a>"
              > I get the contents of myfile.txt displayed in the browser window. If I[/color]
              use;[color=blue]
              > Response.Write "<a href='http://mydomain/myfile.mdb'>myf ile</a>"
              > I get the 'save file as' dialog box appear. How do I force the 'save file
              > as' dialog box to appear for ALL files?
              >
              > I tried using the 'FileSystemObje ct' and using the 'Copy' method of[/color]
              GetFile.[color=blue]
              > But this does not allow you to have a 'user defined' path to save the file
              > (which is pretty obvious, as this is the server side)... Is there another
              > function that I can use, or is there a property setting of the anchor tag,
              > that I need to set?
              >
              >[/color]


              Comment

              Working...