コード例 #1
0
        public ActionResult Upload(IEnumerable <HttpPostedFileBase> uploads)
        {
            int      loadedFiles = 0;
            DataToDB dataToDB    = new DataToDB();

            foreach (var file in uploads)
            {
                if (file != null)
                {
                    string fileName = Server.MapPath("~/Files/" + System.IO.Path.GetFileName(file.FileName));

                    if (FileInfo.CanBeAdded(fileName))
                    {
                        file.SaveAs(fileName);

                        if (dataToDB.SaveDataToDB(fileName))
                        {
                            loadedFiles++;
                        }
                        else
                        {
                            FileInfo.DeleteFile(fileName);
                        }
                    }
                }
            }

            ViewBag.FilesAmount = loadedFiles;
            return(View("Success"));
        }