Forum Moderators: open

Message Too Old, No Replies

Problem with Scripting.FileSystemObject

Output bing written twice?

         

sreejanair

3:40 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



Hi everyone,

I want to write certain data from an HTML form into a text file using ASP.

It is writing into the file but...sometimes once, twice, thrice. Any idea why this unusual behavior. I have been trying to figure this out!

Here is my code:

<%
'Hier der Block für die Automatisierung
'**************************************
Dim TextFile, Header
dim vorname, nachname, personalnummer, netid, datum

TextFile = Server.MapPath ("../Test") & "\daten.txt"

vorname = request.form("vorname")
nachname = request.form("nachname")
personalnummer = request.form("personalnummer")
netid = request.form("netid")

Tag = Day(date)
Monat=Month(date)
Jahr=Year(date)

datum=Tag & "." & Monat & "." & Jahr

text = ""
text = datum & ";" & vorname & ";" & nachname & ";" & personalnummer & ";" & netid & ";"

Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
Set OutStream = FileObject.OpenTextFile (TextFile, 8,true)

OutputString = text
OutStream.WriteLine OutputString

OutStream.Close
Set OutStream = Nothing
Set FileObject = Nothing

%>

Easy_Coder

7:00 pm on Nov 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you sure it's not just 'appending' to your last post? Your passing in 8 which maps to the ForAppending constant.

sreejanair

9:12 am on Nov 7, 2005 (gmt 0)

10+ Year Member



hello,

I did not quite get ur question.

You are right i have to append the data to the file ...if the file already exists when there is a new entry, else the code creates a new file and writes into it.

That is why i have used 8.

Now what exactly is the problem? I would be grateful if u could help me solve thos problem. The data is repeating and it makes no sense to have the same data many times.

Easy_Coder

2:23 pm on Nov 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it's set for appending then it will repeat...

Post 1
Add This To File

Post 2
Add This To File

Post 3
Add This To File

Should result in
Add This To File
Add This To File
Add This To File

Is that what you're seeing?