Results 1 to 4 of 4

Thread: Outputting form data to a file

  1. #1
    Guest

    Question

    So how can I take input forma form and put it into a seperate file on my webserver?

    Thanks, examples are appreciated.

    --Doug

  2. #2
    Guest
    If you're doing it from an ASP you could use the FileSystemObject to write to a file like so:

    Code:
      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

  3. #3
    Guest
    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

  4. #4
    Guest
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width