图片上传
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
string fullFileName = this.FileUpload1.PostedFile.FileName; //全路径 string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); // 这是\ 后面的名字 string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1); //这是.后面的名字 记得要加1 if (type == "jpg" || type == "bmp" || type == "gif") { this.FileUpload1.PostedFile.SaveAs(Server.MapPath("up") + "\\" + fileName); //保存的地方 UP为就文件区 this.Image1.ImageUrl = "../up/" + fileName; //控件IMAGE 可以看到上传的照片 Label1.Text = "../up/" +fileName; Response.Write("<script language='javascript'>alert('上传成功');</script>"); } else { Response.Write("<script language='javascript'>alert('你上传的格式不对!请重新上传!');</script>"); }