homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

Weird Add into text when saved.... ( )
ASP save to text file script.

10+ Year Member

Msg#: 2618 posted 6:39 am on Apr 2, 2005 (gmt 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


Global Options:
 top home search open messages active posts  

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved