English 中文(简体)
反对不提及某一物体的情况?
原标题:
  • 时间:2009-05-19 22:03:44
  •  标签:

我写了这些字句,但我有《纽埃特约》。 请帮助我如何确定!

string FullPath = TempPath + FileName;
System.Drawing.Image Adimg = null;
Adimg = System.Drawing.Image.FromFile(MapPath(FullPath));

我将这些线路放在公共浴室方法中,而TempPath是集体财产,FilName是这种方法的投入。

exception Detail:
System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="System.Web"
  StackTrace:
       at System.Web.UI.Page.MapPath(String virtualPath)
       at FileIO.HasValidAttributes(String FileName) in g:MyProjectsASP.net ProjectsADBridgeadengine2App_CodeFileIO.cs:line 44
       at UploadPage.<Page_Load>b__0(Object sender1, EventArgs e1) in g:MyProjectsASP.net ProjectsADBridgeadengine2UploadPage.aspx.cs:line 29
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

www.un.org

最佳回答

而是在服务器物体上打“地图”:

HttpContext.Current.Server.MapPath(FullPath)
问题回答

这里有几个方面:

  1. Use Path.Combine to build paths from individual pieces
  2. Verify that FullPath refer to a file that is
    • Present on disk
    • Readable by the web process (ie. not running the web process under System Account or similar)

阅读“Fullpath = TempPath + fileName”,似乎你试图通过一个虚拟地址的物理地址?

情况如何? 如果你不这样做,你会给我们什么东西作为对这一职能的投入? 如果是物理途径,就不必使用地图。

为此:

string fullPath = Path.Combine(TempPath, FileName);
System.Drawing.Image adimg = null;
if (!String.IsNullOrEmpty(fullPath))
{
    string serverPath = HttpContext.Current.Server.MapPath(fullPath);
    if (!String.IsNullOrEmpty(serverPath))
        adimg = System.Drawing.Image.FromFile(serverPath);
}

确保<代码>MapPath能给你预期的东西。





相关问题
热门标签