Magic of FSO in ASP-file writing

Source: Internet
Author: User

Author: Gan jiping;

Suppose you want to create a simple message book, you can create a database to store user information. However, if you do not need the powerful functions of the database, using FSO to store information will save you time and money. In addition, some ISPs may restrict database applications on the web.

Suppose you have collected some user information in a form. Here is a simple form htmlCode:

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

Let's look at the code for processing the form in formhandler. asp:

<%

'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 ")

So far, nothing is new. It is nothing more than getting the values of form fields and assigning values to variables. An interesting part is shown below:

Path = "C: EMP est.txt"

Forreading = 1, forwriting = 2, forappending = 3

'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

In retrospect, the opentextfile method returns a textstream object, which is another object in the FSO model. Textstream object reveals the operationCompositionContent method, such as writing, reading, and skipping a row. The VB constant vbcrlf generates a line break.

The value true is defined in the Command Parameter of opentextfile, which tells the system to create a file if the file does not exist. If the file does not exist and the true parameter is not defined, an error occurs.

Now go to the directory c: empand open test.txt. You can see the following information:

User's name

User's home page

User's email

Of course, these words can be replaced by any input in the form.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.