Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Weird Add into text when saved.... ( )

ASP save to text file script.

6:39 am on Apr 2, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2005
votes: 0

When I save to a text file using the script below, it works great. However when I save to much text, like over 500 characters it writes the text, but at the begining it writes this:

my saved text etc...

It's weird o things. I didn't know why it does it, it's really weird. Here is my save to text file page (it's more of an Edit Page):

strPathInfo = ("test.txt") ' root path to text file
strPhysicalPath = Server.MapPath(strPathInfo) ' full file path to text file
' load the file
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

'create filesystemobject (FSO)
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.GetFile(strPhysicalPath)
textFile = "" ' this will hold the contents of the text file

'open file with FSO
set objFileTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault)

Do While objFileTextStream.AtEndOfStream <> True
strFileLine = objFileTextStream.Readline
strLine = Server.HTMLEncode(strFileLine)
strLine = Replace(strLine,CHR(9),"&nbsp;&nbsp;&nbsp;&nbsp;")
textFile = textFile & strLine & vbCrLf


<form action="save.asp" method="post">
<textarea name="update_field" cols="70" rows="20" class="field"><%=textFile%></textarea>
<input name="Submit" type="submit" class="button" value="Save & Update">

And here is my save.asp script:

Dim Stuff, myFSO, WriteStuff
'this is what we will write in the file

Stuff = Request.Form("update_field")

'this line creates an instance of the File Scripting Object named myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
'this line opens the file, notice the 2, it will cause the script to write to the file (overwriting existing text)
Set WriteStuff = myFSO.OpenTextFile("test.txt", 2, True)
'this line actually writes STUFF from above to the file
''this line closes the file
'this line destroys the instance of the File Scripting Object named WriteStuff
SET WriteStuff = NOTHING
'this line destroys the instance of the File Scripting Object named myFSO

Any comments/suggestions is greatly apreciated. Thanks for your time.

~Isaac Lloyd~

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