为什么老是提示我“未将对象引用设置到对象的实例”?这是网上找的存取图片的例子,怎么都用不了呢?出错提示:
行 122: btSubmit.Text="250";
行 123: HttpPostedFile  UpFile  =  UP_FILE.PostedFile;//HttpPostedFile对象,用于读取图象文件属性  
行 124: FileLength  =  UpFile.ContentLength; 
行 125: try 网页代码:
<INPUT id="UP_FILE" style="WIDTH: 471px; HEIGHT: 22px" type="file" size="59" runat="server">程序定义:
protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;程序里的UP_FILE是指INPUT控件的ID属性,还是name属性?

解决方案 »

  1.   

    HttpPostedFile  UpFile=new HttpPostedFile();
    UpFile  =  UP_FILE.PostedFile;這樣使用....
      

  2.   

    try;

    if(this.UP_FILE.PostedFile==null)
        Response.Write("没有上传文件");
    else
    {
        HttpPostedFile  UpFile = new HttpPostedFile();
        UpFile = this.UP_FILE.PostedFile;
        FileLength  =  UpFile.ContentLength; 
    }
      

  3.   

    HttpFileCollection files  = HttpContext.Current.Request.Files
    for(int iFile = 0; iFile < files.Count; iFile++)
      {
         HttpPostedFile postedFile = files[iFile];
      

  4.   

    为什么老是提示我“未将对象引用设置到对象的实例”?这是网上找的存取图片的例子,怎么都用不了呢?
    出错提示:
    行 123: HttpPostedFile  UpFile  =  UP_FILE.PostedFile;
    ---------------------------------------将上面的语句改为如下:
    HttpPostdFile UpFile = this.Request.Files["UP_FILE"];
      

  5.   

    程序里的UP_FILE是指INPUT控件的ID属性,还是name属性?
    UP_FILE是一个类的实例,需要使用 new操作符初始化;
      

  6.   

    还是不行啊!
    现在报“E:\web\postinf\WebForm1.aspx.cs(124): 重载“HttpPostedFile”方法未获取“0”参数”
      

  7.   

    呵呵,估计是没定义form的一个属性:<form encType="multipart/form-data" 
      

  8.   

    谢谢你烟虫!你说得对,就是:<form encType="multipart/form-data"的问题,结帖!