 |
| ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 15th, 2008, 12:14 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Downloading files from website to user's PC
Hi all,
I can't find any examples anywhere for how to download a file from my company's website to a user's PC. There'll be a gridview showing a list of (PDF) documents, with a linkbutton on each row, and when the user clicks on the linkbutton, I want it to open the download dialog so the user can browse to their desired folder and click download. (When I looked for this about 4-5 months ago, I couldn't find anything then either, and even found one comment that it wasn't possible.) Does anybody know how to do this? Thanks very much in advance for any help or advice.
-- LenexaKS
|
|

February 15th, 2008, 12:27 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
PDF's, by default, will open in the browser and, as far as I know, there is no way to pragmatically override these settings so that the user is prompated with a file download as oppsed to the pdf opening in the browser.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
|
|

February 15th, 2008, 12:39 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
You can certainly do it, and it's pretty easy to do. Here's quick example:
Code:
string fileName = "Test.pdf";
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/x-unknown";
Response.WriteFile(Server.MapPath(fileName));
Searching for stream file asp.net on Google should give you more results / ideas.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|

February 15th, 2008, 12:41 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks DParsons... I suspected that was the case.
|
|

February 15th, 2008, 12:44 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Ya, I learned something today! Thats why Imar gets paid the big buck ;]
Good stuff.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
|
|

February 15th, 2008, 01:06 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Big bucks == big money. My mistake. =]
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
|
|

February 15th, 2008, 01:17 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Haha, only in a perfect world would we get paid to post here but maybe Jim can squeeze that into his budget for next year ;]
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
|
|

February 15th, 2008, 02:51 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Imar, works like a charm!
(BTW, dparsons said "big BUCK", not "big buckS". But good karma from saving an ignorant coder is its own reward.)
|
|
 |