Connecting Tech Pros Worldwide Forums | Help | Site Map

How to set the filename of a downloaded file?

Alan Silver
Guest
 
Posts: n/a
#1: Jan 30 '06
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)

Hermit Dave
Guest
 
Posts: n/a
#2: Jan 30 '06

re: How to set the filename of a downloaded file?


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:
[color=blue]
> 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)
>[/color]
Alan Silver
Guest
 
Posts: n/a
#3: Jan 30 '06

re: How to set the filename of a downloaded file?


Thanks, that's just what I wanted.
[color=blue]
>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
>[/color]

--
Alan Silver
(anything added below this line is nothing to do with me)
Closed Thread