当我尝试运行时,在下面显示的类字段中给出异常:
非静态字段,方法或者需要对象引用 property' System.Web.UI.Page.MapPath(string)
为什么?
代码背后的代码:public partial class Profile : System.Web.UI.Page
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/pic"));
答案 0 :(得分:1)
尝试Server.MapPath()
或HttpContext.Current.Server.MapPath()
答案 1 :(得分:1)
DirectoryInfo dir = new DirectoryInfo(
HttpContext.Current.Request.PhysicalApplicationPath + "\\pic"));
答案 2 :(得分:0)