Welcome to WebmasterWorld Guest from 54.161.175.236

Forum Moderators: ocean10000

Message Too Old, No Replies

Stupid thing is killing me.. Problem writing to a text file.

ASP writing to text file script

     
4:01 pm on Apr 25, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2005
posts:29
votes: 0


I wonder if anyone else has this problem. When I write like over 700 characters to a text file using ASP script, it replaces the first 10 or so characters with this:

Here is my save.asp script:

[b]

<%

Dim objFSO, objFile, data

data = Request.Form("data")

Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("test.txt", ForWriting)
objFile.Write data
objFile.Close
SET objFSO = NOTHING
SET data = NOTHING
SET objFile = NOTHING

%>

[/b]

and here is my write.asp script:

[b]

<%

Dim objFSO, objFile, data, objReadFile, strContents

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("test.txt")
If objFile.Size > 0 Then
Set objReadFile = objFSO.OpenTextFile("test.txt", 1)
strContents = objReadFile.ReadAll
response.write strContents
objReadFile.Close
Else
response.write "The file is empty."
End If

%>

<FORM ACTION="save.asp" METHOD="POST" TITLE="form">

<TEXTAREA NAME="data" ROWS="10" COLS="50">
</TEXTAREA>
<BR>
<INPUT TYPE="submit" VALUE="Submit">

</FORM>

[/b]

the write.asp shows whats on the page, and has a text area to write and save the new text. Comments or suggestions is greatly apreciated. And if anyone has a script for writing to a text file using .php or perl I would greatly apreciate an idea on how to do that. Thanks.

~Isaac Lloyd~

p.s. the [ code ] thing isn't working so my script is in BOLD.

12:01 pm on May 5, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 24, 2005
posts:965
votes: 0


Try specifying all of the parameters in your openfile method call. Don'y use the defaults.

Try both with ASCII and if you still get the same problem, try with unicode.