public String Upload() { if (HttpContext.Current.Request.Files.Count < 1) { return(""); } var result = new List <String>(); String today = DateTime.Now.ToString("yyyy-MM-dd"); String dic = HostingEnvironment.MapPath("~/images/upload/" + today + "/"); if (!Directory.Exists(dic)) { Directory.CreateDirectory(dic); } for (var i = 0; i < HttpContext.Current.Request.Files.Count; i++) { HttpPostedFile file = HttpContext.Current.Request.Files[i]; if (file.ContentLength < 1) { continue; } String fileName = Guid.NewGuid().ToString(); String ext = Path.GetExtension(file.FileName); String path = dic + fileName + ext; file.SaveAs(path); var config = DB.yy_SiteSetting.FirstOrDefault(); #region 加水印 if (config != null && config.EnabelWatermark == 1 && !String.IsNullOrEmpty(config.Watermark) && File.Exists(HttpContext.Current.Server.MapPath(config.Watermark))) { var ImgPath = HttpContext.Current.Server.MapPath(config.Watermark); var NewImagePath = HttpContext.Current.Server.MapPath("/images/upload/" + today); fileName = Guid.NewGuid().ToString(); var NewImageSavePath = NewImagePath + "\\" + fileName + ext; var ImgItem = System.Drawing.Image.FromFile(path); Watermark.AddImageSignPic(ImgItem, NewImageSavePath, ImgPath, 5, 100, 6); try { File.Delete(path); } catch { } result.Add("/images/upload/" + today + "/" + fileName + ext); } #endregion #region 加水印 else { result.Add("/images/upload/" + today + "/" + fileName + ext); } #endregion } if (result.Count < 1) { return(""); } return(String.Join(",", result)); }