Technology Programming

How to Write to a File in ASP From a Form

    • 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
RELATED POSTS on "Technology"
Blitzerwarner: Could You Escape the Speed Cameras?
Blitzerwarner: Could You Escape the Speed Cameras?
What Makes a Perfect Web Design Company?
What Makes a Perfect Web Design Company?
Inside No-Fuss Products In Gaming Computers
Inside No-Fuss Products In Gaming Computers
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Gaming Institute, Game Design Schools at PAI-ILS, PAI International Learning Solutions Pune
Free Music Players For Websites
Free Music Players For Websites
'See How NCP Tracks Down Fake Ration Card Holders'
'See How NCP Tracks Down Fake Ration Card Holders'
You Can Stop Panic Attacks in Just two Minutes
You Can Stop Panic Attacks in Just two Minutes
WordPress Blog to WP Site! A Journey to Online Success
WordPress Blog to WP Site! A Journey to Online Success
Videos will give your business portal an extra leverage
Videos will give your business portal an extra leverage
Excellent Ways To Make Weight Loss Work For You
Excellent Ways To Make Weight Loss Work For You
Five Notable Differences between National and International Logo Designs
Five Notable Differences between National and International Logo Designs
Who Should Your Phoenix Web Design Client Be?
Who Should Your Phoenix Web Design Client Be?
White Papers & Other Documents - including ALFLB
White Papers & Other Documents - including ALFLB
Google Analytics Tips
Google Analytics Tips
Want To Make Your Website Faster? Follow These Steps
Want To Make Your Website Faster? Follow These Steps
The Starting of Couture Apparel
The Starting of Couture Apparel
Choose Custom Website Design Services
Choose Custom Website Design Services
Choosing the Right Joomla CMS Developer
Choosing the Right Joomla CMS Developer
A Look at SQL Server Denali AlwaysOn
A Look at SQL Server Denali AlwaysOn
4 Tips to Choose the Perfect Flash Animation Course
4 Tips to Choose the Perfect Flash Animation Course

Leave Your Reply

*