How to set the filename of a downloaded file?

Discussion in 'ASP .Net' started by Alan Silver, Jan 30, 2006.

  1. Alan Silver

    Alan Silver Guest

    Hello,

    I have a page on a site where people can download audio files. At the
    moment, the link on the site sends them to a page where the download is
    logged in a database, then does a Response.Redirect to the actual audio
    file.

    This works fine, but has the disadvantage that the file that is sent
    back has the original file name, which is currently just the database
    ID. I would like to set the file name to something more meaningful, like
    FredsAudio-HowToSellYourCar.wav (or whatever).

    Any way to do this? I know I could just store the wav files with
    meaningful names in the first place, but that means a) a major rewrite
    of a working site and b) more complex code sorting out the file names.
    It would be much easier if there were a way to set the file name that
    the user sees.

    TIA

    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Jan 30, 2006
    #1
    1. Advertising

  2. Instead of passing the link to the actual file you can pass them to an aspx
    page which by some param decides what file to pass.

    to force download you need to put a proper content type and then add a http
    header specifying the filename

    when all that is done us Response.WriteBinary to write the stream to
    reponse.outputstream or use Response.WriteFile

    have a look at this page for more info. contains some code samples
    http://aspalliance.com/259

    --

    Regards,

    Hermit Dave (D'way)
    http://hdave.blogspot.com



    "Alan Silver" wrote:

    > Hello,
    >
    > I have a page on a site where people can download audio files. At the
    > moment, the link on the site sends them to a page where the download is
    > logged in a database, then does a Response.Redirect to the actual audio
    > file.
    >
    > This works fine, but has the disadvantage that the file that is sent
    > back has the original file name, which is currently just the database
    > ID. I would like to set the file name to something more meaningful, like
    > FredsAudio-HowToSellYourCar.wav (or whatever).
    >
    > Any way to do this? I know I could just store the wav files with
    > meaningful names in the first place, but that means a) a major rewrite
    > of a working site and b) more complex code sorting out the file names.
    > It would be much easier if there were a way to set the file name that
    > the user sees.
    >
    > TIA
    >
    > --
    > Alan Silver
    > (anything added below this line is nothing to do with me)
    >
     
    =?Utf-8?B?SGVybWl0IERhdmU=?=, Jan 30, 2006
    #2
    1. Advertising

  3. Alan Silver

    Alan Silver Guest

    Thanks, that's just what I wanted.

    >Instead of passing the link to the actual file you can pass them to an aspx
    >page which by some param decides what file to pass.
    >
    >to force download you need to put a proper content type and then add a http
    >header specifying the filename
    >
    >when all that is done us Response.WriteBinary to write the stream to
    >reponse.outputstream or use Response.WriteFile
    >
    >have a look at this page for more info. contains some code samples
    >http://aspalliance.com/259
    >


    --
    Alan Silver
    (anything added below this line is nothing to do with me)
     
    Alan Silver, Jan 30, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    Extract filename from a filename typed by user

    =?Utf-8?B?Sm9l?=, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,035
    Travis Murray
    Aug 24, 2004
  2. Bob Weiner

    controlling a downloaded filename

    Bob Weiner, May 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    407
    Bob Weiner
    May 19, 2005
  3. Ben Jessel
    Replies:
    2
    Views:
    350
    Andy Fish
    Nov 25, 2003
  4. Ed
    Replies:
    10
    Views:
    45,998
    alok000707
    Jul 13, 2010
  5. Stefano Crocco
    Replies:
    0
    Views:
    149
    Stefano Crocco
    Nov 14, 2008
Loading...

Share This Page