473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to set the filename of a downloaded file?

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)
Jan 30 '06 #1
2 1224
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)

Jan 30 '06 #2
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)
Jan 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Kornelius Finkenbein | last post by:
Hello folks! I've got a strange problem with my download-script in conjunction with M$ internet explorer, if the filename I want to link to includes more than one points. In Netscape the problem...
3
by: Russell | last post by:
Hi, I'm using php to generate a csv file and want to force the user to download it to their local PC. Trouble is, when I use: header("Content-Disposition: attachment;...
7
by: deko | last post by:
I need to allow users to download files from a directory that is not publicly accessible. To do this, I use a download script: header("Content-Type: application/octet-stream");...
2
by: andylong :: andrea : azzini | last post by:
My problem is: i need to write an ASP page which first checks whether the user has permissions to download a ZIP file, and then streams the file itself if the user is allowed to see it. I have...
7
by: J1C | last post by:
How could I create a random filename for a single-use download? So, if a user was to download a file from a site it would send them a unique filename that could only be used once. That link would...
2
by: Bob Weiner | last post by:
Can I control the name of a file downloaded if that file name isn't in a request header? I have a data grid that contains a list of excel files by date. In each row there is a ButtonColumn...
4
by: news.microsoft.com | last post by:
Hello All, im am new to ASP.NET, so bare with me. i have an application that i am building in stages. stage1 user picks data required stage2 file is written to a virutal directory Stage3...
2
by: rudderstick | last post by:
Hi there all, I have an interesting problem.... I work for a company that develops software for the building industry and would like to distribute one of our software products via the web. ...
10
by: Steve | last post by:
I am trying to create a downloader which will bypass the saveas box in the WebBrowser control. I have the file downloading, but I don't know what the filename is that is being passed through the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.