Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Writing to a file "Bad file mode"

Reply
Thread Tools

Writing to a file "Bad file mode"

 
 
Doug Parker
Guest
Posts: n/a
 
      04-19-2004
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
%>


------------------------------------------------------------
http://www.phreshdesign.com


 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      04-19-2004
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.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Question: Writing text file based TestBenches vs. Waveform file based simulation. BLF VHDL 4 08-07-2004 12:44 AM
File Access error - writing to .txt file John Carnahan ASP .Net 2 07-18-2003 10:35 PM
A failure occurred writing to the resources file. Access is denied. -- RESX file is locked? -- WHY? Mark Kamoski ASP .Net 1 07-04-2003 12:02 PM



Advertisments