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

File downloading with COM and ASP

By , , 5 Sep 2000
 
  • 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:

    Extension=.zip
    ContentType=application/x-zip-compressed
    

    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\test.zip", 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\test.zip")     
    	'Response.BinaryWrite saBinFile
    	'Set saBinFile     = nothing
    	
    	Set objBinaryRead = nothing
    %>
    

    License

    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

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

    Curt Robinson
    United States United States
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralMy vote of 1memberkraftspl11 Jan '09 - 11:19 
    GeneralIE 6 can't download a zip filememberPiyushVarma18 Nov '08 - 8:49 
    Questiondownloading music file using ASPmembersnigdhajayan25 Jun '08 - 20:35 
    Generaldownloading music file using ASPmembersnigdhajayan25 Jun '08 - 20:33 
    Generaldown loadingmembermnalammwb14 Mar '08 - 4:23 
    Generalerror - cannot create activexcontrolmemberPriya B21 Oct '07 - 20:11 
    GeneralI can't downloadmemberChanda_khanapure31 Jan '06 - 23:56 
    Generalmultiple downloadsmembermoorprab7 Oct '05 - 19:57 
    how to process multiple downloads simultaneously?
    Questionhow to view word filesmembermitesh22228 Sep '05 - 19:48 
    Generaldisplay vc++ output string on a browser using aspmemberrockyn3192 May '05 - 21:58 
    Questionhow 2 get download pop up window?membersmrits6 Apr '05 - 20:15 
    GeneralMIME setting in IIS 5.0membernia_put7 Sep '04 - 9:02 
    GeneralDownload image field from SQL-ServermemberZoink15 Jul '04 - 0:34 
    GeneralHelp me please~~membercharcoalc5 May '04 - 0:54 
    GeneralError: Response object, ASP 0106 (0x80020005)memberravda21 Aug '03 - 9:23 
    GeneralFile transfer objectmemberpjaka1 Apr '03 - 23:41 
    QuestionI failed to download zip file?memberBinary Programmer1 Mar '03 - 0:17 
    AnswerRe: I failed to download zip file?memberBinary Programmer12 May '03 - 23:15 
    AnswerRe: I failed to download zip file?membermadprincehatter3 Sep '03 - 9:17 
    GeneralI think I have the solutionmemberstewe28 Feb '03 - 1:36 
    GeneralRe: I think I have the solutionmemberdmanoharan20 May '03 - 22:26 
    QuestionDownloaded test.zip become empty?memberBinary Programmer21 Feb '03 - 3:25 
    AnswerRe: Downloaded test.zip become empty?memberstewe28 Feb '03 - 1:10 
    GeneralRe: Downloaded test.zip become empty?memberBinary Programmer28 Feb '03 - 22:17 
    GeneralAccess to Excel problemsussAnonymous5 Dec '02 - 0:44 

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

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