void UploadDataTable(StructUpload StructObj) { try { PlFU = new PlUpload(); PlFU.tableName = StructObj.TableName; bool tblCount = dlFU.CheckTable(PlFU); string Query = ""; int count = 0; if (tblCount == false) { Query += "Create Table " + PlFU.tableName + "("; foreach (DataColumn item in StructObj.BulkDT.Columns) { Query += item + " varchar(130)"; count++; Query += ", "; } Query += ")"; int Status = dlFU.DynamicTable(Query); } PlFU.FileName = StructObj.FileName; bool status = dlFU.FileNameCheck(PlFU); if (status == true) { dlFU.DeleteData(PlFU); } dlFU.BulkDataInsert(StructObj.BulkDT, StructObj.TableName); } catch (Exception ex) { if (DtErrorFILE == null) { DtErrorFILE = ErrorData(); } DataRow dr = DtErrorFILE.NewRow(); dr["ExcelName"] = StructObj.FileName; dr["TableName"] = StructObj.TableName; dr["Exception"] = ex.Message; DtErrorFILE.Rows.Add(dr); //lblException.Text += "<i class='fa fa-frown-o'></i> " + ++errorCount + ". "; //lblException.Text += "Problem In File Please Check File - " + StructObj.FileName + " This Is Not Create Because of - <br />" + ex.Message + "<br />"; //continue; } }
async void ImportAllFiles() { //string createNew = @"E:\Amrawati Projects\CSV_FIles\NewCreate\DIGI_DATA_S04_TO_W10"; string directory = @"E:\Amrawati Projects\CSV_FIles\Files\DIGI_DATA_S11_TO_S16"; string TableName = ""; int count = 0; foreach (var getFIles in Directory.GetFiles(directory)) { FileInfo currFile = new FileInfo(getFIles); string fileName = currFile.Name; string Sesion = ""; string getSession = fileName.Substring(fileName.LastIndexOf("_") + 1, 1).ToUpper(); string getYear = fileName.Substring(fileName.LastIndexOf("_") + 2, 2).ToUpper(); if (getYear != "13") { continue; } if (getSession == "S") { Sesion = "Summer"; } else if (getSession == "W") { Sesion = "Winter"; } try { string Tab = fileName; string File = ""; Tab = Tab.Substring(Tab.IndexOf("_")); File = Tab = Tab.Split('_')[1].Split('_')[0]; File = File.Replace("TAB", "FILE"); TableName = "Tbl_" + (Convert.ToInt16(getYear) + 2000) + "_" + Sesion + "_" + File; } catch (Exception ex) { if (DtErrorFILE == null) { DtErrorFILE = ErrorData(); } DataRow dr = DtErrorFILE.NewRow(); dr["ExcelName"] = "Invalid File Name - " + fileName; dr["TableName"] = ""; dr["Exception"] = ex.Message; DtErrorFILE.Rows.Add(dr); continue; } //Tab = Tab.Substring(3); StructUpload StructObj = ConvertCSVtoDataTable(currFile); StructObj.TableName = TableName; StructObj.FileName = fileName; if (StructObj.IsInError) { if (DtErrorFILE == null) { DtErrorFILE = ErrorData(); } DataRow dr = DtErrorFILE.NewRow(); dr["ExcelName"] = StructObj.FileName; dr["TableName"] = StructObj.TableName; dr["Exception"] = StructObj.ErrorMessage.Replace("<i class='fa fa-frown-o'></i> ", "Error : ").Replace("<br />", "~");//lblException.Text.Replace("<i class='fa fa-frown-o'></i> ", "Error : ").Replace("<br />","~"); DtErrorFILE.Rows.Add(dr); continue; } await System.Threading.Tasks.Task.Run(() => UploadDataTable(StructObj)); Thread.Sleep(1500); count++; lblCountFile.Text = count.ToString() + " Files Uploaded."; } CreateExcelError(); }