});
6、上传文件后,控制器中的处理
/// <summary>
/// 上传项目报告
/// </summary>
/// <param name="id">项目ID</param>
/// <param name="file"></param>
/// <returns></returns>
[HttpPost]
public ActionResult UploadFile(int id, HttpPostedFileBase file)
{
if (file == null)
return Content("没有选择文件");
if (AuthContext.Current == null)
return Content("登录异常!");
using (var db = new Entities())
{
var model = db.Project.Find(id);
if (model == null)
return Content("项目异常!");
string path = String.Format(@"Control\{0}\{1}\{2}.hfrpt", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.ToString("dd-hhmmss"));
var key = FileHelper.GetFileName(path);
var temp = FileHelper.GetFileName(String.Format(@"Temp\{0}.hfrpt", DateTime.Now.ToString("yyyyMMdd-hhmmss")));
file.SaveAs(temp);
var safekey = id.ToString() + "haifeng%";
EncryptHelper.DesEncrypt(temp, key, safekey);
System.IO.File.Delete(temp);
model.ReportFilePath = path;
var entry = db.Entry(model);
entry.State = EntityState.Modified;
db.SaveChanges();
return Content("上传成功");
}