Print Page | Close Window

How do I write to a text file........

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=1814
Printed Date: 28 March 2026 at 11:06pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: How do I write to a text file........
Posted By: chili
Subject: How do I write to a text file........
Date Posted: 14 April 2003 at 12:45pm

Im trying to write to a text file without deleting the existing text in the file....but when I use this method:

set FSO = Server.CreateObject("scripting.FileSystemObject")
set myFile = fso.CreateTextFile("C:\Inetpub\wwwroot\test.txt", true)
myFile.WriteLine("howdy)
myFile.Close
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set fso = server.CreateObject("Scripting.FileSystemObject")
set f = fso.GetFile("C:\Inetpub\wwwroot\test.txt")
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
     myText = myText & ts.ReadLine

It writes over the text that was in the file before .

So my question is....how do I prevent that from happening and just add text to the existing text that is in the file.

 

Thx in advance

 

 




Replies:
Posted By: MorningZ
Date Posted: 14 April 2003 at 1:15pm
your issue is

set myFile = fso.CreateTextFile("C:\Inetpub\wwwroot\test.txt", true)

yup, thats creating a new text file just like its told to do

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthOpenTextFile.asp - OpenTextFile for appending instead

-------------
Contribute to the working anarchy we fondly call the Internet



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net