Asp.net 获取当前目录的三种方法

作者:

方法一:

string sPath = System.IO.Path.GetDirectoryName(Page.Request.PhysicalPath)

方法二:

string sPath = System.Web.HttpContext.Current.Request.MapPath(“/“)

方法三:

string sPath = Page.Server.MapPath(“/“);

我推荐使用第二种

有时候可能出现找不到类的情况,请引用System.Web.dll

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注