欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

 
ASP编程要点ABC

使用Server.MapPath

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

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

< %

whichfile="D:\inetpub\wwwroot\whatever\junk.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("\whatever\junk.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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP编程要点ABC之一(使用Server.MapPath)
分享到: 更多 (0)

相关推荐

  • 暂无文章