当我尝试运行这个选项时,请给我类字段中的异常,如下所示:
非静态字段、方法或属性的System.Web.UI.Page.MapPath(字符串)需要对象引用。
为什么?
代码背后:
public partial class Profile : System.Web.UI.Page
{
DirectoryInfo dir = new DirectoryInfo(MapPath("~/pic"));发布于 2013-02-18 18:47:42
DirectoryInfo dir = new DirectoryInfo(
HttpContext.Current.Request.PhysicalApplicationPath + "\\pic"));发布于 2013-02-18 18:45:32
试试Server.MapPath()或HttpContext.Current.Server.MapPath()
发布于 2013-02-18 18:41:58
来自MSDN文档:
路径开头的...the斜杠(/)表示站点的绝对虚拟路径。
所以你的"~“是错误的,没有必要的。
https://stackoverflow.com/questions/14943133
复制相似问题