最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ASP编程要点ABC之一
时间:2022-07-02 23:50:48 编辑:袖梨 来源:一聚教程网
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
% >
使用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
% >
相关文章
- 太阳能热水器的原理是什么 07-28
- 王者荣耀世界小乔守护者玩法攻略 07-28
- 英雄联盟手游豹女连招技巧 07-28
- 向僵尸开炮王胖子厉害吗 07-28
- 原神月之四版本活动祈愿第一期介绍 07-28
- 小拇指凹坑,就是新时代的“手机病” 07-28