Server.MapPath() 探究
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
[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的某一節(jié)點的屬性值[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 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |