Click here to Skip to main content
Click here to Skip to main content

File downloading with COM and ASP

, , 5 Sep 2000
Rate this:
Please Sign up or sign in to vote.
A COM object you can use to transfer files in ASP
<!-- Download Links -->
  • VC Component source - 43 Kb
  • VB Component source - 6 Kb
  • Example ASP script - 1 Kb
  • Introduction

    This article is about direct file downloading through a COM component. It uses the IResponse interface to send a file directly to the client browser.

    With this approach you can protect your files from being downloaded by an unauthorized person.

    To send the file to the client you need to register this kind of file within the IIS MIME types. To do it go to the ISS administration and under the HTTP Header add this kind of file. In the sample a zip file is used, so the MIME type is:

    To send a file to the browser you must set the Response.Buffer to TRUE and the ContentType to the file type. After this you send the data using the Response object through the BinaryWrite method.

    To accomplish this task a component was developed: FileTransfer. The interface used is called IBinaryRead. These are its methods:

    Method Description
    ReadBinFile(filename) This method returns the content of the file as an VARIANT (SAFEARRAY)
    ResponseBinaryWrite(filename, responseObject) This method reads the file and send it using the Response object. It returns the operation result

    If you want to download a custom file type, you must register it in the client machine too.

    An example of using the FileTransfer object follows:

    	Option Explicit
    	Dim objBinaryRead 
    	Dim saBinFile		'if you don't want error safe
    	Dim bDownloadStatus
    	Set objBinaryRead = CreateObject("FileTransfer.BinaryRead")
    	Response.Buffer      = true
    	Response.ContentType = "application/x-zip-compressed"
    	'transfer the file to the client		
    	bDownloadStatus = objBinaryRead.ResponseBinaryWrite("c:\temp\", Response)
    	'this is not an error safe code
    	'if the file doesn't exist the ASP will have an error
    	'saBinFile = objBinaryRead.ReadBinFile("c:\temp\")     
    	'Response.BinaryWrite saBinFile
    	'Set saBinFile     = nothing
    	Set objBinaryRead = nothing


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Authors

    Architect VisionOne AG
    Switzerland Switzerland
    XicoLoko is a brazilian developer based in Switzerland.

    Curt Robinson

    United States United States
    No Biography provided

    Comments and Discussions

    GeneralMy vote of 1 Pinmemberkraftspl11-Jan-09 12:19 
    GeneralIE 6 can't download a zip file PinmemberPiyushVarma18-Nov-08 9:49 
    Questiondownloading music file using ASP Pinmembersnigdhajayan25-Jun-08 21:35 
    Generaldownloading music file using ASP Pinmembersnigdhajayan25-Jun-08 21:33 
    Generaldown loading Pinmembermnalammwb14-Mar-08 5:23 
    Generalerror - cannot create activexcontrol PinmemberPriya B21-Oct-07 21:11 
    GeneralI can't download PinmemberChanda_khanapure1-Feb-06 0:56 
    Generalmultiple downloads Pinmembermoorprab7-Oct-05 20:57 
    Questionhow to view word files Pinmembermitesh22228-Sep-05 20:48 
    Generaldisplay vc++ output string on a browser using asp Pinmemberrockyn3192-May-05 22:58 
    Questionhow 2 get download pop up window? Pinmembersmrits6-Apr-05 21:15 
    GeneralMIME setting in IIS 5.0 Pinmembernia_put7-Sep-04 10:02 
    GeneralDownload image field from SQL-Server PinmemberZoink15-Jul-04 1:34 
    GeneralHelp me please~~ Pinmembercharcoalc5-May-04 1:54 
    GeneralError: Response object, ASP 0106 (0x80020005) Pinmemberravda21-Aug-03 10:23 
    GeneralFile transfer object Pinmemberpjaka2-Apr-03 0:41 
    QuestionI failed to download zip file? PinmemberBinary Programmer1-Mar-03 1:17 
    I just found that I can download small size file.
    I successfully download a test.txt.
    I just couldn't download .zip file no matter how big or small the zip file is.

    Any comment?

    AnswerRe: I failed to download zip file? PinmemberBinary Programmer13-May-03 0:15 
    AnswerRe: I failed to download zip file? Pinmembermadprincehatter3-Sep-03 10:17 
    GeneralI think I have the solution Pinmemberstewe28-Feb-03 2:36 
    GeneralRe: I think I have the solution Pinmemberdmanoharan20-May-03 23:26 
    QuestionDownloaded become empty? PinmemberBinary Programmer21-Feb-03 4:25 
    AnswerRe: Downloaded become empty? Pinmemberstewe28-Feb-03 2:10 
    GeneralRe: Downloaded become empty? PinmemberBinary Programmer28-Feb-03 23:17 
    GeneralAccess to Excel problem PinsussAnonymous5-Dec-02 1:44 
    QuestionHow to know where the file is saved ? PinsussAnonymous19-Nov-02 16:34 
    AnswerRe: How to know where the file is saved ? PinsussAnonymous15-Jul-05 19:35 
    Generalthere much time for large file Pinmemberjinux23-Sep-02 20:29 
    Generaldowloading a pdf file PinmemberArti17-Jun-02 7:26 
    GeneralRe: dowloading a pdf file PinmemberAnonymous23-Jun-02 15:29 
    GeneralRe: dowloading a pdf file PinsussAnonymous30-Jan-04 10:26 
    Generaldownloading files with Netscape PinmemberMatti Niskasaari3-Jan-02 1:24 
    GeneralFile Download PinmemberLakshmi Kanth Upadrasta15-Nov-01 13:25 
    GeneralDownload file Pinmemberedss7-Nov-01 2:39 
    Generalprocess names the file incorrectly Pinmemberlyndonjohnson14-Aug-01 10:56 
    GeneralRe: process names the file incorrectly PinmemberTai15-Aug-01 17:23 
    GeneralRe: process names the file incorrectly PinmemberMichael Stern6-Sep-01 6:15 
    Generalmime types Pinmemberluc2-Aug-01 4:49 
    GeneralRe: mime types PinmemberJocke6-Aug-01 3:34 
    QuestionHow to use? PinmemberAnonymous31-Jul-01 23:22 
    AnswerRe: How to use? PinmemberEZUID16-Jan-03 19:49 
    Questiona zip file with ASP?? Pinmemberlinda31-Jul-01 7:43 
    Generalchoosing which file is downloaded PinmemberJ Koenig26-Jul-01 12:29 
    GeneralRe: choosing which file is downloaded PinmemberApurv13-Mar-02 3:27 
    GeneralRe: choosing which file is downloaded Pinmemberxicoloko13-Mar-02 6:14 
    QuestionHow to find if the file was successfully downloaded? PinmemberAnonymous9-May-01 16:46 
    AnswerRe: How to find if the file was successfully downloaded? PinmemberKen Dabbs14-Jun-01 5:16 
    QuestionHow set File Download dialog PinmemberMax A. Tkachenko5-Apr-01 6:02 
    AnswerRe: How set File Download dialog PinmemberKen Dabbs14-Jun-01 5:13 
    GeneralRe: How set File Download dialog PinmemberDr. Bonne13-Aug-01 8:24 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.150414.1 | Last Updated 6 Sep 2000
    Article Copyright 2000 by xicoloko, Curt Robinson
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid