Beispiel #1
0
 public JsonResult ImportStudent()
 {
     if (Request.Files.Count == 0)
     {
         return(Json(new { state = false, Message = "没有上传文件" }));
     }
     try
     {
         var student  = new StudentServices();
         var filepath = System.Web.HttpContext.Current.Server.MapPath("~/FileUpload");
         CreateFolderIfNeeded(filepath);
         string badge = HttpContext.User.Identity.Name;
         foreach (string file in Request.Files)
         {
             HttpPostedFileBase uploadFile = Request.Files[file] as HttpPostedFileBase;
             if (uploadFile != null && uploadFile.ContentLength > 0)
             {
                 var path = Path.Combine(filepath, Guid.NewGuid().ToString() + ".xls");
                 uploadFile.SaveAs(path);
                 student.ImportStudent(file);
             }
         }
         return(Json(new { State = true, Message = "上传成功" }));
     }
     catch (Exception e)
     {
         return(Json(new { State = false, Message = e.Message }));
     }
 }