Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    27
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question I can't open file using "ADODB.Stream"

    Hi all! I can’t open hex file using this:

    Js file
    Code:
    function GetFile(file_name) 
    {
     var Content=null;
     var Stream; 
     try 
      {         
    	  Stream = new ActiveXObject("ADODB.Stream") 
    		Stream.Type = 16 //Hex         
    		Stream.Open()         
    		Stream.LoadFromFile(file_name)         
    		Content = Stream.Read()         
    		FileSize = Stream.Size         
    		Stream.Close()         
    		return Content;     
    	}
    	 catch(e) 
    	  {         
    		  alert(e.name + ': ' + e.message); 
    		}
    }

    HTML file:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>District</title>
        <link rel="stylesheet" href="estilos.css" type="text/css" media="all">
        <style type="text/css"></style>
    
    <script type="text/javascript" src=js/main_url_fails.js></script>
    <script type="text/javascript"></script>
    </head>
    <body>
    <script>
    
    map_string=GetFile("maps/Temp.dat")
    
    </script>
    
    </body>
    
    </html>

    Error missage is: “Server’s Automatization can not create the object”

    Can anyone help me, please?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,092
    Thanks
    23
    Thanked 594 Times in 593 Posts
    ADO is a programming interface to access data in a database. That means it is a server side language. It is used in an ASP file.

    Javascript is a client side language that works in a browser. It can not work server side nor can it read a database.

    You can not run ADODB in a js file. You need ASP.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    967
    Thanks
    19
    Thanked 211 Times in 209 Posts
    sorry
    Last edited by DaveyErwin; 09-17-2012 at 06:37 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Actually, you *CAN* run ADODB.Stream in JavaScript in the browser.

    Provided:
    (a) The browser is MSIE.
    (b) The site the JavaScript comes from is marked as a Trusted Site
    (c) The browser user says "OK" when asked if he/she wants to allow an unsafe ActiveX control in the browser.

    All of which combines to mean that this is only a practical solution in an inTRAnet, typically an in-house system where all users are required to use MSIE and required to set browser permissions to allow all this.

    Having said all that...

    The code posted still won't work, because these 2 lines
    Code:
    		Stream.LoadFromFile(file_name)  
    ...
    map_string=GetFile("maps/Temp.dat")
    mean that you are trying to load the file "Temp.dat" from the directory "c:\windows\system32\maps" *ON THE USER'S MACHINE*. Which is surely not at all what you intended to do.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Drunklord (09-18-2012)

  • #5
    New Coder
    Join Date
    Sep 2011
    Posts
    27
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Is there any way to load a hex file then? I looked for it everywhere and can’t find the resolution.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    I give up. What is a "hex file"?

    Are you a witch who wants to put a curse on someone? <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Ahhh...went back to your first post...you mean a binary file. That is, a non-text file.

    Sure, you can load it with HTTP GET using AJAX, for example. But what will you do with it once it is loaded?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •