Ejemplo n.º 1
0
        public ActionResult UploadFiles(HttpPostedFileBase[] files)
        {
            if (ModelState.IsValid)
            {
                int fileCounter = 0;
                foreach (HttpPostedFileBase file in files)
                {
                    if (file != null)
                    {
                        if (file.FileName.EndsWith(".xlsx"))
                        {
                            var ServerSavePath = Path.Combine(Server.MapPath("~/UploadedFiles/") + Guid.NewGuid());
                            file.SaveAs(ServerSavePath);
                            DataBaseHandler.FilesToDB(ServerSavePath);
                            System.IO.File.Delete(ServerSavePath);
                            fileCounter++;
                        }
                    }
                }

                ViewBag.UploadStatus = fileCounter + " files uploaded successfully.";
            }
            return(View());
        }