Writing to a file "Bad file mode"

D

Doug Parker

Hi -
I need to write to a file. I get the "Bad file mode" error when I run the
script below. I understand that this is a permissions issue. Since I'm
working with a shared server, I apparently can't login and change file
permission settings. I called the tech support for the host I'm working
with, and they couldn't figure it out. I can't believe this is so difficult
since the same operation entails a single chmod command in Unix.

Any help would be greatly appreciated...


<!--#include file="fmtDateTime.asp" -->
<%
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso_OpenTextFile(Server.MapPath("counter.txt"),2)

line=a.readLine
lines=split(line,"|")
fileDate = lines(0)
counter = lines(1)

curDate = fmtDateTime(Now(), "yyyy-mm-dd")
temp = split(curDate,"-")
y = temp(0)
m = temp(1)
d = temp(2)

if curDate = fileDate then
counter = counter + 1
newDate = fileDate
else
counter = 1
newDate = curDate
end if



Set a = Nothing
Set fso = Nothing
%>
 
E

Evertjan.

Doug Parker wrote on 19 apr 2004 in
microsoft.public.inetserver.asp.general:
I need to write to a file. I get the "Bad file mode" error when I run
the script below.
Set fso = CreateObject("Scripting.FileSystemObject")
Set a = fso_OpenTextFile(Server.MapPath("counter.txt"),2)

line=a.readLine

Wrong parameter:

Use the OpenTextFile method to open the text file. The OpenTextFile
method requires two parameters: the path to the file and one of the
following values:

• For reading (parameter value = 1, constant = ForReading). Files opened
in this mode can only be read from. To write to the file, you must open
it a second time by using either the ForWriting or ForAppending mode.

• For writing (parameter value 2, constant = ForWriting). Files opened in
this mode will have new data replace any existing data. (That is,
existing data will be deleted and the new data added.) Use this method to
replace an existing file with a new set of data.

• For appending (parameter value 8, constant = ForAppending). Files
opened in this mode will have new data appended to the end of the file.
Use this method to add data to an existing file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top