public UploadedFiles UpdateUplodedFileDetail(UploadedFiles uploadedFile, int RowCount) { try { using (SqlConnection con = _databaseFactory.GetDBConnection()) { using (SqlCommand cmd = new SqlCommand()) { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Connection = con; cmd.CommandText = "[Accounts].[UpdateUploadedFile]"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = uploadedFile.ID; cmd.Parameters.Add("@FilePath", SqlDbType.NVarChar, 250).Value = uploadedFile.FilePath; cmd.Parameters.Add("@FileType", SqlDbType.NVarChar, 50).Value = uploadedFile.FileType; cmd.Parameters.Add("@RecordCount", SqlDbType.Int).Value = uploadedFile.RecordCount = RowCount; cmd.Parameters.Add("@FileStatus", SqlDbType.NVarChar, 50).Value = uploadedFile.FileStatus; cmd.Parameters.Add("@UpdatedBy", SqlDbType.NVarChar, 250).Value = uploadedFile.CommonObj.UpdatedBy; cmd.Parameters.Add("@UpdatedDate", SqlDbType.DateTime).Value = uploadedFile.CommonObj.UpdatedDate; cmd.ExecuteNonQuery(); } } return(uploadedFile); } catch (Exception ex) { throw ex; } }
void DeleteFileButton_Click(object sender, EventArgs e) { var button = sender as Button; var path = button.CommandName; var node = Node.LoadNode(path); if (node == null) { ErrorLabel.Text = "Cannot find content!"; ErrorPlaceHolder.Visible = true; return; } // check: was this file uploaded by me? if yes, delete. Otherwise don't allow delete. if (node.CreatedById == User.Current.Id) { Node.ForceDelete(path); _fileListElements = _fileListElements.Where(a => a.Path != path).ToList(); if (_fileListElements.Count == 0) { _fileListElements = null; } UploadedFiles.DataSource = _fileListElements; UploadedFiles.DataBind(); } else { ErrorLabel.Text = "This content cannot be deleted since it was created by another user!"; ErrorPlaceHolder.Visible = true; } }
public UploadedFiles ValidateImportData(UploadedFiles uploadedFile, string filePath) { List <ImportOtherExpenses> removedData = new List <ImportOtherExpenses>(); string extension = Path.GetExtension(filePath); try { switch (extension) { case ".xls": //Excel 97-03 List <ImportOtherExpenses> ExcelDataXls = _importOtherExpensesRepository.GetExcelDataToList(uploadedFile, filePath, 1); uploadedFile.RecordCount = ExcelDataXls.Count; removedData = _importOtherExpensesRepository.InsertValidateExpenseData(ExcelDataXls, false); uploadedFile.RemovedDataCount = removedData.Count; uploadedFile.ImportExpenseList = (removedData.Count != 0) ? removedData : ExcelDataXls; break; case ".xlsx": //Excel 07 to 12 List <ImportOtherExpenses> ExcelDataXlsx = _importOtherExpensesRepository.GetExcelDataToList(uploadedFile, filePath, 2); uploadedFile.RecordCount = ExcelDataXlsx.Count; removedData = _importOtherExpensesRepository.InsertValidateExpenseData(ExcelDataXlsx, false); uploadedFile.RemovedDataCount = removedData.Count; uploadedFile.ImportExpenseList = (removedData.Count != 0) ? removedData : ExcelDataXlsx; break; } } catch (Exception ex) { throw ex; } return(uploadedFile); }
private void AddDocuments(ref Artwork artwork, IEnumerable <HttpPostedFileBase> artworkFiles) { foreach (var doc in artworkFiles) { if (doc != null) { string mimeType = doc.ContentType; string fileName = Path.GetFileName(doc.FileName); int fileLength = doc.ContentLength; if (!(fileName == "" || fileLength == 0)) { Stream docfileStream = doc.InputStream; byte[] docfileData = new byte[fileLength]; docfileStream.Read(docfileData, 0, fileLength); UploadedFiles newFile = new UploadedFiles { FileContent = docfileData, MimeType = mimeType, FileName = fileName }; artwork.UploadedFiles.Add(newFile); } } } }
public async Task ReplaceAsync(string token, Stream stream, Dictionary <string, string> parameters) { var user = await DWKitRuntime.Security.GetCurrentUserAsync(); string name = null; if (parameters.ContainsKey(FileProperties.Name)) { name = parameters[FileProperties.Name]; } string contentType = null; if (parameters.ContainsKey(FileProperties.ContentType)) { contentType = parameters[FileProperties.ContentType]; } UploadedFiles file; if (Guid.TryParse(token, out Guid id)) { file = await UploadedFiles.SelectByKey(id); } else { file = new UploadedFiles() { Id = id, CreatedBy = user?.Name, CreatedDate = DateTime.Now }; } if (name != null) { file.Name = name; } if (file.ContentType != null) { file.ContentType = contentType; } file.UpdatedBy = user?.Name; file.UpdatedDate = DateTime.Now; file.Used = true; file.Data = new byte[stream.Length]; if (stream != null) { await stream.WriteAsync(file.Data, 0, (int)stream.Length); file.AttachmentLength = stream.Length; } await file.ApplyAsync(); }
public int SetFiles(UploadedFiles Obj, string EmployeeId) { try { return(_workorderems.spSetFileUpload(Obj.Action, Obj.Id, Obj.FileEmployeeId, Obj.FileId, Obj.FileName, Obj.AttachedFileName, EmployeeId, "Y")); } catch (Exception ex) { throw; } }
public async Task <bool> RemoveAsync(string token) { Guid id; if (Guid.TryParse(token, out id)) { await UploadedFiles.Remove <Guid>(id); return(true); } return(false); }
public ActionResult UploadFiles(IEnumerable <HttpPostedFileBase> attachments) { // The Name of the Upload component is "attachments" foreach (var file in attachments) { // Some browsers send file names with full path. We only care about the file name. var fileName = Path.GetFileName(file.FileName); var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName); file.SaveAs(destinationPath); UploadedFiles.Add(destinationPath); } // Return an empty string to signify success return(Content("")); }
public List <UploadedFiles> GetAllUploadedFile() { List <UploadedFiles> uploadedFileList = new List <UploadedFiles>(); try { Settings setting = new Settings(); string excessPath = "/Content/Uploads/ImportedFiles/"; using (SqlConnection con = _databaseFactory.GetDBConnection()) { using (SqlCommand cmd = new SqlCommand()) { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Connection = con; cmd.CommandText = "[Accounts].[GetAllUploadedFile]"; cmd.CommandType = CommandType.StoredProcedure; using (SqlDataReader sdr = cmd.ExecuteReader()) { if ((sdr != null) && (sdr.HasRows)) { while (sdr.Read()) { UploadedFiles uploadedFile = new UploadedFiles(); { uploadedFile.ID = (sdr["ID"].ToString() != "" ? Guid.Parse(sdr["ID"].ToString()) : uploadedFile.ID); uploadedFile.FileType = (sdr["FileType"].ToString() != "" ? (sdr["FileType"].ToString()) : uploadedFile.FileType); uploadedFile.FilePath = (sdr["FilePath"].ToString() != "" ? sdr["FilePath"].ToString().Replace(excessPath, "") : uploadedFile.FilePath); uploadedFile.RecordCount = (sdr["RecordCount"].ToString() != "" ? int.Parse(sdr["RecordCount"].ToString()) : uploadedFile.RecordCount); uploadedFile.FileStatus = (sdr["FileStatus"].ToString() != "" ? sdr["FileStatus"].ToString() : uploadedFile.FileStatus); uploadedFile.CreatedDate = (sdr["CreatedDate"]).ToString() != "" ? DateTime.Parse(sdr["CreatedDate"].ToString()).ToString(setting.dateformat) : sdr["CreatedDate"].ToString(); } uploadedFileList.Add(uploadedFile); } } } } } } catch (Exception ex) { throw ex; } return(uploadedFileList); }
public UploadedFiles ImportDataToDB(UploadedFiles uploadedFile, string filePath) { UploadedFiles uploadFileObj = new UploadedFiles(); List <ImportOtherExpenses> removedData = new List <ImportOtherExpenses>(); string extension = Path.GetExtension(filePath); decimal totalAmount = 0; try { switch (extension) { case ".xls": //Excel 97-03 List <ImportOtherExpenses> ExcelDataXls = _importOtherExpensesRepository.GetExcelDataToList(uploadedFile, filePath, 1); foreach (ImportOtherExpenses ExcelData in ExcelDataXls) { totalAmount = totalAmount + ExcelData.Amount; } removedData = _importOtherExpensesRepository.InsertValidateExpenseData(ExcelDataXls, true); uploadedFile.FileStatus = "Successfully Imported"; uploadFileObj = _importOtherExpensesRepository.UpdateUplodedFileDetail(uploadedFile, ExcelDataXls.Count - removedData.Count); uploadFileObj.RemovedDataCount = removedData.Count; uploadFileObj.ImportExpenseList = (removedData.Count != 0) ? removedData : ExcelDataXls; uploadFileObj.TotalAmount = totalAmount; break; case ".xlsx": //Excel 07 to 12 List <ImportOtherExpenses> ExcelDataXlsx = _importOtherExpensesRepository.GetExcelDataToList(uploadedFile, filePath, 2); foreach (ImportOtherExpenses ExcelData in ExcelDataXlsx) { totalAmount = totalAmount + ExcelData.Amount; } removedData = _importOtherExpensesRepository.InsertValidateExpenseData(ExcelDataXlsx, true); uploadedFile.FileStatus = "Successfully Imported"; uploadFileObj = _importOtherExpensesRepository.UpdateUplodedFileDetail(uploadedFile, ExcelDataXlsx.Count); uploadFileObj.RemovedDataCount = removedData.Count; uploadFileObj.ImportExpenseList = (removedData.Count != 0) ? removedData : ExcelDataXlsx; uploadFileObj.TotalAmount = totalAmount; break; } } catch (Exception ex) { throw ex; } return(uploadFileObj); }
/// <summary> /// ファイルのアップロード /// </summary> /// <param name="srcPath">アップロード対象ファイル</param> private async Task UploadFileAsync(string srcPath) { string relPath = srcPath.Substring(BaseDir.Length + 1); string dstPath = Path.Combine(UploadInfo.Target.Folder, relPath); // ディレクトリの場合 if (Directory.Exists(srcPath)) { await CreateDirectoryAsync(dstPath); return; } // アップロード一覧はHashSetにしたので常にユニーク UploadedFiles.Add(relPath); bool doCopy = true; bool existFile = File.Exists(dstPath); // 既存ファイルはタイムスタンプをコピー条件にして不用意に古いものがアップされないようにする if (existFile) { var result = await CompareFileTimeAsync(srcPath, dstPath); doCopy = result > 0; } if (doCopy) { var dstDir = Path.GetDirectoryName(dstPath); if (!Directory.Exists(dstDir)) { await CreateDirectoryAsync(dstDir); } var flagStr = (existFile) ? "Copy:" : "New:"; await Pane.WriteLineAsync($"{flagStr} {relPath} -> {dstPath}"); #if EXEC_UPLOAD await Task.Run(() => { // ファイルをコピーする。もし、リードオンリー属性がついていたら強制で排除する(VSS対応時の名残) File.Copy(srcPath, dstPath, true); FileAttributes fileAttr = File.GetAttributes(srcPath); fileAttr &= ~FileAttributes.ReadOnly; File.SetAttributes(dstPath, fileAttr); }); #endif } }
/// <summary> /// Created By :Ashwajit Bansod /// Created Date : 10-Oct-2019 /// Created For : To save file /// </summary> /// <param name="Obj"></param> /// <param name="EmployeeId"></param> /// <returns></returns> public bool SaveFile(UploadedFiles Obj, string EmployeeId) { var _repo = new FillableFormRepository(); bool isSaved = false; try { Obj.Action = Obj.Id != null ? "U" : "I"; var save = _repo.SetFiles(Obj, EmployeeId); isSaved = true; } catch (Exception ex) { isSaved = false; Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public bool SaveFile(UploadedFiles Obj, string EmployeeId)", "Exception While Saving File.", Obj); throw; } return(isSaved); }
protected override void CreateChildControls() { ErrorPlaceHolder.Visible = false; if (Upload.HasFile) { try { this.SaveFile(); } catch (Exception ex) { ErrorLabel.Text = ex.Message; ErrorPlaceHolder.Visible = true; } } UploadedFiles.DataSource = _fileListElements; UploadedFiles.ItemDataBound += new RepeaterItemEventHandler(UploadedFiles_ItemDataBound); UploadedFiles.DataBind(); }
public async Task <string> AddAsync(Stream stream, Dictionary <string, object> parameters, bool used = true) { var user = await DWKitRuntime.Security.GetCurrentUserAsync(); string name = string.Empty; if (parameters.ContainsKey(FileProperties.Name)) { name = parameters[FileProperties.Name] as string; } string contentType = string.Empty; if (parameters.ContainsKey(FileProperties.ContentType)) { contentType = parameters[FileProperties.ContentType] as string; } var file = new UploadedFiles() { Id = DWKitRuntime.DbProvider.GenerateGuid(), Name = name, AttachmentLength = stream.Length, ContentType = contentType, CreatedBy = user?.Name, CreatedDate = DateTime.Now, Used = used, Properties = JsonConvert.SerializeObject(parameters) }; file.Data = new byte[stream.Length]; await stream.ReadAsync(file.Data, 0, (int)stream.Length); await file.ApplyAsync(); return(file.Id.ToString("N")); }
public async Task <(Stream Stream, Dictionary <string, string> Properties)> GetAsync(string token) { Guid id; if (Guid.TryParse(token, out id)) { var item = await UploadedFiles.SelectByKey(id); var stream = new MemoryStream(item.Data); var dic = new Dictionary <string, string> { { FileProperties.Name, item.Name }, { FileProperties.Length, item.AttachmentLength.ToString() }, { FileProperties.ContentType, item.ContentType }, { FileProperties.CreatedBy, item.CreatedBy }, { FileProperties.CreatedDate, item.CreatedDate.ToString() }, { FileProperties.UpdatedBy, item.UpdatedBy }, { FileProperties.UpdatedDate, item.UpdatedDate.ToString() } }; return(Stream : stream, Properties : dic); } return(Stream : null, Properties : null); }
public UploadedFiles InsertAttachment(UploadedFiles uploadedFile) { try { SqlParameter outputID = null; using (SqlConnection con = _databaseFactory.GetDBConnection()) { using (SqlCommand cmd = new SqlCommand()) { if (con.State == ConnectionState.Closed) { con.Open(); } cmd.Connection = con; cmd.CommandText = "[Accounts].[InsertUploadedFile]"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@FilePath", SqlDbType.NVarChar, 250).Value = uploadedFile.FilePath; cmd.Parameters.Add("@FileType", SqlDbType.NVarChar, 50).Value = uploadedFile.FileType; cmd.Parameters.Add("@RecordCount", SqlDbType.Int).Value = uploadedFile.RecordCount; cmd.Parameters.Add("@CreatedBy", SqlDbType.NVarChar, 250).Value = uploadedFile.CommonObj.CreatedBy; cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = uploadedFile.CommonObj.CreatedDate; cmd.Parameters.Add("@FileStatus", SqlDbType.NVarChar, 50).Value = uploadedFile.FileStatus; outputID = cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier); outputID.Direction = ParameterDirection.Output; cmd.ExecuteNonQuery(); } uploadedFile.ID = Guid.Parse(outputID.Value.ToString()); } } catch (Exception Ex) { throw Ex; } return(uploadedFile); }
public void ShouldBeAbleToCreateJobModelTypes() { var created = from simpleCommand in Command.NewSimpleCommand("echo 'Hello, World!'").Lift("simple-command") from parameterizedCommand in Command.NewParametrizedCommand( new ParametrizedCommand( "echo 'Hello, %user%'", new[] { "user" }.ToFSharpList())).Lift() from tryWithCatch in new CommandWithErrorHandler(parameterizedCommand, FSharpOption <Command> .Some(simpleCommand)).Lift( "try-with-catch") from tryWithoutCatch in new CommandWithErrorHandler(simpleCommand, FSharpOption <Command> .None).Lift("try-without-catch") from commandSet0 in CommandSet.Zero.Lift() from commandSet in new CommandSet( new[] { tryWithCatch }.ToFSharpList(), new[] { simpleCommand }.ToFSharpList()).Lift() from localFiles0 in LocalFiles.Zero.Lift() from localFiles in LocalFiles.NewLocalFiles( new[] { new FileInfo("temp.txt") }.ToFSharpList()).Lift() from uploadedFiles0 in UploadedFiles.Zero.Lift() from uploadedFiles in UploadedFiles.NewUploadedFiles( new[] { new ResourceFile("blobSource", "blobPath") }.ToFSharpList()).Lift("uploaded-files") from workloadUnitTemplate0 in WorkloadUnitTemplate.Zero.Lift() from workloadUnitTemplate in new WorkloadUnitTemplate(commandSet, localFiles, false).Lift() from workloadArguments0 in WorkloadArguments.Zero.Lift() from workloadArguments in WorkloadArguments.NewWorkloadArguments( new Dictionary <string, FSharpList <string> > { { "users", new[] { "john", "pradeep" }.ToFSharpList() } }.ToFSharpMap()).Lift() from workloadSpecification in new WorkloadSpecification( new[] { workloadUnitTemplate }.ToFSharpList(), LocalFiles.Zero, workloadArguments).Lift() from taskName in TaskName.NewTaskName("simple-task").Lift() from taskArguments0 in TaskArguments.Zero.Lift() from taskArguments in TaskArguments.NewTaskArguments( new Dictionary <string, string> { { "name", "john" } }.ToFSharpMap()).Lift() from defaultTaskSpecification in TaskSpecification.Zero.Lift() from jobName in JobName.NewJobName("simple-job").Lift() from nullJobPriority in JobPriority.NewJobPriority(null).Lift() from jobPriority in JobPriority.NewJobPriority(10).Lift() from defaultJobSpecification in JobSpecification.Zero.Lift() select "done"; Assert.AreEqual("done", created.Value); }
public List <ImportOtherExpenses> GetExcelDataToList(UploadedFiles fileUploadObj, string fname, int flag) { List <ImportOtherExpenses> importOtherExpenseList = new List <ImportOtherExpenses>(); DataTable ExcelData = null; try { //Insert all values from excel to datatable using (OleDbConnection excel_con = _databaseFactory.GetOleDBConnection(flag, fname)) { excel_con.Open(); string sheet1 = "DataSheet$"; ExcelData = new DataTable(); //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default. OleDbCommand cmdExcel = new OleDbCommand(); cmdExcel.Connection = excel_con; cmdExcel.CommandText = "SELECT * From [" + sheet1 + "]"; OleDbDataAdapter oda = new OleDbDataAdapter(); oda.SelectCommand = cmdExcel; oda.Fill(ExcelData); excel_con.Close(); } //To remove all Empty Row from DataTable ExcelData = ExcelData .Rows.Cast <DataRow>() .Where(row => !row.ItemArray.All(field => field is DBNull || string.IsNullOrWhiteSpace(field as string))) .CopyToDataTable(); ExcelData.Columns.Add("ErrorRow", typeof(int)); int count = 1; foreach (DataRow row in ExcelData.Rows) { row["ErrorRow"] = ++count; } for (int i = 0; i < ExcelData.Rows.Count; i++) { DataRow row = ExcelData.Rows[i]; ImportOtherExpenses importOtherExpenseObj = new ImportOtherExpenses(); importOtherExpenseObj.ExpenseDate = row["Date"].ToString().Trim(); importOtherExpenseObj.AccountCode = row["AccountCode"].ToString().Trim(); importOtherExpenseObj.Company = row["ExpCompany"].ToString().Trim(); importOtherExpenseObj.EmpCode = row["EmpCode"].ToString().Trim(); importOtherExpenseObj.EmpName = row["EmpName"].ToString().Trim(); importOtherExpenseObj.EmpCompany = row["EmpCompany"].ToString().Trim(); importOtherExpenseObj.PaymentMode = row["PayMode"].ToString().Trim(); importOtherExpenseObj.ExpenseRef = row["PayReference"].ToString().Trim(); importOtherExpenseObj.Description = row["Description"].ToString().Trim(); importOtherExpenseObj.Amount = Decimal.Parse(row["Amount"].ToString().Trim()); importOtherExpenseObj.CommonObj = fileUploadObj.CommonObj; importOtherExpenseObj.ErrorRow = int.Parse(row["ErrorRow"].ToString()); importOtherExpenseList.Add(importOtherExpenseObj); } } catch (Exception ex) { if (ex.Message.Equals("Column 'Date' does not belong to table .")) { throw new Exception("Invalid Excel File Uploaded"); } else if (ex.Message.Equals("'Data$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.")) { throw new Exception("The sheet Data is missing."); } throw ex; } return(importOtherExpenseList); }
public UploadedFiles InsertAttachment(UploadedFiles uploadedFile) { uploadedFile.FileStatus = "Unvalidated"; return(_importOtherExpensesRepository.InsertAttachment(uploadedFile)); }
public ActionResult UploadFile() { UploadedFilesViewModel uploadedFilesVM = new UploadedFilesViewModel(); UploadedFiles uploadedFilesObj = new UploadedFiles(); // Get all files from Request object HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files[0]; try { AppUA appUA = Session["AppUA"] as AppUA; // Checking no of files injected in Request object if (Request.Files.Count > 0) { string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } if (ValidateFileName(fname) != "success") { return(Json(new { Result = "WARNING", Message = "Invalid Filename!" })); } if (System.IO.File.Exists(Path.Combine(Server.MapPath("~/Content/Uploads/ImportedFiles/"), fname)) == false) { uploadedFilesVM.FilePath = ChangeFilePath(fname); } else { return(Json(new { Result = "ERROR", Message = "File uploaded recently" })); } UploadedFilesViewModel uploadedFiles = Mapper.Map <UploadedFiles, UploadedFilesViewModel>(( from i in _importOtherExpensesBusiness.GetAllUploadedFile() where uploadedFilesVM.FilePath.Equals("/Content/Uploads/ImportedFiles/" + i.FilePath) select i).ToArray()[0] ); uploadedFiles.CommonObj = new CommonViewModel(); uploadedFiles.CommonObj.CreatedBy = appUA.UserName; uploadedFiles.CommonObj.CreatedDate = common.GetCurrentDateTime(); uploadedFiles.CommonObj.UpdatedBy = appUA.UserName; uploadedFiles.CommonObj.UpdatedDate = common.GetCurrentDateTime(); fname = Path.Combine(Server.MapPath("~/Content/Uploads/ImportedFiles/"), fname); file.SaveAs(fname); uploadedFilesObj = _importOtherExpensesBusiness.ImportDataToDB(Mapper.Map <UploadedFilesViewModel, UploadedFiles>(uploadedFiles), fname); } else { return(Json(new { Result = "WARNING", Message = "No files selected." })); } return(Json(new { Result = "OK", Message = "File Uploaded Successfully!", ImportExpenseList = JsonConvert.SerializeObject(uploadedFilesObj.ImportExpenseList), TotalCount = uploadedFilesObj.RecordCount, RemovedCount = uploadedFilesObj.RemovedDataCount, FileName = Path.GetFileName(uploadedFilesObj.FilePath), TotalAmount = uploadedFilesObj.TotalAmount })); } catch (Exception ex) { return(Json(new { Result = "EXCEPTION", Message = ex.Message })); } }
public ActionResult ValidateUploadFile() { UploadedFilesViewModel uploadedFilesVM = new UploadedFilesViewModel(); UploadedFiles uploadFilesObj = new UploadedFiles(); // Get all files from Request object HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files[0]; try { AppUA appUA = Session["AppUA"] as AppUA; // Checking no of files injected in Request object if (Request.Files.Count > 0) { string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = file.FileName; } if (ValidateFileName(fname) != "success") { return(Json(new { Result = "WARNING", Message = "Invalid File, Either filename or filetype mismatch !" })); } if (System.IO.File.Exists(Path.Combine(Server.MapPath("~/Content/Uploads/ImportedFiles/"), fname)) == false) { uploadedFilesVM.FilePath = ChangeFilePath(fname); } else { return(Json(new { Result = "ERROR", Message = "File uploaded recently" })); } uploadedFilesVM.CommonObj = new CommonViewModel(); uploadedFilesVM.CommonObj.CreatedBy = appUA.UserName; uploadedFilesVM.CommonObj.CreatedDate = common.GetCurrentDateTime(); uploadedFilesVM.CommonObj.UpdatedBy = appUA.UserName; uploadedFilesVM.CommonObj.UpdatedDate = common.GetCurrentDateTime(); uploadedFilesVM.FileType = "OtherExpenses"; List <UploadedFiles> uploadedFileList = _importOtherExpensesBusiness.GetAllUploadedFile(); object fileExist = (from i in uploadedFileList where uploadedFilesVM.FilePath.Equals("/Content/Uploads/ImportedFiles/" + i.FilePath) && i.FileStatus.Equals("Successfully Imported") select i).FirstOrDefault(); if (fileExist != null) { return(Json(new { Result = "ERROR", Message = "File Already Imported!" })); } UploadedFiles uploadedFiles = _importOtherExpensesBusiness.InsertAttachment(Mapper.Map <UploadedFilesViewModel, UploadedFiles>(uploadedFilesVM)); fname = Path.Combine(Server.MapPath("~/Content/Uploads/ImportedFiles/"), fname); file.SaveAs(fname); uploadFilesObj = _importOtherExpensesBusiness.ValidateImportData(uploadedFiles, fname); System.IO.File.Delete(fname); } else { return(Json(new { Result = "WARNING", Message = "No files selected. Select one and upload" })); } int Count = uploadFilesObj.ImportExpenseList != null ? uploadFilesObj.RecordCount - uploadFilesObj.ImportExpenseList.Count : uploadFilesObj.RecordCount; return(Json(new { Result = "OK", Message = "File Validated Successfully!", ImportExpenseList = JsonConvert.SerializeObject(uploadFilesObj.ImportExpenseList), TotalCount = uploadFilesObj.RecordCount, RemovedCount = uploadFilesObj.RemovedDataCount, filename = Path.GetFileName(uploadFilesObj.FilePath) })); } catch (Exception ex) { System.IO.File.Delete(Server.MapPath("~/Content/Uploads/ImportedFiles/" + file.FileName)); return(Json(new { Result = "EXCEPTION", Message = ex.Message })); } }