Example #1
0
        public ActionResult UploadFile(FileUploadModel model)
        {
            string tempPath = null;
            var submittedFile = Request.Files["File"];

            if (submittedFile != null && submittedFile.ContentLength > 0) {
                AppUtil.GetTempPath(submittedFile.FileName, out tempPath);
                submittedFile.SaveAs(tempPath);
            }

            if (tempPath == null) {
                return View(model);
            }

            var existingFile = new FileInfo(tempPath);
            var extension = existingFile.Extension;
            var headerData = new List<string>();

            switch (extension) {
                case ".xlsx": {
                        using (var package = new ExcelPackage(existingFile)) {
                            var workSheet = package.Workbook.Worksheets[1];
                            if (workSheet != null && workSheet.Dimension != null && workSheet.Dimension.End.Row > 1) {
                                for (var col = 1; col <= workSheet.Dimension.End.Column; col++) {
                                    if (workSheet.Cells[1, col].Value != null)
                                        headerData.Add(workSheet.Cells[1, col].Value.ToString());
                                }
                            }
                        }
                    }
                    break;
            }
            AppUtil.DeleteDirectory(new FileInfo(tempPath).DirectoryName);
            return View(model);
        }
Example #2
0
 public ActionResult UploadFile()
 {
     var model = new FileUploadModel();
     return View(model);
 }