必须是在提交后才能得到File1.PostedFile。应该是你的代码有问题。把相关的代码都贴出来吧。

解决方案 »

  1.   

    if(FileUp.PostedFile!=null)
    {
    string myFilename=FileUp.PostedFile.FileName;
    int posi=myFilename.LastIndexOf("\\");
    string fn=myFilename.Substring(posi);
    string spath=Server.MapPath(@"./zp/");
    FileUp.PostedFile.SaveAs(spath+fn);
    this.Img_zp.ImageUrl =@"./zp/"+fn;
    this.Button1.Enabled =false;
    UpZp=true;

    }
    我的代码,
    用于
    http://www.hntbtc.com/rsgl/rsgl.aspx
    源程序
    http://www.hntbtc.com/hncjgl
      

  2.   

    真的活不成了,if(FileUp.PostedFile!=null) 果然判断出来了。就是这里过不去,可是就这样,我的程序另外新建一个项目,把相同的代码复制过去,却可以入库。是不是哪儿没设置对?代码应该没问题吧:private void Button1_Click(object sender, System.EventArgs e)
    {
    Stream imgStream;
    int imgLen;
       if (UploadFile.PostedFile !=null)
    { imgStream  = UploadFile.PostedFile.InputStream;
    imgLen =  UploadFile.PostedFile.ContentLength;
    byte[] imgBinaryData=new byte[imgLen];
             int n = imgStream.Read(imgBinaryData, 0, imgLen);          
    int NumRowsAffected = MyDatabaseMethod( imgBinaryData);
    }
    }
    public int MyDatabaseMethod(byte[] imgbin)
    {
    SqlConnection connection = new SqlConnection("Initial Catalog=basedb;Data Source=zdf;Integrated Security=SSPI;");
    string SQL="INSERT INTO MinuteInfo (ResultPic) VALUES (@img_data) ";
    SqlCommand command=new SqlCommand ( SQL,connection );
              
    SqlParameter param1=new SqlParameter("@img_data",SqlDbType.Image ); 
      
    param1.Value = imgbin;
    command.Parameters.Add( param1 ); connection.Open();
    int numRowsAffected = command.ExecuteNonQuery();
    connection.Close();
    return numRowsAffected;
    }
      

  3.   

    谢谢2位,原因找到了,表单里缺少 enctype="multipart/form-data"
    十分感谢2位的支持。