This browser does not support basic Web standards, preventing the display of our site's intended design. May we suggest that you upgrade your browser?

Web Development Code Library ASPFile System Object - Write

File System Object - Write

Use the File System Object to write to a text file on your server. This version allows you to append data to the file and will create the file if it does not exist

<!--Document Name="formhandler.asp" -->

<html>
  <body>

     <form action="formhandler.asp" method="post">
          <input type="text" size="10" name="username">
          <input type="text" size="10" name="homepage">
          <input type="text" size="10" name="Email">
     </form>

  </body>
</html>

<%

'Put error checking here to make sure they submitted something to the page
'Also check to see if they have hit the reload button (hint: use session
'variables)

' Get form info

strName = Request.Form("username")
strHomePage = Request.Form("homepage")
strEmail = Request.Form("Email")

' create the fso object

Set fso = Server.CreateObject("Scripting.FileSystemObject")

path = "c:\temp\test.txt"

ForReading = 1
ForWriting = 2
ForAppending = 8

' open the file

set file = fso.opentextfile(path, ForAppending, TRUE)

' write the info to the file

file.write(strName) & vbcrlf
file.write(strHomePage) & vbcrlf
file.write(strEmail) & vbcrlf
' close and clean up

file.close

set file = nothing
set fso = nothing

%>
Excellence. Our Measure. Our Motto. Our Goal.