现在的位置: 首页 > 综合 > 正文

asp.net 获取当前目录

2011年11月27日 ⁄ 综合 ⁄ 共 407字 ⁄ 字号 评论关闭

学习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/")是当前虚拟目录下的任意目录

另:获取全路径中的文件名

string  sFile = System.IO.Path.GetFileName(sFile);

抱歉!评论已关闭.