Download links

R

Ron

Hi all,

Probably a simple question... How can I make a link or a button
download a file instead of just opening it? Thanks.
 
L

Lucas Tam

(e-mail address removed) (Ron) wrote in
Probably a simple question... How can I make a link or a button
download a file instead of just opening it?

You need to change the Response.ContentType to an unknown content type.
 
S

Steve C. Orr [MVP, MCSD]

E

Eric

Steve said:
Response.ContentType = "application/PDF";
Response.AppendHeader("content-disposition", "attachment:
filename=test.pdf");
Response.WriteFile("c:\test.pdf");

Here's more info:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref
/html/frlrfsystemwebhttpresponseclasswritefiletopic.asp
http://searchvb.techtarget.com/vsnetTip/1,293823,sid8_gci937876_tax293
033,00.html
http://www.aspnetpro.com/NewsletterArticle/2003/09/asp200309so_l/asp20
0309so_l.asp

The WriteFile needs a MapPath:

Response.WriteFile(Server.MapPath(@"c:\test.pdf"));

Eric
 
E

Eric

Eric said:
The WriteFile needs a MapPath:

Response.WriteFile(Server.MapPath(@"c:\test.pdf"));

Eric

Sorry, I guess it doesn't need MapPath if you specify a full pathname.

Eric
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top