Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    writing to a file

    hi. iam new to the whole asp thing. i want to make a way of writing to a text file. here is the input:

    Code:
    <html>
    <head>
    <title>text epriment input</title>
    
    <body>
    <form name="form" method="get" action="text.asp">
      <input type="text" name="textfield">
      <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>
    and the proccessing bit:
    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <html>
    <head>
    <title>test experiments output</title>
    </head>
    <body>
    <%
    input = request.QueryString("textfield")
    
    set fs = Server.CreateObject("Scripting.FileSystemObject")
    set f = fs.OpenTextFile(Server.MapPath("text.txt"),true)
    f.Write(input) 
    response.Write(f.ReadAll)
    f.close
    
    f = nothing
    fs = nothing
    
    %>
    
    </body>
    </html>
    aparently iam using the wrong file mode, but iam using the overwrite mde, ie 1. why doesnt it work?

    thnx for replies.

    PS iam using asp not asp.net!
    Last edited by spetsnaz; 07-05-2004 at 10:51 AM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    You have to specify an io-mode for the filehandle, this would be the second argument for the method

    See here for info about OpenTextFile method
    I am the luckiest man in the world

  • #3
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thnx for the speedy reply, what was 8 (constant for appending) from:

    set f = fs.OpenTextFile(Server.MapPath("text.txt"),true)

    it should have been:

    set f = fs.OpenTextFile(Server.MapPath("text.txt"),8,true)

    i have a follow on question from the above. i will post it tommorow...

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    478
    Thanks
    0
    Thanked 2 Times in 2 Posts
    And in the meantime here's a good FSO resource:

    FileSystemObject
    http://www.4guysfromrolla.com/webtec...leSystemObject
    5-part FAQ
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

  • #5
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok. what i have is this menu screen:
    <body>
    menu<br>
    <a href="textregistration.htm">register</a><br>
    <a href="textlogin.htm">log in</a><br>
    </body>
    the textregistration.htm is this:
    <body>
    registration<br>
    <form name="form" method="get" action="textinput.asp">
    <input type="text" name="textfield">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    the textlogin.htm is this:
    log in<br>
    <form name="form" method="get" action="textoutput.asp">
    <input type="text" name="textfield">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    the textinput.asp:
    <body>
    <%
    dim fs,f,input
    input = request.QueryString("textfield")

    set fs = Server.CreateObject("Scripting.FileSystemObject")
    set f = fs.OpenTextFile(Server.MapPath("text.txt"),8,true,-2)
    f.WriteLine(input)
    f.close

    set f = nothing
    set fs = nothing

    %>
    return to <a href="menu.htm">menu</a>
    </body>
    and the thing which is causing the problem, the textoutput.asp:
    <body>
    <%

    lines = 1
    ''''''''''''''''''''''''''''''''''''''''''''''''''set up all variables
    input = request.QueryString("textfield")
    set fs = Server.CreateObject("Scripting.FileSystemObject")
    set f = fs.OpenTextFile(Server.MapPath("text.txt"),1,true,-2)

    ''''''''''''''''''''''''''''''''''''''''''''''''''output contents for manual check
    Response.Write(f.ReadAll)

    ''''''''''''''''''''''''''''''''''''''''''''''''''count the number of files
    do while f.AtEndOfStream = false
    lines = lines + 1
    loop

    ''''''''''''''''''''''''''''''''''''''''''''''''''check for username
    for x=1 to lines
    if f.Read(x) = input then
    a = true
    else
    a = false
    next x

    ''''''''''''''''''''''''''''''''''''''''''''''''''infor user of his/her registration statues
    if a = true then
    Response.Write("your are registered")

    else
    Response.Write("you are not registered")

    ''''''''''''''''''''''''''''''''''''''''''''''''''prevent memory leaks
    f.close
    set f = nothing
    set fs = nothing
    %>
    </body>
    aparently "next is unexpected". iam not sure why it doesnt work. it should work. does anyone have any idea? iqm sorry if this ammount of code is a bit overkill but its just iam not sure what exactly is wrong, plz help!
    Last edited by spetsnaz; 07-07-2004 at 08:31 AM.

  • #6
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    the best FSO reference imo is at http://www.sloppycode.net/fso/ (apart from a few bugs like calling it fso then fsobject in the next line.. but the comments usually point these out

    usually probles with fso are related to permissions or script blocking form things such as norton av (this looks like its just hanging so no error etc would have shown up)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •