This topic is locked

Save new data to csv file.

10/17/2007 4:38:02 PM
ASPRunnerPro General questions
D
dlangham author

I would like to save new data to a csv file after adding a new record.

If anyone has any code for this using events, that would be great.
Regards

Dale

Sergey Kornilov admin 10/17/2007

Dale,

'Create File System Object

Set Fso = CreateObject("Scripting.FileSystemObject")
'path to folder to be written to

FileName = Server.MapPath("csv.txt")
'create the file to write to

Set txtStream = Fso.OpenTextFile(FileName, 8, True)
txtStream.WriteLine dict("field1") & ", " & dict("field2") & ", " & dict("field3") & ", " & dict("field4")
txtStream.Close
D
dlangham author 10/17/2007

Thank you Sergey,
That is just what I was looking for.

I generate a unique ref number in a field dict("Ref No") and I would like to name the file with this data i.e. 987976556.txt instead of csv.txt

Any ideas?
Regards

Dale

Sergey Kornilov admin 10/17/2007

Dale,
use dict("Ref No") as a file name.

D
dlangham author 10/18/2007

Thank you Sergey,
I will give that a try.

D
dlangham author 10/18/2007

Worked a treat, here is the code I used if anyone else needs it.

'Create File System Object

Set Fso = CreateObject("Scripting.FileSystemObject")
'path to folder to be written to

FileName = Server.MapPath (dict("Ref No")&""&(".csv"))
'create the file to write to

Set txtStream = Fso.OpenTextFile(FileName, 8, True)
txtStream.WriteLine dict("Ref No") & "," & dict("Order No")
txtStream.Close