public ICrudManager SaveUploadedFile(string systemFolder, string fileNameNoExtension, ICrudManager crudManager) { var file = _sessionContext.RetrieveUploadedFile(); if (file == null || file.ContentLength <= 0 || crudManager.HasFailingReport()) { return(crudManager); } var folderPath = _sessionContext.MapPath(systemFolder); var extension = file.FileName.Substring(file.FileName.LastIndexOf(".")); var newName = fileNameNoExtension + extension; string filePath = folderPath + "\\" + newName; var exists = Directory.Exists(folderPath); if (!exists) { Directory.CreateDirectory(folderPath); } //TODO insert rules engine here var fileExists = File.Exists(filePath); CrudReport crudReport = new CrudReport(); if (fileExists) { crudReport.AddErrorInfo(new ErrorInfo(null, WebLocalizationKeys.FILE_ALREADY_EXISTS.ToString())); crudManager.AddCrudReport(crudReport); return(crudManager); } file.SaveAs(filePath); crudReport.Success = true; crudManager.AddCrudReport(crudReport); return(crudManager); }
public ICrudManager SaveUploadedFile(string systemFolder, string fileNameNoExtension, ICrudManager crudManager) { var file = _sessionContext.RetrieveUploadedFile(); if (file == null || file.ContentLength <= 0 || crudManager.HasFailingReport()) return crudManager; var folderPath = _sessionContext.MapPath(systemFolder); var extension = file.FileName.Substring(file.FileName.LastIndexOf(".")); var newName = fileNameNoExtension + extension; string filePath = folderPath + "\\" + newName; var exists = Directory.Exists(folderPath); if (!exists) { Directory.CreateDirectory(folderPath); } //TODO insert rules engine here var fileExists = File.Exists(filePath); CrudReport crudReport= new CrudReport(); if (fileExists) { crudReport.AddErrorInfo(new ErrorInfo(null,WebLocalizationKeys.FILE_ALREADY_EXISTS.ToString())); crudManager.AddCrudReport(crudReport); return crudManager; } file.SaveAs(filePath); crudReport.Success = true; crudManager.AddCrudReport(crudReport); return crudManager; }