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, Jan 30, 2006
    #1
    1. Advertisements

  2. Alan Silver

    Guest Guest

    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
     
    Guest, Jan 30, 2006
    #2
    1. Advertisements

  3. Alan Silver

    Alan Silver Guest

    Thanks, that's just what I wanted.
     
    Alan Silver, Jan 30, 2006
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.