public ResponseModel BulkUploadCategory(IFormFile File, int CategoryFor = 1) { string downloadFilePath = string.Empty; string bulkUploadFilesPath = string.Empty; bool errorfilesaved = false; bool successFilesaved = false; int count = 0; MasterCaller masterCaller = new MasterCaller(); SettingsCaller fileU = new SettingsCaller(); ResponseModel objResponseModel = new ResponseModel(); int statusCode = 0; string statusMessage = ""; DataSet dataSetCSV = new DataSet(); string fileName = ""; string finalAttchment = ""; string timeStamp = DateTime.Now.ToString("ddmmyyyyhhssfff"); string[] filesName = null; List <string> CSVlist = new List <string>(); try { var files = Request.Form.Files; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { fileName += files[i].FileName.Replace(".", timeStamp + ".") + ","; } finalAttchment = fileName.TrimEnd(','); } var Keys = Request.Form; var exePath = Path.GetDirectoryName(System.Reflection .Assembly.GetExecutingAssembly().CodeBase); Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)"); var appRoot = appPathMatcher.Match(exePath).Value; string Folderpath = appRoot + "\\" + UploadedBulkFile; if (files.Count > 0) { filesName = finalAttchment.Split(","); for (int i = 0; i < files.Count; i++) { using (var ms = new MemoryStream()) { files[i].CopyTo(ms); var fileBytes = ms.ToArray(); MemoryStream msfile = new MemoryStream(fileBytes); FileStream docFile = new FileStream(Folderpath + "\\" + filesName[i], FileMode.Create, FileAccess.Write); msfile.WriteTo(docFile); docFile.Close(); ms.Close(); msfile.Close(); string s = Convert.ToBase64String(fileBytes); byte[] a = Convert.FromBase64String(s); // act on the Base64 data } } } string token = Convert.ToString(Request.Headers["X-Authorized-Token"]); Authenticate authenticate = new Authenticate(); authenticate = SecurityService.GetAuthenticateDataFromTokenCache(Cache, SecurityService.DecryptStringAES(token)); #region FilePath bulkUploadFilesPath = appRoot + "\\" + "BulkUpload\\UploadFiles" + "\\" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)CategoryFor); downloadFilePath = appRoot + "\\" + "BulkUpload\\DownloadFiles" + "\\" + CommonFunction.GetEnumDescription((EnumMaster.FileUpload)CategoryFor); #endregion dataSetCSV = CommonService.csvToDataSet(Folderpath + "\\" + finalAttchment); CSVlist = masterCaller.CategoryBulkUpload(new CategoryServices(Cache, Db), authenticate.TenantId, authenticate.UserMasterID, CategoryFor, dataSetCSV); #region Create Error and Succes files and Insert in FileUploadLog if (!string.IsNullOrEmpty(CSVlist[0])) { errorfilesaved = CommonService.SaveFile(downloadFilePath + "\\Category\\ Error" + "\\" + "CategoryErrorFile.csv", CSVlist[0]); } if (!string.IsNullOrEmpty(CSVlist[1])) { successFilesaved = CommonService.SaveFile(downloadFilePath + "\\Category\\Success" + "\\" + "CategorySuccessFile.csv", CSVlist[1]); } count = fileU.CreateFileUploadLog(new FileUploadService(Cache, Db), authenticate.TenantId, "Categorymaster.csv", errorfilesaved, "CategoryErrorFile.csv", "CategorySuccessFile.csv", authenticate.UserMasterID, "Category", downloadFilePath + "\\Category\\Error" + "\\" + "CategoryErrorFile.csv", downloadFilePath + "\\Category\\ Success" + "\\" + "CategorySuccessFile.csv", CategoryFor ); #endregion statusCode = count > 0 ? (int)EnumMaster.StatusCode.Success : (int)EnumMaster.StatusCode.RecordNotFound; statusMessage = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)statusCode); objResponseModel.Status = true; objResponseModel.StatusCode = statusCode; objResponseModel.Message = statusMessage; objResponseModel.ResponseData = CSVlist.Count; } catch (Exception) { throw; } return(objResponseModel); }