Click here to Skip to main content
6,634,665 members and growing! (20,710 online)
Email Password   helpLost your password?
Web Development » ASP » Components     Intermediate

File downloading with COM and ASP

By xicoloko, Curt Robinson

A COM object you can use to transfer files in ASP
VC6Win2K, ASP, IIS, Dev
Posted:5 Sep 2000
Views:206,924
Bookmarked:43 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
32 votes for this article.
Popularity: 6.33 Rating: 4.21 out of 5
2 votes, 20.0%
1

2

3
1 vote, 10.0%
4
7 votes, 70.0%
5
  • 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


    Member
    XicoLoko is a brazilian developer based in Switzerland.

    Occupation: Architect
    Company: VisionOne AG
    Location: Switzerland Switzerland

    Curt Robinson


    Member

    Location: United States United States

    Other popular ASP articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 25 of 58 (Total in Forum: 58) (Refresh)FirstPrevNext
    GeneralMy vote of 1 Pinmemberkraftspl12:19 11 Jan '09  
    GeneralIE 6 can't download a zip file PinmemberPiyushVarma9:49 18 Nov '08  
    Questiondownloading music file using ASP Pinmembersnigdhajayan21:35 25 Jun '08  
    Generaldownloading music file using ASP Pinmembersnigdhajayan21:33 25 Jun '08  
    Generaldown loading Pinmembermnalammwb5:23 14 Mar '08  
    Generalerror - cannot create activexcontrol PinmemberPriya B21:11 21 Oct '07  
    GeneralI can't download PinmemberChanda_khanapure0:56 1 Feb '06  
    Generalmultiple downloads Pinmembermoorprab20:57 7 Oct '05  
    Questionhow to view word files Pinmembermitesh22220:48 28 Sep '05  
    Generaldisplay vc++ output string on a browser using asp Pinmemberrockyn31922:58 2 May '05  
    Generalhow 2 get download pop up window? Pinmembersmrits21:15 6 Apr '05  
    GeneralMIME setting in IIS 5.0 Pinmembernia_put10:02 7 Sep '04  
    GeneralDownload image field from SQL-Server PinmemberZoink1:34 15 Jul '04  
    GeneralHelp me please~~ Pinmembercharcoalc1:54 5 May '04  
    GeneralError: Response object, ASP 0106 (0x80020005) Pinmemberravda10:23 21 Aug '03  
    GeneralFile transfer object Pinmemberpjaka0:41 2 Apr '03  
    GeneralI failed to download zip file? PinmemberBinary Programmer1:17 1 Mar '03  
    GeneralRe: I failed to download zip file? PinmemberBinary Programmer0:15 13 May '03  
    GeneralRe: I failed to download zip file? Pinmembermadprincehatter10:17 3 Sep '03  
    GeneralI think I have the solution Pinmemberstewe2:36 28 Feb '03  
    GeneralRe: I think I have the solution Pinmemberdmanoharan23:26 20 May '03  
    GeneralDownloaded test.zip become empty? PinmemberBinary Programmer4:25 21 Feb '03  
    GeneralRe: Downloaded test.zip become empty? Pinmemberstewe2:10 28 Feb '03  
    GeneralRe: Downloaded test.zip become empty? PinmemberBinary Programmer23:17 28 Feb '03  
    GeneralAccess to Excel problem PinsussAnonymous1:44 5 Dec '02  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 5 Sep 2000
    Editor: Chris Maunder
    Copyright 2000 by xicoloko, Curt Robinson
    Everything else Copyright © CodeProject, 1999-2009
    Web22 | Advertise on the Code Project