//单附件上传 public JsonResult UpLoadImage(HttpPostedFileBase file) { var res = new JsonResult(); res.JsonRequestBehavior = JsonRequestBehavior.AllowGet; try { string id = Guid.NewGuid().ToString(); image img = new image(); img.id = id; img.fileName = file.FileName; img.fileType = file.ContentType; img.fileSize = file.ContentLength; String[] arr = file.FileName.Split(new char[1] { '.' }); img.filePath = "/UpLoadFile/" + id + "." + arr[arr.Length - 1]; string path = Server.MapPath(img.filePath); file.SaveAs(path); bool flag = new BLL.handleImage().save(img); if (flag) { res.Data = new { success = true, data = new { id = id, link = img.filePath } }; } else { res.Data = new { success = false }; } return(res); } catch (Exception ex) { res.Data = new { success = false }; return(res); } }
//返回image对象 public static image generateImage(string id) { DataTable dt = new BLL.handleImage().queryDetail(id); image img = new image(); img.id = dt.Rows[0]["id"].ToString(); img.fileName = dt.Rows[0]["fileName"].ToString(); img.fileType = dt.Rows[0]["fileType"].ToString(); img.fileSize = Convert.ToInt32(dt.Rows[0]["fileSize"].ToString()); img.filePath = dt.Rows[0]["filePath"].ToString(); img.create_time = dt.Rows[0]["create_time"].ToString(); return(img); }
//返回list image对象 public static List <image> generateListImage(string ids) { DataTable dt = new BLL.handleImage().queryList(ids); List <image> list = new List <image>(); for (int i = 0; i < dt.Rows.Count; i++) { image img = new image(); img.id = dt.Rows[i]["id"].ToString(); img.fileName = dt.Rows[i]["fileName"].ToString(); img.fileType = dt.Rows[i]["fileType"].ToString(); img.fileSize = Convert.ToInt32(dt.Rows[i]["fileSize"].ToString()); img.filePath = dt.Rows[i]["filePath"].ToString(); img.create_time = dt.Rows[i]["create_time"].ToString(); list.Add(img); } return(list); }