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


作者:黄云坤
出处:http://www.huangyunkun.com/
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
支持: 新浪微博

原文地址:https://www.cnblogs.com/htynkn/p/2229170.html