public bool AddUploadFile() { try { using (TransactionScope scorp = new TransactionScope()) { HttpFileCollection files = HttpContext.Current.Request.Files; List <Attachment> attachs = new List <Attachment>(); foreach (string key in files.AllKeys) { HttpPostedFile file = files[key]; if (!string.IsNullOrEmpty(file.FileName) && file.ContentLength > 0) { Attachment attach = new Attachment(); attach.GoodNo = ""; attach.PicId = Core.Common.CreatGoodNo("pic"); attach.PicName = file.FileName; attach.PicPath = HttpContext.Current.Server.MapPath("~/ceshitupian/"); attachs.Add(attach); file.SaveAs(attach.PicPath + attach.PicId); } } //保存参数到数据库 return(upload.AddUploadFile(attachs)); } } catch (Exception ex) { throw new Exception(ex.Message + "发生了错误!"); } }