- 1). Create an input form using HTML form elements. Add text fields to accept the required information and a submit button to send the input data to your ASP script for writing to your file. Refer to the example below for the correct syntax for a simple form designed to capture name and email address and send the data to a page named SaveToFile.asp.
<form name="MyForm" method="post" action="SaveToFile.asp">
<p><input type="text" name="name"></p>
<p><input type="text" name="email"></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form> - 2). Create the SaveToFile.asp page with a script that accepts the information passed to it from your form and assigns the data to variables. See the example below for the proper ASP syntax for accepting form data. Note the ' indicates a comment follows. Comments are ignored by the server and will be used to offer explanation of the code that follows.
<% ' This indicates the beginning of an ASP script.
' Create the name and email variables.
Dim vName, vEmail
' Assign the form data to each variable.
vName=request.form("name")
vEmail=request.form("email")
' This indicates the end of the ASP script.
%> - 3). Create an instance of the file you want to write to with the ASP FileSystemObject and the TextFile object.
' Create the file variables.
Dim fs, file
' Create an instance of the FileSystemObject.
set fs=Server.CreateObject("Scripting.FileSystemObject")
' Create an instance of the TextFile Object.
set file=fs.CreateTextFile("MyFile.txt",true) - 4). Write the information stored in the vName and vEmail variables to your file and separate the information with a comma.
' Write the variables to the file.
file.write(vName)
file.write(",")
file.write(vEmail) - 5). Close the file object and destroy the FileSystemObject and the TextFile object then end the ASP script.
file.close
set file=nothing
set fs=nothing
%> - 6). Review the entire script to ensure that the syntax is correct and the proper file names are referenced. Save the file and name it SaveToFile.asp, then upload your pages to your server using the file management system provided by your web host.
<%
Dim vName, vEmail
vName=request.form("name")
vEmail=request.form("email")
Dim fs, file
set fs=Server.CreateObject("Scripting.FileSystemObject")
set file=fs.CreateTextFile("MyFile.txt",true)
file.write(vName)
file.write(",")
file.write(vEmail)
file.close
set file=nothing
set fs=nothing
%>
SHARE