Writing to a file "Bad file mode"

Discussion in 'ASP General' started by Doug Parker, Apr 19, 2004.

  1. Doug Parker

    Doug Parker Guest

    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
    Doug Parker, Apr 19, 2004
    #1
    1. Advertising

  2. Doug Parker

    Evertjan. Guest

    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)
    Evertjan., Apr 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Kamoski
    Replies:
    1
    Views:
    2,440
  2. BLF
    Replies:
    4
    Views:
    1,264
    Mike Treseler
    Aug 7, 2004
  3. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    786
    John Carnahan
    Jul 18, 2003
  4. JuneCleaver

    Writing to a log file with in an aspx file.

    JuneCleaver, Apr 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,038
    Juan Romero
    Apr 8, 2004
  5. HNguyen
    Replies:
    4
    Views:
    2,383
    HNguyen
    Dec 21, 2004
Loading...

Share This Page