Click here to Skip to main content
12,829,115 members (35,602 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked
Posted 5 Sep 2000

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:

    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

    You may also be interested in...


    Comments and Discussions

    QuestionCompiled .DLL? Pin
    KlausDK8-Nov-16 7:00
    memberKlausDK8-Nov-16 7:00 
    GeneralMy vote of 1 Pin
    kraftspl11-Jan-09 12:19
    memberkraftspl11-Jan-09 12:19 
    GeneralIE 6 can't download a zip file Pin
    PiyushVarma18-Nov-08 9:49
    memberPiyushVarma18-Nov-08 9:49 
    Questiondownloading music file using ASP Pin
    snigdhajayan25-Jun-08 21:35
    membersnigdhajayan25-Jun-08 21:35 
    Generaldownloading music file using ASP Pin
    snigdhajayan25-Jun-08 21:33
    membersnigdhajayan25-Jun-08 21:33 
    Generaldown loading Pin
    mnalammwb14-Mar-08 5:23
    membermnalammwb14-Mar-08 5:23 
    Generalerror - cannot create activexcontrol Pin
    Priya B21-Oct-07 21:11
    memberPriya B21-Oct-07 21:11 
    GeneralI can't download Pin
    Chanda_khanapure1-Feb-06 0:56
    memberChanda_khanapure1-Feb-06 0:56 
    Generalmultiple downloads Pin
    moorprab7-Oct-05 20:57
    membermoorprab7-Oct-05 20:57 
    Questionhow to view word files Pin
    mitesh22228-Sep-05 20:48
    membermitesh22228-Sep-05 20:48 
    Generaldisplay vc++ output string on a browser using asp Pin
    rockyn3192-May-05 22:58
    memberrockyn3192-May-05 22:58 
    Questionhow 2 get download pop up window? Pin
    smrits6-Apr-05 21:15
    membersmrits6-Apr-05 21:15 
    GeneralMIME setting in IIS 5.0 Pin
    nia_put7-Sep-04 10:02
    membernia_put7-Sep-04 10:02 
    GeneralDownload image field from SQL-Server Pin
    Zoink15-Jul-04 1:34
    memberZoink15-Jul-04 1:34 
    GeneralHelp me please~~ Pin
    charcoalc5-May-04 1:54
    membercharcoalc5-May-04 1:54 
    GeneralError: Response object, ASP 0106 (0x80020005) Pin
    ravda21-Aug-03 10:23
    memberravda21-Aug-03 10:23 
    Hello everybody,

    I'm Roland and new to this community.
    I tried out the FileTransfer component and everything works fine with VBScript. However, I prefer to program in JavaScript as this is closer to "C" which we use for our application.

    The file to be transferred is an executable.

    With the Javascript I get the following error:
    Error Type:
    Response object, ASP 0106 (0x80020005)
    An unhandled data type was encountered.
    Error line: Response.BinaryWrite(saBinFile) ;

    Anybody who can help me?
    Both scripts below.

    Many thanks in advance,
    Roland Confused | :confused:

    Option Explicit
    Dim objBinaryRead
    Dim saBinFile
    Dim bDownloadStatus
    Dim FilePath

    FilePath = "c:\Inetpub\wwwroot\MyWeb\MyFile.exe"

    Set objBinaryRead = CreateObject("FileTransfer.BinaryRead")

    Response.Buffer = true
    Response.ContentType = "application/x-msdownload"
    Response.AddHeader "content-disposition", "filename=MyFile.exe"

    saBinFile = objBinaryRead.ReadBinFile(FilePath)
    Response.BinaryWrite saBinFile

    Set saBinFile = nothing
    Set objBinaryRead = nothing

    <%@ LANGUAGE = JavaScript %>
    Response.Buffer = "True" ;
    Response.ContentType = "application/x-msdownload" ;

    var objBinaryRead = Server.CreateObject("FileTransfer.BinaryRead") ;
    var FilePath = "c:\Inetpub\wwwroot\MyWeb\MyFile.exe" ;

    Response.AddHeader("content-disposition", "filename=MyFile.exe") ;

    var saBinFile = objBinaryRead.ReadBinFile(FilePath) ;
    Response.BinaryWrite(saBinFile) ;

    saBinFile = null ;
    objBinaryRead = null ;
    Response.End ;
    GeneralFile transfer object Pin
    pjaka2-Apr-03 0:41
    memberpjaka2-Apr-03 0:41 
    QuestionI failed to download zip file? Pin
    Binary Programmer1-Mar-03 1:17
    memberBinary Programmer1-Mar-03 1:17 
    AnswerRe: I failed to download zip file? Pin
    Binary Programmer13-May-03 0:15
    memberBinary Programmer13-May-03 0:15 
    AnswerRe: I failed to download zip file? Pin
    madprincehatter3-Sep-03 10:17
    membermadprincehatter3-Sep-03 10:17 
    GeneralI think I have the solution Pin
    stewe28-Feb-03 2:36
    memberstewe28-Feb-03 2:36 
    GeneralRe: I think I have the solution Pin
    dmanoharan20-May-03 23:26
    memberdmanoharan20-May-03 23:26 
    QuestionDownloaded become empty? Pin
    Binary Programmer21-Feb-03 4:25
    memberBinary Programmer21-Feb-03 4:25 
    AnswerRe: Downloaded become empty? Pin
    stewe28-Feb-03 2:10
    memberstewe28-Feb-03 2:10 
    GeneralRe: Downloaded become empty? Pin
    Binary Programmer28-Feb-03 23:17
    memberBinary Programmer28-Feb-03 23:17 

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

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

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