asp:FileUpload 上次图片
<asp:FileUpload ID="FileUpload附件" runat="server" Width="200px" /> protected void btnEdit_Click(object sender, EventArgs e) { if (txtCarPlateNumber.Text.Trim() == "") { ClientScript.RegisterStartupScript(GetType(), "", "alert('请输入车牌号!');", true); return; } int Id = 0; if (string.IsNullOrEmpty(Request.Params["Id"]) == false) { Id = int.Parse(Request.Params["Id"]); } ModelBlackWhiteList model = new ModelBlackWhiteList(); model.Id = Id; model.CarPlateType = ddlCarPlateType.SelectedItem.Text; model.CarPlateNumber = txtCarPlateNumber.Text.Trim(); model.Company = txtCompany.Text.Trim(); model.BWFlag = ddlBWFlag.SelectedItem.Value; model.OperatorName = this.UserLogin; model.CreateDateTime = DateTime.Now; string CommandName = Request.Params["CommandName"].ToString(); switch (CommandName) { case "Upd": { if (FileUpload附件.PostedFile.FileName.Trim().Length != 0) { string savePath; string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms"); if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg")) { savePath = Server.MapPath("~/Upload/");//指定上传文件在服务器上的保存路径 //检查服务器上是否存在这个物理路径,如果不存在则创建 if (!System.IO.Directory.Exists(savePath)) { System.IO.Directory.CreateDirectory(savePath); } savePath = savePath + fileName + ".jpg"; FileUpload附件.SaveAs(savePath); model.CarPicPath = "/Upload /" + fileName + ".jpg"; } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择JPG图片文件!');", true); return; } } int result = SqlSugarClientHelper.SqlDBConnection.Updateable<ModelBlackWhiteList>(model).ExecuteCommand(); if (result > 0) { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true); } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失败!');", true); } break; } case "New": { if (FileUpload附件.PostedFile.FileName.Trim().Length != 0) { string savePath; string fileName = DateTime.Now.ToString("yyyyMMddHHmmssms"); if (FileUpload附件.HasFile && FileUpload附件.PostedFile.FileName.Contains(".jpg")) { savePath = Server.MapPath("~/Upload/BWFLag/");//指定上传文件在服务器上的保存路径 //检查服务器上是否存在这个物理路径,如果不存在则创建 if (!System.IO.Directory.Exists(savePath)) { System.IO.Directory.CreateDirectory(savePath); } savePath = savePath + fileName + ".jpg"; FileUpload附件.SaveAs(savePath); model.CarPicPath = "/Upload/BWFLag/" + fileName + ".jpg"; } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择JPG图片文件!');", true); return; } } int result = SqlSugarClientHelper.SqlDBConnection.Insertable<ModelBlackWhiteList>(model).ExecuteCommand(); if (result > 0) { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存成功!');window.location = 'BlackWhiteListManage.aspx';", true); } else { ClientScript.RegisterStartupScript(GetType(), "", "alert('保存失败!');", true); } break; } } }