file1 為<input type=file id=file1 name=file1.....中的id.

解决方案 »

  1.   

    file1本来是一个客户端的控件,你是否把它运行在服务器端了?选择该控件点击右键选择“运行在服务器”这样在CS代码里面就会有相应的声明!
      

  2.   

    to  cuike519(studing sps(修练中...)) 
     filel可以设置为runat=server
      

  3.   

    file1是html控件,到Server使用,需要实例化
      

  4.   

    少了
    runat=server
    加上试试!
      

  5.   

    文件上传到数据库!
    {

    //取得上传文件的长度
    lenstr = File1.PostedFile.ContentLength;  //HttpPostedFile对象,用于读取图象文件属性 if(File1.PostedFile == null && File1.PostedFile.ContentLength ==0)
    {
    Response.Write("<script language=javascript>alert('文档大小0K!')</script>");
    //Response.End();
    }
    else
    {
    if (lenstr > 102400)
    {
    Response.Write("<script language=javascript>alert('文档大小不能超过100K!')</script>");
    }
    else
    {
    //Response.Write(lenstr); Sql = "insert into kj_MainPictureLink values("+DropDownList1.SelectedItem.Value.ToString()+",@Img_FileName,@Img_Type,@Img_Size,@Tab_Image,'"+TextBox1.Text.ToString()+"','"+DateTime.Now+"')"; SqlConnection MyConnection = new SqlConnection(Application["MySource"].ToString()); SqlCommand MyCommand = new SqlCommand(Sql,MyConnection); //MyCommand.Parameters.Add("@Tab_Image",SqlDbType.Image, lenstr).Value=imagebytes;  //文件名
    SqlParameter param = new SqlParameter("@Img_FileName",SqlDbType.NVarChar,100);
    param.Value = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\")+1);
    MyCommand.Parameters.Add(param); //文件类型
    param = new SqlParameter("@Img_Type",SqlDbType.NVarChar,50);
    param.Value = File1.PostedFile.ContentType;
    MyCommand.Parameters.Add(param); //文件大小
    param = new SqlParameter("@Img_Size",SqlDbType.Float,8);
    param.Value = lenstr;
    MyCommand.Parameters.Add(param); //文件内容
    byte[] context = new Byte[lenstr];
    param = new SqlParameter("@Tab_Image",SqlDbType.Image);
    File1.PostedFile.InputStream.Read(context,0,lenstr);
    param.Value = context;
    MyCommand.Parameters.Add(param); MyConnection.Open();

    //进行输入
    try
    {
    MyCommand.ExecuteNonQuery();
    }
    catch (Exception ex) 
    {
    Response.Write(ex.Message);

    } info.Text = "录入成功!"; TextBox1.Text = ""; Response.Write("<script language=javascript>alert('录入成功!');</script>");
    }
    }
    }