using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using QMAPP.Common.Web.Controllers; using System.Text; using System.Text.RegularExpressions; namespace QMAPP.MD.Web.Controllers { public class ImageController : QController { #region 上传文件 /// /// 载入行为 /// /// public ActionResult ImageUplod() { return View(); } /// /// 上传行为 /// /// 文件 /// js [HttpPost] public ActionResult ImageUplod(HttpPostedFileBase file) { string expandName = ""; string fileName = file.FileName; try { //构造文件名 if (fileName.IndexOf(".") > 0) { //文件格式后缀 expandName = fileName.Substring(fileName.LastIndexOf(".") + 1); } // 设置完整(文件名+文件格式) fileName = Guid.NewGuid().ToString() + "." + expandName; string imagePath = System.Configuration.ConfigurationManager.AppSettings["ImagePath"].ToString(); //string imagePath = "Images/MaterialImage/"; // 获取保存图片的项目文件夹 string uploadPath = Server.MapPath("~/" + imagePath); // 将项目路径与文件夹合并 //保存文件 string savePath = uploadPath + fileName; file.SaveAs(savePath); return this.GetJsViewResult(string.Format("window.returnValue='{0}';window.close();", System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8))); } catch (Exception ex) { throw ex; } } #endregion } }