using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; namespace QMAPP.Common.Web.Controllers { public class FileController : QController { // // GET: /File/ #region 上传文件 /// /// 载入行为 /// /// public ActionResult UploadFile() { return View(); } /// /// 上传行为 /// /// 文件 /// js [HttpPost] public ActionResult UploadFile(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 tempPath = Server.MapPath(HttpRuntime.AppDomainAppVirtualPath) + "Temp\\"; //保存文件 file.SaveAs(tempPath + fileName); return this.GetJsViewResult(string.Format("window.returnValue='{0}';window.close();", System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8))); } catch (Exception ex) { throw ex; } } #endregion } }