• λ我爱Aspx >> Asp.Net >> 深入理解ASP中FSO的神奇功能
  • 深入理解ASP中FSO的神奇功能

  • :aspxer  Դ:internet  :2007-5-15 20:47:01  ؼ:asp
  • 假设你在一个表单中收集了一些用户信息,这里是一个简单表单HTML代码:

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

    再看看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")

    迄今为止,还没有新鲜的东西,无非是获取表单域的值并且赋值到变量。下面出现了有趣的部分 - 写文件:

    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

    回想一下,OpenTextFile方法返回一个TextStream对象,它是FSO模型中的另外一个对象。TextStream对象揭示了操作文件内容的方法,比如写、读一行、跳过一行。VB常量vbcrlf产生一个换行符。

    在OpentextFile的命令参数中定义了TRUE,这就告诉了系统,如果文件不存在,就创建它。如果文件不存在,并且没有定义TRUE参数,就会出错。

    现在转到目录c: emp,打开test.txt,你可以看到如下的信息:

    Ҷƪл˵?
  • һƪ20种看ASP程序源码的方法及工具
    һƪ借他人的程序造自己的家园 菜鸟也会架论坛