天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
1.6 KiB

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 上传文件
/// <summary>
/// 载入行为
/// </summary>
/// <returns></returns>
public ActionResult UploadFile()
{
return View();
}
/// <summary>
/// 上传行为
/// </summary>
/// <param name="file">文件</param>
/// <returns>js</returns>
[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
}
}