コード例 #1
0
        public ActionResult Upload(HttpPostedFileBase upload)
        {
            string filePath   = "";
            string validation = ".xml";

            if (upload != null)
            {
                errorMessage = "";

                string fileName = System.IO.Path.GetFileName(upload.FileName);

                if (fileName.Contains(validation) == false)
                {
                    errorMessage = "Sorry, this file is not XML, select XML file";
                    return(RedirectToAction("Index"));
                }
                if (upload.ContentLength > 3000000)
                {
                    errorMessage = "Sorry, file exceeds the specified size of 4 MB";
                    return(RedirectToAction("Index"));
                }
                upload.SaveAs(Server.MapPath("~/Data/" + fileName));
                filePath = Server.MapPath("~/Data/" + fileName);
            }

            else if (upload == null)
            {
                errorMessage = "File not selected! Please select the file to continue";
                return(RedirectToAction("Index"));
            }


            if (filePath != "")
            {
                XmlLoader repository = new XmlLoader(filePath);
                Units = repository.GetData();
            }

            return(RedirectToAction("Index"));
        }