ASP编程要点ABC之一(使用Server.MapPath)
出处:eNet学院 2004年02月14日 作者:甘冀平 责任编辑:zwg
文章导读:ASP编程要点ABC之一(使用Server.MapPath)
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
% >
[1]
>>继续下一页
相关快问问题
频道精选
不花钱又能表达芳心,为对方设计情人节贺卡或者壁纸之类的,相信你的花心思制作的作品也能感动对方。...[详细]
- 如何利用ASP实现邮箱访问09-22
- 应用总结:ASP编程心得回放09-21
- ASP连接11种数据库语法总结09-21
- ASP利用Google实现在线翻译功能09-12
- Asp无组件生成缩略图08-29
论坛热帖
热门软件下载推荐
本周十大热评文章
本周十大人气文章
软件今日报价






