当前位置:首页 > 网络编程 > WEB编程 > ASP > ASP编程要点ABC之一(使用Server.MapPath)

ASP编程要点ABC之一(使用Server.MapPath)

点击次数:20 次 发布日期:2008-11-26 14:32:05 作者:源代码网
源代码网推荐

ASP编程要点ABC

使用Server.MapPath

  尽可能地使用Server.MapPath()来表示存储在服务器上的文件,而不要用静态绝对路径。因为,如果采用静态绝对路径,当web路径发生变化时,将导致文件路径表达错误,从而不得不修改原静态路径。而使用Server.MapPath()表示的路径就不必再做修改。

比如,以下的代码就不是好的方法:

< %

whichfile="D:inetpubwwwrootwhateverjunk.txt"

set fs = CreateObject("Scripting.FileSystemObject")

Set thisfile = fs.OpenTextFile(whichfile, 1, False)

tempSTR=thisfile.readall

response.write tempSTR

thisfile.Close

set thisfile=nothing

set fs=nothing

% >

建议使用下面的代码来完成同样的功能:

< %

whichfile=server.mappath("whateverjunk.txt")

set fs = CreateObject("Scripting.FileSystemObject")

Set thisfile = fs.OpenTextFile(whichfile, 1, False)

tempSTR=thisfile.readall

response.write tempSTR

thisfile.Close

set thisfile=nothing

set fs=nothing

% >


源代码网供稿.
上一篇: asp中ADO的优化  下一篇: ASP编程要点ABC
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华