Dear All: I have seen many threads in this forum where developers ask: >> How to download a file by opening the “Save As Dialog” in ASP.NET? I found it convenient to create a component that will make your life easy whenever you want to download a file. All
of you know that the process of saving or downloading a file from the server to the client is done by rewriting the header by attaching to it the file that is to be downloaded. You can download
DownLoadFile 1.0 component for free. However, source code is not available. Once you download the zip file above. Unzip it and you will find a single dll file called DownLoadFile.dll. Steps to install this component: 1-
Place the DownLoadFile in the bin directory of your web application 2- If you are using Visual Studio.NET 2003, you will have to Add Reference and choose the dll file found in the bin directory of your web application The namespace DownLoadFile contains only
one class called DownLoad. This class has only one method called DFile. DFile method has the following header declaration: public static void DFile( string FileName) Where: 1- FileName Represents the name of the file to be downloaded (string value) Steps to
use the control: 1- For Code-Behind, add the following to the list of classes imported in the current page: using DownLoadedFile; 2- For Code-Inline, add the following import statement: 2- Inside your server-side code, use the following method call to open
a new window: DownLoad.DFile("~/Files/test.exe"); The above method call would open the Save AS Dialog box, prompting to download the executable file called test.exe located in subfolder Files, has the following attribute: File to be downloaded is test.exe
File Extensions that are allowed to be downloaded with this control are: .htm .html .txt .zip .xls .ppt .pps .pdf .png .gif .jpeg .jpg .jpe .doc .rtf .exe This component has been tested only on IE browser. If you have any comments please don’t hesitate to
contact me here at this thread or even at my personal email: bhaidar@gmail.com Happy Programming!! Best Regards Sincerely, Bilal A. Haidar
haidar_bilal
All-Star
45607 Points
8728 Posts
MVP
DownLoadFile Control
Feb 20, 2005 09:41 AM|LINK