How to set the filename of a downloaded file?

A

Alan Silver

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
 
G

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
 
A

Alan Silver

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top