public ActionResult AuditCallback(string code) { var list = cInstance.GetCompHisList(string.Format("AND CH_CompCode='{0}'", code)); Bse_CompHistory model = list.FirstOrDefault(o => o.CH_iType == "File"); List <Bse_CompHistory> auditHis = list.Where(o => o.CH_iType != "File").ToList(); if (model != null) { try { var d = System.IO.Path.GetTempPath(); //var d = @"E:\运营方案"; string filename = Path.GetFileName(model.CH_FilePath); string temp = Server.MapPath(model.CH_FilePath); string srcpath = temp; string despath = Path.Combine(d, filename); ThumNail.AddWaterWord(string.Format("{0} {1}", SessionConfig.UserName(), DateTime.Now.ToString("yy-MM-dd hh:mm")), srcpath, despath, 10, auditHis.Count * 30); //如果存在则表示生成成功 if (System.IO.File.Exists(despath)) { System.IO.File.Copy(despath, srcpath, true); System.IO.File.Delete(despath); } } catch (Exception ex) { return(new JsonResult { Data = new { result = "fail", Msg = ex.Message } }); } Bse_CompHistory newModel = new Bse_CompHistory(); newModel.CH_Code = cInstance.GenerateHistoryCode(); newModel.CH_CompCode = model.CH_CompCode; newModel.CH_FilePath = model.CH_FilePath; newModel.CH_Auditor = SessionConfig.UserId(); newModel.CH_AuditorName = SessionConfig.UserName(); newModel.CH_Date = DateTime.Now; newModel.CH_iType = "His"; newModel.CH_Type = "审核"; cInstance.AddHis(newModel); return(new JsonResult { Data = new { result = "success", Msg = "数据更新成功!" } }); } else { return(new JsonResult { Data = new { result = "fail", Msg = "请上传图纸文件图片!" } }); } }
/// <summary> /// 返回上传成功后的文件名,如果上传失败则返回"" /// </summary> /// <param name="fu">FileUpload控件ID</param> /// <returns></returns> protected string UpFile(FileUpload FileUpload1) { string fileFullName = ""; if (FileUpload1.HasFile) { //判断文件是否小于2Mb if (FileUpload1.PostedFile.ContentLength < 1024 * 1024 * 2) { try { string filename = DateTime.Now.ToString("yyyyMMddhhmmssffff"); string path = DateTime.Now.ToString("yyyyMM"); if (!Directory.Exists(Server.MapPath("~/UpFile/" + path + "/"))) { Directory.CreateDirectory(Server.MapPath("~/UpFile/" + path + "/")); } string fileExt = FileUpload1.FileName.Split('.')[1].ToString().ToLower(); //上传文件并指定上传目录的路径 FileUpload1.PostedFile.SaveAs(Server.MapPath("~/UpFile/" + path + "/") + filename + "_bak." + fileExt); //将大图缩小,以免太大影响打开速度 ThumNail.MakeThumNail(Server.MapPath("~/UpFile/" + path + "/") + filename + "_bak." + fileExt, Server.MapPath("~/UpFile/" + path + "/") + filename + "." + fileExt, 600, 600, "HW2"); File.Delete(Server.MapPath("~/UpFile/" + path + "/") + filename + "_bak." + fileExt); //生成缩略图 ThumNail.MakeThumNail(Server.MapPath("~/UpFile/" + path + "/") + filename + "." + fileExt, Server.MapPath("~/UpFile/" + path + "/") + filename + "_s." + fileExt, 300, 300, "HW2"); /*注意->这里为什么不是:FileUpLoad1.PostedFile.FileName * 而是:FileUpLoad1.FileName? * 前者是获得客户端完整限定(客户端完整路径)名称 * 后者FileUpLoad1.FileName只获得文件名. */ //当然上传语句也可以这样写(貌似废话): //FileUpLoad1.SaveAs(@"D:\"+FileUpLoad1.FileName); filename = filename + "." + fileExt; fileFullName = "/UpFile/" + path + "/" + filename; } catch (Exception ex) { //lblMessage.Text = "出现异常,上传图片失败!" + ex.Message; //lblMessage.Text += ex.Message; } } else { //lblMessage.Text = "上传文件不能大于2MB!"; } } return(fileFullName); }
/// <summary> /// 零件图纸上传(图片上传) /// </summary> /// <param name="qqfile"></param> /// <returns></returns> public ActionResult Upload(string qqfile) { var path = Server.MapPath("~/Upload"); var dpath = Server.MapPath("~/Upload/Temp"); string file = Comm.FileUpload.UploadFile(qqfile, path, System.Web.HttpContext.Current); string dfile = Path.Combine(dpath, Path.GetFileName(file)); //业务处理 已审人数*50作为高度 if (string.IsNullOrEmpty(file)) { return(Json(new { result = "fail", message = "上传失败!" }, "application/json")); } ThumNail.AddWaterWord(SessionConfig.UserName(), file, dfile, 100, 100); return(Json(new { result = "success", path = "/Upload/" + Path.GetFileName(file), message = "成功" }, "application/json")); }