日期:2014-05-18  浏览次数:20502 次

上传控件的错误??谁能帮帮我
protected void Button1_Click(object sender, EventArgs e)
  {
  if (this.File1.Value != null) ???file1是什么意思??
  {
  //获取文件的完整路径 
  string path = this.File1.PostedFile.FileName;
  //获取文件名 
  string filename = System.IO.Path.GetFileName(path); ????filename 是什么意思??
  Response.Write(path);
  Response.Write(filename);
  //获取文件的长度 
  = File1.PostedFile.ContentLength; ???又是什么??
  Byte[] length = new Byte[filelength];
  Response.Write(filelength);
  Stream instream = File1.PostedFile.InputStream; ???Stream instream 是什么意思???
  instream.Read(length, 0, filelength);
  SqlConnection conn = new SqlConnection("server=.;uid=sa;database=Future");
  string addpic = "insert into pic values(@picture)";
  SqlCommand com = new SqlCommand(addpic, conn);
  com.Parameters.Add(new SqlParameter("@picture", SqlDbType.Binary, filelength));
  com.Parameters["@picture"].Value = length;
  conn.Open();
  com.ExecuteNonQuery();
  Response.Write("cheng gong");
  Response.OutputStream.Write(length, 0, filelength);
  //Response.ContentType="image/jpg"; 
  conn.Close();
  } 
  }

------解决方案--------------------
???file1是什么意思??------->上传控件的名字
????filename 是什么意思??--->变量用来接收文件名
filelength = File1.PostedFile.ContentLength; ???filelength是什么??
----->变量未定义类型,错误,ContentLength是取文件长度
int filelength = File1.PostedFile.ContentLength;
 ???Stream instream 是什么意思??? 是流呀要引用IO包
using System.IO;