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

posted @ 2011-10-30 12:03  夜明的孤行灯  阅读(634)  评论(3编辑  收藏  举报
返回顶部