public ActionResult UploadAchievement(HttpPostedFileBase file, int courseId) { string path = null; try { if (file == null) { return(Json(new { exists = false })); } string fileName = HttpContext.Server.MapPath("~/Resources/Temp/") + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + System.IO.Path.GetFileName(file.FileName); file.SaveAs(fileName); if (!System.IO.File.Exists(fileName)) { return(Json(new { exists = false })); } path = fileName; ExcelManager excel = new ExcelManager(fileName); if (!excel.CheackAchievementTemplates()) { return(Json(new { exists = true, legal = false })); } SQLManager manager = new SQLManager(); var grades = excel.GetAchievement(); bool flag = manager.AddGrades(grades, courseId); if (flag) { return(Json(new { exists = true, legal = true, success = true })); } return(Json(new { exists = true, legal = true, success = false })); } finally { if (path != null) { System.IO.File.Delete(path); } } }