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.
61 lines
1.5 KiB
61 lines
1.5 KiB
4 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Web;
|
||
|
using System.Web.Mvc;
|
||
|
using QMAPP.Common.Web.Controllers;
|
||
|
using System.Text;
|
||
|
|
||
|
namespace QMAPP.FJC.Web.Controllers
|
||
|
{
|
||
|
public class FileController : QController
|
||
|
{
|
||
|
#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;
|
||
|
|
||
|
//保存文件
|
||
|
file.SaveAs(MvcApplication.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
|
||
|
|
||
|
}
|
||
|
}
|