Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking 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 Basics 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
 
Old June 14th, 2006, 07:27 AM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Downloading files via a browser

I have been looking for the way to download and save a file utilizing ASP.NET. I see plenty written on uploading files to the server. I also have been to many websites where a click invokes a SaveAs dialog to initiate a file download from the server. It appears that no book on ASP.NET addresses this subject. Can anybody shed any light on downloading files via the browser?



 
Old June 14th, 2006, 09:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

this is a way i found but i dont remeber when.. you should not credit me for this thing... I have this being used in an application and is working...


        Response.AppendHeader("content-disposition", "attachment; filename=" & sFileName)
        Response.ContentType = "application/octet-stream"
        Response.WriteFile(sFileNameWithPath)
        Response.Flush()



HTH

Gonzalo
 
Old June 14th, 2006, 03:53 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I appreciate the response. I was told today by a co-worker that if I initialize a hyperlink to a file (i.e. .exe, .txt, .pdf, etc.) on the server and subsequently a user clicks on that link, the browser, recognizing the link to the file, will invoke a dialog to prompt the user to save or open the file. In other words, the download of a file is a functionality that is implicit in the browser and no server-side code is require to perform the download.

 
Old June 14th, 2006, 04:13 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, that all depends on the browser's configuration.

On many systems, you'll find that .doc, .pdf, .txt, .xls and others are opened in the browser, because the browser *does* recognize them and is able to initialize a viewer....

I think the code that gbianchi posted should make *all* files be recognized as a downloadable, and not a viewable file....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem downloading sensitive files mat41 Classic ASP Professional 1 May 4th, 2006 08:45 PM
Please suggest me downloading 2 files at same time kvingupta Pro VB 6 0 March 7th, 2006 09:01 AM
Protect Files from downloading asif_sharif ASP.NET 1.0 and 1.1 Professional 6 January 11th, 2006 01:59 AM
deny downloading image files. jojys Javascript How-To 1 October 19th, 2004 03:17 PM
downloading files serge Classic ASP Professional 4 September 8th, 2003 10:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.