protected void btnDownloadEntries_Click(object sender, EventArgs e) { //ShowError2(true, "alert alert-danger", ""); if (ddlDownloadEntries.SelectedItem.Text.Trim() != "Select Device") { try { string filePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "CSV\\Test.CSV"; if (File.Exists(filePath)) { File.Delete(filePath); File.Create(filePath).Close(); } StringBuilder sb = new StringBuilder(); sb = bio.AttendanceLog(ddlDownloadEntries.SelectedItem.Text.Trim()); if (sb.Length != 0) { File.AppendAllText(filePath, sb.ToString()); if (ImportLog()) { string SP = "CALL `sp_GetLatest_Log`()"; int result = mc.ExecuteNonQuery(SP); ShowError2(true, "alert alert-success", result + " Record(s) are Downloaded Successfully"); } else ShowError2(true, "alert alert-danger", "File Importing Failed"); } else { if (bio.Msg == "") ShowError2(true, "alert alert-danger", "No Records for Processing"); else ShowError2(true, "alert alert-danger", bio.Msg); } } catch (Exception ex) { ShowError2(true, "alert alert-danger", ex.Message); } } } private bool ImportLog() { string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + "CSV\\Test.CSV"; path = path.Replace(@"\", @"//"); string query = "TRUNCATE TABLE tbl_attendancelog_tmp;LOAD DATA LOCAL INFILE '" + path + "' INTO TABLE tbl_attendancelog_tmp FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n' (IpAddress,EnrollNumber,dwVerifyMode,dwInOutMode,dwWorkcode,Record_Date,dwYear,dwMonth,dwDay,Record_Time,dwHour,dwMinute,dwSecond,Access_Time)"; int result = mc.ExecuteNonQuery(query); if (result > 0) return true; else return false; }