安大互联
财经热点 > Asp编程 > ASP编程要点ABC之一(使用Server.MapPath)
ASP编程要点ABC之一(使用Server.MapPath)
浏览次数:【846】  发布日期:2009-8-13 12:09:22    文章分类:Asp编程   
专题:】 【
 

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

% >

手机扫码浏览该文章
 ● 相关资讯专题
  • 网络建设业务咨询

   TEl:13626712526