Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with the FileSystemObject/TextStream Object

Status
Not open for further replies.

sizeof

Programmer
Jul 11, 2001
4
IL
Hi all.

I'm trying to read a text file that exists on the drive using the FileSystemObject object. For some reason, the ASP engine freezes when I call the OpenTextFile method.

I can create a new FileSystemObject object; However, in the next line, where an OpenTextFile method is implemented, it gets stuck. It doesn't matter if I specify a file by its full path or use Server.MapPath.

Why does it happen? Does it have anything to do with permissions? Also, I have an updated VB Scripting Engine (5.5). I even downloaded it and installed once again – and it doesn't seem to help my problem - still stuck when doing OpenTextFile calls.

I'm running Windows 2000 Server, and IE 5.5 is installed on the server.

By the way, when I use the FileSystemObject object for other tasks, such as checking for file existence (fs.FileExists()), it works fine.

Thanks in advance for your help.
 
Have you tried opening different files? Maybe it's an issue with one aprticular file rather than the methods that open it... Just a thought
 
Yes, I have tried. It failes in EVERY OpenTextFile method call.

Very weird, especially when other methods and usages of the FileSystemObject work just fine.

Any suggestions?
 
COuld you check the NT permissions on the directory the file is in and post them? I'm not interested in your network users, just the IIS created accounts.

G -GTM Solutions, Home of USITE-
-=
 
I'm also having the same kind of problem, but I can't even write a file.
I'm using the code:

Code to write:
======================================================
<%
Option Explicit
Response.Expires = -1
Dim FileObject, CounterFile, InPut , OutPut, NewCount, OldCount
Set FileObject = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
CounterFile = Server.MapPath (&quot;counterHOME.txt&quot;)
Set InPut = FileObject.OpenTextFile (CounterFile, 1, False)
OldCount = Trim(InPut.ReadLine)
NewCount = OldCount + 1
Set OutPut = FileObject.CreateTextFile (CounterFile, True)
OutPut.WriteLine(NewCount)
InPut.Close
OutPut.Close
Set FileObject = Nothing
Set InPut = Nothing
Set OutPut = Nothing
%>

Code to read:
======================================================
<%
Option Explicit
Response.Expires = -1
Dim FileObject, CounterFile, InPut, OldCount
Set FileObject = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
CounterFile = Server.MapPath (&quot;counterHOME.txt&quot;)
Set InPut = FileObject.OpenTextFile (CounterFile, 1, False)
OldCount = Trim(InPut.ReadLine)
InPut.Close
Set FileObject = Nothing
Set InPut = Nothing
%>

Whenever any of the files are called it just does nothing.

What could be the problem?

Thank you.


NightWatcher
 
Set InPut = FileObject.OpenTextFile (CounterFile, 1, False)

object.OpenTextFile(filename[, iomode[, create[, format]]])

That &quot;1&quot; opens the file ForReading, not Writing.
Constant Value Description
ForReading 1 Open a file for reading only. You can't write to this file.
ForAppending 8 Open a file and write to the end of the file.

Use
object.CreateTextFile(filename,true) ' Overwrite
 
Thanks, but where and what should I change that?
Is it the red line?

Code to write:
======================================================
<%
Option Explicit
Response.Expires = -1
Dim FileObject, CounterFile, InPut , OutPut, NewCount, OldCount
Set FileObject = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
CounterFile = Server.MapPath (&quot;counterHOME.txt&quot;)
Set InPut = FileObject.OpenTextFile (CounterFile, 1, False)
OldCount = Trim(InPut.ReadLine)
NewCount = OldCount + 1
Set OutPut = FileObject.CreateTextFile (CounterFile, True)
OutPut.WriteLine(NewCount)
InPut.Close
OutPut.Close
Set FileObject = Nothing
Set InPut = Nothing
Set OutPut = Nothing
%>

And the code to read is OK?

Thank you.


NightWatcher
 
Nerver mind, I must be blind BUT the following line probably should not have parens since you are not executing a function.
OutPut.WriteLine(NewCount)
Use
OutPut.WriteLine NewCount
Also I think youn should CLOSE the InPut before creating OutPut for the same file.

Code:
Set InPut = FileObject.OpenTextFile (CounterFile, 1, False)
OldCount = Trim(InPut.ReadLine)
NewCount = OldCount + 1
InPut.Close ' Put CLOSE here

Set OutPut = FileObject.CreateTextFile (CounterFile, True)
OutPut.WriteLine NewCount ' NO PARENS
OutPut.Close
 
How do I access the Last date Modified property of a file?

Here's part of my code
<%
dim fs
set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
if fs.FileExists(&quot;C:\Billing.txt&quot;) then

Response.Write(&quot;File found!&quot;)
'I Don't know what code to put in here. to access the ' date 'modified propoerty

else

Response.Write(&quot;File not found!&quot;)

end if


%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top