Server.MapPath() 探究
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
[b]server.mappath(path)[br][/b] the [b]mappath[/b] method maps the specified relative or virtual path to the corresponding physical directory on the server.[br]parameters (msdn:[url=ms-help://ms.msdnqtr.2003feb.2052/iisref/htm/ref_vbom_serommp.htm]ms-help://ms.msdnqtr.2003feb.2052/iisref/htm/ref_vbom_serommp.htm[/url])[br]用法:[br]1.server.mappath("/") 应用程序根目录所在的位置 如 c:\inetpub\wwwroot\[br]2.server.mappath("./") 表示所在页面的当前目录 [br] 注:等价于server.mappath("") 返回 server.mappath("")所在页面的物理文件路径[br]3.server.mappath("../")表示上一级目录 [br]4.server.mappath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,就是虚拟目录所在的位置 如:c:\inetpub\wwwroot\example\[br]注:等效于server.mappath("~")。[br][br]不知道是否正确,研究中......[br]另:以下几句等效[br]string filename=server.mappath("./") + @"\web.config";[br]string filename=server.mappath("./") + "/web.config";[br]string filename=server.mappath("") + @"\web.config"[br][br]附一例子:修改web.config的某一节点的属性值[br]
[img]http://lanshh.cnblogs.com/images/outliningindicators/none.gif[/img][color=#000000] [/color][color=#0000ff]public[/color][color=#000000] [/color][color=#0000ff]void[/color][color=#000000] write()[br][img]http://lanshh.cnblogs.com/images/outliningindicators/expandedblockstart.gif[/img][img]http://lanshh.cnblogs.com/images/outliningindicators/contractedblock.gif[/img] [/color][hilitecolor=#ffffff][/hilitecolor][color=#000000]{[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] [/color][color=#0000ff]string[/color][color=#000000] key1 [/color][color=#000000]=[/color][color=#000000] [/color][color=#0000ff]this[/color][color=#000000].textbox1.text;[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] dataset ds [/color][color=#000000]=[/color][color=#000000] [/color][color=#0000ff]new[/color][color=#000000] dataset();[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] ds.readxml(server.mappath([/color][color=#000000]""[/color][color=#000000])[/color][color=#000000]+[/color][color=#000000]"[/color][color=#000000]/web.config[/color][color=#000000]"[/color][color=#000000]);[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] [/color][color=#008000]//[/color][color=#008000] 不是tables[0][/color][color=#008000][br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img][/color][color=#000000] ds.tables[[/color][color=#000000]1[/color][color=#000000]].rows[[/color][color=#000000]0[/color][color=#000000]][[/color][color=#000000]1[/color][color=#000000]] [/color][color=#000000]=[/color][color=#000000] key1;[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] ds.acceptchanges();[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] ds.writexml(server.mappath([/color][color=#000000]""[/color][color=#000000])[/color][color=#000000]+[/color][color=#000000]"[/color][color=#000000]/web.config[/color][color=#000000]"[/color][color=#000000]);[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] ds.dispose();[br][img]http://lanshh.cnblogs.com/images/outliningindicators/inblock.gif[/img] [br][img]http://lanshh.cnblogs.com/images/outliningindicators/expandedblockend.gif[/img] }[/color] 该文章在 2010/11/29 13:59:27 编辑过 |
关键字查询
相关文章
正在查询... |