protected void Button1_Click(object sender, EventArgs e)
{
{
try
{
myconn = DB.CreateDB();
string addurl = Request["TxtAddurl"].ToString();
string title = FunStr(this.TxtTitle.Text);
//string content = FunStr(this.TxtContent.Text);
//string ptype = Request.QueryString["action"].ToString();
string FileName = myFile.Value;
HttpPostedFile UpFile = myFile.PostedFile; //获取对由客户端指定的上传文件的访问
FileLength = UpFile.ContentLength;//获取上传文件的字节大小
if (FileLength == 0)
{
myconn.Open();
OleDbCommand cmd1 = new OleDbCommand("insert into link(title,addurl,picture) values('" + title + "','" + addurl + "')", myconn);
cmd1.ExecuteNonQuery();
Response.Write("<script>alert('数据添加成功');window.location.href='Admin_LinkAdd.aspx'</script>");
myconn.Close();
}
else
{
string exName = FileName.Substring(FileName.LastIndexOf(".") + 1).ToUpper();//截取图片的后缀名
if (exName == "JPG" || exName == "BMP" || exName == "GIF")//判断图片的类型
{
if (FileLength > 204800)//判断图片是否大于200k(根据自己的需要判断大小)
{
Response.Write("<script>alert('对不起,图片大小不能大于200K');window.location.href='Admin_LinkAdd.aspx'</script>");
return;
}
else
{
string ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + "." + exName;//图片名称设置为保存的时间
Byte[] FileByte = new Byte[FileLength]; //图象文件储存到数组
Stream ObjectStream = UpFile.InputStream;//建立数据流对像,获取一个 Stream 对象,该对象指向一个上载文件,以准备读取该文件的内容。
ObjectStream.Read(FileByte, 0, FileLength); //读取图象文件数据
string StrSql = "Insert Into link(title,addurl,picture) Values(values('" + title + "','" + addurl + "',@ImageName)";
OleDbCommand Cmd = new OleDbCommand(StrSql, myconn);
//Cmd.Parameters.Add("@Image",OleDbType.Binary, FileLength).Value = FileByte;
Cmd.Parameters.Add("@ImageName", OleDbType.VarChar, 100).Value = ImageName;
myconn.Open();
this.myFile.PostedFile.SaveAs(Server.MapPath("/Upload") + "\\" + ImageName);
Cmd.ExecuteNonQuery();
myconn.Close();
Response.Write("<script>alert('数据添加成功');window.location.href='Admin_LinkAdd.aspx'</script>");
}
}
else
{
Response.Write("<script>alert('对不起,请选择正确的的图片!');window.location.href='Admin_LinkAdd.aspx'</script>");
return;
}
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
}
}
代码是这样的
调试的时候到 myconn.Close();
就跳到下面了啊出现错误提示
'没有找到upload的衍射路径'
是怎么回事啊?