VBScript FSO: CreateFile OK, OpenTextFile fails

Discussion in 'ASP General' started by Paul, Mar 15, 2006.

  1. Paul

    Paul Guest

    In one place in my project, I need to create a text file. Each time it runs
    it should overwrite the previous version. I use the following code and it
    works fine:

    FileLoc = server.MapPath("list.txt")
    Set fsTemp = server.CreateObject("Scripting.FileSystemObject")
    Set RecordsFile = fsTemp.CreateTextFile(FileLoc,true)
    RecordsFile.WriteLine(RecCache)
    RecordsFile.Close

    In another page in the same project, I need to create a logfile of certain
    transactions, so each time it needs to append to the end of the file. This
    code results in an error 5.

    FileLoc = server.MapPath("DBLog.txt")
    Set fsTemp = server.CreateObject("Scripting.FileSystemObject")
    Set RecordsFile = fsTemp.OpenTextFile(FileLoc, ForAppending, True)
    RecordsFile.WriteLine(strSQL)
    RecordsFile.Close

    Can you point out what I am doing wrong?

    Thanks.
    Paul
    Paul, Mar 15, 2006
    #1
    1. Advertising

  2. Paul

    Bob Lehmann Guest

    What's error 5?

    Bob Lehmann

    "Paul" <> wrote in message
    news:%237J1%...
    > In one place in my project, I need to create a text file. Each time it

    runs
    > it should overwrite the previous version. I use the following code and it
    > works fine:
    >
    > FileLoc = server.MapPath("list.txt")
    > Set fsTemp = server.CreateObject("Scripting.FileSystemObject")
    > Set RecordsFile = fsTemp.CreateTextFile(FileLoc,true)
    > RecordsFile.WriteLine(RecCache)
    > RecordsFile.Close
    >
    > In another page in the same project, I need to create a logfile of certain
    > transactions, so each time it needs to append to the end of the file. This
    > code results in an error 5.
    >
    > FileLoc = server.MapPath("DBLog.txt")
    > Set fsTemp = server.CreateObject("Scripting.FileSystemObject")
    > Set RecordsFile = fsTemp.OpenTextFile(FileLoc, ForAppending, True)
    > RecordsFile.WriteLine(strSQL)
    > RecordsFile.Close
    >
    > Can you point out what I am doing wrong?
    >
    > Thanks.
    > Paul
    >
    >
    >
    >
    >
    >
    Bob Lehmann, Mar 16, 2006
    #2
    1. Advertising

  3. "Bob Lehmann" <> wrote in message
    news:...
    > What's error 5?


    Access Denied...
    Egbert Nierop \(MVP for IIS\), Mar 16, 2006
    #3
  4. "Egbert Nierop (MVP for IIS)" <> wrote in
    message news:...
    >
    > "Bob Lehmann" <> wrote in message
    > news:...
    > > What's error 5?

    >
    > Access Denied...
    >


    Access Denied... On Facility 7 (Windows API)

    OR

    Invalid Procedure call... On Facility 4 where the interface implementor is
    VB

    OR

    Anything else you care to think of... On Facility 4 where the interface is
    A.N Other object

    :)

    My bets on Invalid Procedure Call.

    It would be nice not to have to guess, Paul?

    Anthony.
    Anthony Jones, Mar 16, 2006
    #4
  5. Paul

    Paul Guest

    Sorry, I thought VBScript had a consistent error set.

    It returns Error 5-Invalid procedure call or argument

    The error occurs on the line "Set RecordsFile = fsTemp.OpenTextFile(FileLoc,
    ForAppending, True)"
    Paul, Mar 16, 2006
    #5
  6. Paul wrote:
    > Sorry, I thought VBScript had a consistent error set.
    >
    > It returns Error 5-Invalid procedure call or argument
    >
    > The error occurs on the line "Set RecordsFile =
    > fsTemp.OpenTextFile(FileLoc, ForAppending, True)"


    It looks like you've failed to define the ForAppending constant. Add this
    line:
    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Mar 16, 2006
    #6
  7. Paul

    Paul Guest

    Bob,

    That was it. Works now. Thank you!!

    Paul

    > It looks like you've failed to define the ForAppending constant. Add this
    > line:
    > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >
    Paul, Mar 17, 2006
    #7
    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. Sean Liong via .NET 247

    CreateFile - Read/Write client's Stroage

    Sean Liong via .NET 247, Jun 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    523
    bradley
    Jun 9, 2005
  2. MIUSS
    Replies:
    6
    Views:
    824
    John Harrison
    Feb 28, 2007
  3. Udo Hoerhold

    CreateFile in unmanaged code fails

    Udo Hoerhold, Jun 14, 2006, in forum: ASP .Net Security
    Replies:
    0
    Views:
    221
    Udo Hoerhold
    Jun 14, 2006
  4. JT

    OpenTextFile and logging

    JT, Dec 23, 2003, in forum: ASP General
    Replies:
    4
    Views:
    169
  5. jwallison

    OpenTextFile just hangs

    jwallison, Feb 26, 2004, in forum: ASP General
    Replies:
    2
    Views:
    178
    jwallison
    Feb 26, 2004
Loading...

Share This Page