Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2012, 11:03 AM   PM User | #1
Drunklord
New Coder

 
Join Date: Sep 2011
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
Drunklord is an unknown quantity at this point
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?
Drunklord is offline   Reply With Quote
Old 09-17-2012, 04:11 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
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.
sunfighter is offline   Reply With Quote
Old 09-17-2012, 06:30 PM   PM User | #3
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 814
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
sorry

Last edited by DaveyErwin; 09-17-2012 at 06:37 PM..
DaveyErwin is offline   Reply With Quote
Old 09-17-2012, 08:32 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
Drunklord (09-18-2012)
Old 09-18-2012, 12:53 PM   PM User | #5
Drunklord
New Coder

 
Join Date: Sep 2011
Posts: 27
Thanks: 8
Thanked 0 Times in 0 Posts
Drunklord is an unknown quantity at this point
Is there any way to load a hex file then? I looked for it everywhere and can’t find the resolution.
Drunklord is offline   Reply With Quote
Old 09-18-2012, 11:35 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-18-2012, 11:36 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:09 AM.


Advertisement
Log in to turn off these ads.