Solved

Can I read data from a text file using vbscript in a html file?

Posted on 2008-09-30
7
950 Views
Last Modified: 2012-05-05
I have done a lot of windows apps programs and vbscript files, but not web apps, hence my confusion.  Can I read a text file using the filesystemobject in a vbscript in an html file?  I just need to read some data from the text file.  I don't want to use a database and a table if I can read the data in a text file.  

the html file runs fine on my pc but I get the error when I move the html to the server and try to run it in a browser on my pc.

Here is my html
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
Start <br>

<SCRIPT LANGUAGE="VBSCRIPT" runat="server">
on error resume next
dim fso
set fso = CreateObject("Scripting.FileSystemObject")      '''error occurs here
msgbox "fso error - " & err.description
</script>

End <br>
</BODY>
</HTML>
-------------------
the msbox displays "fso error - Activex component can't create object".

I can move the script to a.vbs file and run in on the server without the error.  It can create the filesystemobject in a vbs script file on the server,  but the script in the html file gets an error trying to create the filesystemobject on the server.

This seems like a simple thing to do but I'm just getting started with web apps and not sure what works or doesn't.  Can I do what I want???

Thanks





0
Comment
Question by:utahalee
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22612142
Try changing this line:
set fso = CreateObject("Scripting.FileSystemObject")

to this
Set fso = Server.CreateObject("Scripting.FileSystemObject")

Regards,

Rob.
0
 

Author Comment

by:utahalee
ID: 22613954
Thanks for the answering the question.
I now get an "object required" error instead of the "Activex component can't create object" error.
Any other suggestions?  



0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22619325
Which line gives you that error? There is no other line in the above code that uses that fso object.

You might have something like:

<SCRIPT LANGUAGE="VBSCRIPT" runat="server">
on error resume next
dim fso
set fso = CreateObject("Scripting.FileSystemObject")
Set objFile = fso.CreateTextFile("NewFile.txt", True)
objFile.Write "Something"
objFile.Close
</script>


note that because you have used
Set FSO = CreateObject("Scripting.FileSystemObject")

you must call the methods of the filesystemobject using the FSO object name, such as
fso.CreateTextFile

If you were to try
fso2.CreateTextFile

you'd get "Object Required"

Regards,

Rob.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:utahalee
ID: 22624809
I changed my line to Set fso = Server.CreateObject("Scripting.FileSystemObject") as you suggested.

I get the "Object Required"  error on that line now instead of the Activex component can't create object that I got before I added "Server." to the createobject.

I can't use error the FileSystemObject methods becasue of the error I get when I try to create the FSO object.

The script works fine outside of the html.  Should I be able to use the FileSystemObject in vbscript in an html file to check if a  text file exists on the server?  If it exists I would use the filesystemobject to read the  textfile and format in a table on the web page.  I haven't done much with scripts in web pages so I hope this can work.

Thanks for all your help so far.

0
 
LVL 65

Accepted Solution

by:
RobSampson earned 100 total points
ID: 22628655
Hmmm, yes that should work:
http://www.eggheadcafe.com/articles/20030627b.asp

I'm really not sure.  You do need to be running the page on a Windows server though, but I'm not sure if other operating systems support it....I think you can get VBScript for Unix, but I can't remember.

Regards,

Rob.
0
 

Author Closing Comment

by:utahalee
ID: 31501546
Thanks for your help and verifying that what I want to do should work.  I am running on a windows server.  Further investigation of the error message is leading me down the path that the problem is with the server and something needs to be changed or fixed on it.  Thanks.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 22639269
No problem. Thanks for the grade.

Perhaps you need to look into re-installing or repairing the VBScript engine...

Regards,

Rob.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now