コード例 #1
0
        public ActionResult UploadExcel(FormCollection formCollection)
        {
            WorldRefExcelDataModel worldExcelModel = new WorldRefExcelDataModel();
            string retStatus = "";

            try
            {
                worldExcelModel.IsOrganization = formCollection["Organization"] == null ? false : true;
                worldExcelModel.IsCustomer     = formCollection["Customer"] == null ? false : true;
                worldExcelModel.IsProject      = formCollection["Project"] == null ? false : true;
                worldExcelModel.IsType         = formCollection["Type"] == null ? false : true;
                worldExcelModel.IsYear         = formCollection["Year"] == null ? false : true;
                worldExcelModel.IsStatus       = formCollection["Status"] == null ? false : true;
                //   worldExcelModel.IsCountry = formCollection["Country"] == null ? false : true;
                // worldExcelModel.IsEmail = formCollection["Email"] == null ? false : true;
                worldExcelModel.userid = Convert.ToInt32(Request.Cookies["UserId"].Value);

                ReadExcel readExcel = new ReadExcel();

                string path      = string.Empty;
                string filename  = string.Empty;
                string SavePath  = string.Empty;
                string Extension = string.Empty;
                foreach (string upload in Request.Files)
                {
                    SavePath = Guid.NewGuid().ToString();
                    path     = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
                    filename = Path.GetFileName(Request.Files[upload].FileName);

                    Extension = Path.GetExtension(Request.Files[upload].FileName);

                    if (Extension.ToLower() != ".xls" && Extension.ToLower() != ".xlsx")
                    {
                        TempData.Clear();
                        TempData.Add("ErrorMessage", "Please Upload Correct format.Please Download the Format");
                        return(RedirectToAction("UploadExcel"));
                    }

                    Request.Files[upload].SaveAs(Path.Combine(path, SavePath + Extension));
                }
                readExcel.ExcelPath       = Path.Combine(path, SavePath + Extension);
                worldExcelModel.ExcelPath = Path.Combine(SavePath + Extension).ToString();
                worldExcelModel.ExcelName = filename;
                retStatus = readExcel.ReadDataFromExcel();
                readExcel.AddData(worldExcelModel);

                TempData.Clear();
                TempData.Add("ErrorMessage", "Thank you for taking a step forward to glorifying yourself in WorlRef Map");
            }
            catch (Exception ex)
            {
                TempData.Clear();
                TempData.Add("ErrorMessage", ex.Message.ToString());//"Please Upload Correct format.Please Download the Format");
                return(RedirectToAction("UploadExcel"));
            }
            return(RedirectToAction("UploadExcel"));
        }
コード例 #2
0
        public ActionResult UploadExcel(FormCollection formCollection)
        {
            WorldRefExcelDataModel worldExcelModel = new WorldRefExcelDataModel();
            string retStatus = "";
            try
            {
                worldExcelModel.IsOrganization = formCollection["Organization"] == null ? false : true;
                worldExcelModel.IsCustomer = formCollection["Customer"] == null ? false : true;
                worldExcelModel.IsProject = formCollection["Project"] == null ? false : true;
                worldExcelModel.IsType = formCollection["Type"] == null ? false : true;
                worldExcelModel.IsYear = formCollection["Year"] == null ? false : true;
                worldExcelModel.IsStatus = formCollection["Status"] == null ? false : true;
                //   worldExcelModel.IsCountry = formCollection["Country"] == null ? false : true;
                // worldExcelModel.IsEmail = formCollection["Email"] == null ? false : true;
                worldExcelModel.userid = Convert.ToInt32(Request.Cookies["UserId"].Value);

                ReadExcel readExcel = new ReadExcel();

                string path = string.Empty;
                string filename = string.Empty;
                string SavePath = string.Empty;
                string Extension = string.Empty;
                foreach (string upload in Request.Files)
                {
                    SavePath = Guid.NewGuid().ToString();
                    path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
                    filename = Path.GetFileName(Request.Files[upload].FileName);

                    Extension = Path.GetExtension(Request.Files[upload].FileName);

                    if (Extension.ToLower() != ".xls" && Extension.ToLower() != ".xlsx")
                    {
                        TempData.Clear();
                        TempData.Add("ErrorMessage", "Please Upload Correct format.Please Download the Format");
                        return RedirectToAction("UploadExcel");
                    }

                    Request.Files[upload].SaveAs(Path.Combine(path, SavePath + Extension));
                }
                readExcel.ExcelPath = Path.Combine(path, SavePath + Extension);
                worldExcelModel.ExcelPath = Path.Combine(SavePath + Extension).ToString();
                worldExcelModel.ExcelName = filename;
                retStatus = readExcel.ReadDataFromExcel();
                readExcel.AddData(worldExcelModel);

                TempData.Clear();
                TempData.Add("ErrorMessage", "Thank you for taking a step forward to glorifying yourself in WorlRef Map");
            }
            catch (Exception ex)
            {
                TempData.Clear();
                TempData.Add("ErrorMessage", ex.Message.ToString());//"Please Upload Correct format.Please Download the Format");
                return RedirectToAction("UploadExcel");
            }
            return RedirectToAction("UploadExcel");
        }