Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 1/24/2014 9:16:15 AM
用Asp.Net获取目录的方法_[Asp.Net教程]

用Asp.Net获取目录的方法_[Asp.Net教程]

学习asp.net上传文件时,发现有三种方法可以获取当前web程序目录物理路径:

方法一:
string sPath = System.IO.Path.GetDirectoryName(Page.Request.PhysicalPath);

方法二:
string sPath = System.Web.HttpContext.Current.Request.MapPath("images/");  //("images/")是当前虚拟目录下的任意目录

方法三:
string sPath = Page.Server.MapPath("images/");  //("images/")是当前虚拟目录下的任意目录
sPath = Page.Server.MapPath(".");  //当前目录

另:获取全路径中的文件名
string sFile = System.IO.Path.GetFileName(sFile);






If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)




QQ:154298438
QQ:417480759