上传图片2
<asp:FileUpload ID="FileUpload1" runat="server" />
string fullFileName = this.FileUpload1.PostedFile.FileName;
string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);
string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);
if (type == "jpg" || type == "JPG" || type == "gif" || type == "GIF" || type == "BMP" || type == "bmp")
{
string p;
string t,Sql;
t = DateTime.Now.Ticks.ToString();
p = Request.Url.AbsoluteUri.Replace("personal/perpic.aspx", "UploadFile/" + t + "." + type);
this.FileUpload1.PostedFile.SaveAs(Server.MapPath("../UploadFile") + "\\" + t + "." + type);
//txtPic.Text = p;
Image1.ImageUrl = p;
Sql="update Job_Person set pic='"+p+"' where id='" +Session["id"].ToString() +"'";
con.Open();
cmd = new SqlCommand(Sql, con);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
//Response.Write(p);
Response.Write("<script>alert('图片上传成功!!');</script>");
}
else
{
Response.Write("<script>alert('图片格式错误!!')</script>");
}