?
Solved

OpenTextFile gets 'Object doesn't support this property or method'

Posted on 2005-04-06
27
Medium Priority
?
2,771 Views
Last Modified: 2011-10-03
Famous last words 'It was working before and I didn't change a thing!'  Well, I musta.

This script had been functioning for a year.  It still functions on the remote server but is failing on my desktop running IIS locally.

//=============================
    if (state != Session("LastState")){
      var dir = Server.MapPath(".") + "\\";
   
      var fs=Server.CreateObject("Scripting.FileSystemObject");
      try {
        var fd=fs.GetFile(dir+"ibaMenu" + OwnerID + ".js");  <---------------- A
        fd.Delete();
        fd.Close;
      }
      catch(err){}
   
      var fr=fs.OpenTextFile(dir+"ibamenu_staticBlock1.js",1,false);  <------------------- B
      var x=fr.ReadAll();
      var fw=fs.CreateTextFile(dir+"ibaMenu" + OwnerID + ".js");
      fw.Write(x);
      fr.Close();
//=============================

The script fails at both point A and B with "Object doesn't support this property or method" number (0x800A01B6).  It falls through point A to point B because of the try block, otherwise it'd just fail there without going on to point B.  (dir+"ibaMenu" + OwnerID + ".js") evaulates correctly.  The file does exist and therefore should have been deleted at point A.

Norton Firewall has been disabled.  It makes no difference if Norton Antivirus autoprotect is enabled or disabled but the script blocking feature is off.

How do I get it working again?
0
Comment
Question by:Bob3975
  • 14
  • 7
  • 2
  • +2
25 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 13723801
which Line does it referers to?

maybe it should be

fw.WriteLine(x);
0
 
LVL 15

Expert Comment

by:deighc
ID: 13724978
Are you sure your file path is correct?

After you map the base path (using Server.Mappath) you append "\\". Why?

This will give you a path like:

D:\inetpub\wwwroot\myfolder\\

Which would give a full file path like:

D:\inetpub\wwwroot\myfolder\\myfile.js

That doesn't look like a valid path to me.
0
 
LVL 8

Expert Comment

by:anthonywjones66
ID: 13725032
Deigh,c

The "\\" is an escape for "\"  your looking at JavaScript here. :)

Bob3975,

What OS and SP level are you running on your local machine?

It looks like the CreateObject method isn't giving you the object you are expecting.

Have tried running a local js file like:-

var o = new ActiveXObject("Scripting.FileSystemObject")
var fd = o.GetFile("C:\Temp\Test.txt")
alert(fd.name)

Does this work ok?

Anthony.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:deighc
ID: 13725084
> The "\\" is an escape for "\"  your looking at JavaScript here. :)

Oh, yeah. Ooops :-)

OK, next suggestion: take out your try..catch block altogether (just for testing purposes) and see what error is thrown on the offending lines.

As you know the FSO most certainly does support the GetFile and OpenTextFile methods so this your current error message is misleading.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13726735
if none of these help check if your Anti Virus software is blocking  a script execution
0
 

Author Comment

by:Bob3975
ID: 13728010
I modified Anthony's suggested code to be ...

var o = new ActiveXObject("Scripting.FileSystemObject")
var fd = o.GetFile("C:\\Temp\\invoke.txt")
alert(fd.name)

in front of my code and it still fails with
Microsoft JScript runtime (0x800A01B6)
Object doesn't support this property or method.  

C:\Temp\invoke.txt is a file on my system.

Taking the catch out fails in the same way.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13728351
are you doing this serverside or clientside..?
0
 

Author Comment

by:Bob3975
ID: 13728426
serverside
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13728997
there's no alert(fd.name) on serverside
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13729002
does it work in ASP?
0
 

Author Comment

by:Bob3975
ID: 13729488
In Anthony's code, it fails (stops) on the GetFile.  You're correct about the alert not being valid, I track it in the debugger.  Referring to the topmost post, point A falls through because of the try/catch but the trapped exception says "Object doesn't support this property or method".  Point B stops with the same error.

"Does it work in ASP", this is ASP written with javascript.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13729644
I understand this is asp page, but all I'm trying to say is this

<%
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile("c:\test.txt")
Response.Write(f1.DateLastModified)
%>
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13729650
I mean

Set fso = Server.CreateObject("Scripting.FileSystemObject")
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13729711
not sure but try this anyway, declare variable first and then assign it to the object like so

var fso, fd;
fso = new ActiveXObject("Scripting.FileSystemObject");
fd = o.GetFile("C:\\Temp\\invoke.txt")
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13729765

or

var fso, ob;
fso = new ActiveXObject("Scripting.FileSystemObject");

foreach(ob in fso){
     Response.Write(ob.toString() + "<br>");
}
   

0
 

Author Comment

by:Bob3975
ID: 13729945
var fso, ob;
fso = new ActiveXObject("Scripting.FileSystemObject");

for (ob in fso){
     Response.Write(ob.toString() + "<br>");

That lists no (0) properties
//==========================
I tried a seperate vb asp page with...

<%
Dim fso, f1
Set fso = server.CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile("c:\test.txt")
Response.Write(f1.DateLastModified)
%>

and got...
Microsoft VBScript runtime (0x800A01B6)
Object doesn't support this property or method: 'GetFile'
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730023
what OS and IIS do you have on home computer..?
0
 

Author Comment

by:Bob3975
ID: 13730045
MS XP sp1 / IIS 5.1
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730074
do you have any anti virus software..?
0
 

Author Comment

by:Bob3975
ID: 13730165
yes, Norton, but scripting is off and it fails with autoprotect on or off...Norton firewall has been disabled.
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730173
if you have AV software then check if it's blocking script execution, if this doesn't help than you have to reinstall "scrrun.dll", it can be found here

http://www.dll-files.com/dllindex/dll-files.shtml?scrrun

this is the DLL which contains FileSystemObject class and might be corrupted or maybe registry is screwed up... who knows, but I still believe that it's anti virus script blocking mechanism
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730192
you were 1 minite ahead of me, so proceed with reinstalling the DLL
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13730204
it comes with readme.txt file, I suggest reading it first
0
 

Accepted Solution

by:
Bob3975 earned 0 total points
ID: 13731339
I tried installing scrrun.dll but it still failed.

I installed sp2 and the problem is now corrected.  
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 13731464
that would have been the last thing on my mind... :) good luck!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question