Click to See Complete Forum and Search --> : Outputting form data to a file
So how can I take input forma form and put it into a seperate file on my webserver?
Thanks, examples are appreciated.
--Doug
If you're doing it from an ASP you could use the FileSystemObject to write to a file like so:
Dim objFSO
Dim objTS
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
' Open up a file for appending.
Set objTS = objFSO.OpenTextFile("c:\some_path\some_file.txt", 8, True)
objTS.WriteLine "Date: " & Now
objTS.WriteLine Request.Form("form_var_1") & " " & Request.Form("form_var_2")
objTS.WriteLine "" ' Blank line.
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
This is a simple example...I'm about outta here and didn't have time for something elaborate!
Paul
Will this write to the begining or end of file or what? I am acutally trying to figure out how to make a guestbook type of thing, where the new info is written to the beginning of the file, which would actually be an html file.
Mostly the key for me right now is to find out how to add the form info into a certain place in the file. Is this doable?
thanks again
This particular code is set for 'append' mode, which would write to the end of the file. To write to the beginning of a text file you'd have to first read the text file, then tack the original file on to the end of your new text, then rewrite the text file. It's a little trickier - especially if you're guestbook is hit a lot - things could get really ugly if multiple people tried to write at once. You'd probably have to implement some kind of file locking scheme to prevent it.
You might want to try that planet source code website or some other cgi/asp site as this type of guestbook (writing it out as HTML) is fairly common. I haven't written such a guestbook (I'd use a different approach like a db or a structured text file that was formatted by an ASP) and it would be a lot of code.
Good luck,
Paul
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.