protected void BtnUploadTxtFile_Click(object sender, EventArgs e) { if (textFileUpload.HasFile) { try { string[] validFileTypes = { "MIR", "IUR", "FLU" }; for (int i = 0; i < validFileTypes.Length; i++) { if (Path.GetExtension(textFileUpload.PostedFile.FileName) == "." + validFileTypes[i]) { if (textFileUpload.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(textFileUpload.FileName); textFileUpload.SaveAs(Server.MapPath(@"~/Admin/TextFiles/") + filename); LblFileStatus.Text = "Upload status: File uploaded!"; } else { LblFileStatus.Text = "Upload status: The file has to be less than 100 kb!"; } } else { // LblFileStatus.Text = "Upload status: Only MIR,IUR,FLU files are accepted!"; LblFileStatus.Text = "Upload status: File Uploaded Successfully."; } } } catch (Exception ex) { LblFileStatus.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; ExceptionLogging.SendExcepToDB(ex); } } try { string path = Server.MapPath(@"~/Admin/TextFiles"); DirectoryInfo dir = new DirectoryInfo(path); foreach (FileInfo flInfo in dir.GetFiles()) { if (flInfo.Extension == ".MIR") { ConvertMir c = new ConvertMir(); c.ConvertData(flInfo.DirectoryName + "\\" + flInfo.Name, path); Response.Redirect("ImportTicketList.aspx"); } } } catch (Exception ex) { LblFileStatus.Text = "MIR Reading " + ex.Message; ExceptionLogging.SendExcepToDB(ex); } }
protected void button2_Click(object sender, EventArgs e) { try { string content = ""; string FileName = ""; string Type = "getContent"; DataSet ds = objBALFilereading.GetFilesContent(Type); if (ds.Tables[0].Rows.Count > 0) { Stopwatch sw = new Stopwatch(); // Start The StopWatch ...From 000 sw.Start(); HttpPostedFile UploadedFiles; int i = 0; foreach (DataRow dtlRow in ds.Tables[0].Rows) { content = dtlRow["FileContent"].ToString(); FileName = dtlRow["FileName"].ToString(); // UploadedFiles = FileName; if (content != "") { ConvertMir c = new ConvertMir(); c.ConvertData(FileName, content); // DownloadTheFileToServer(FileName, i, content); } } sw.Stop(); //Writing Execution Time in label string ExecutionTimeTaken = string.Format("Minutes :{0}\nSeconds :{1}\n<br/> Mili seconds :{2}", sw.Elapsed.Minutes, sw.Elapsed.Seconds, sw.Elapsed.TotalMilliseconds); System.Threading.Thread.Sleep(sw.Elapsed.Minutes); label1.Text = ExecutionTimeTaken; //string path = Server.MapPath(@"uplaodfiles\pdf"); //DirectoryInfo dir = new DirectoryInfo(path); //foreach (FileInfo flInfo in dir.GetFiles()) //{ // if (flInfo.Extension == ".MIR") // { // ConvertMir c = new ConvertMir(); // c.ConvertData(flInfo.DirectoryName + "\\" + flInfo.Name, path); // label1.Text = "MIR Reading " + "Successfully"; // } //ClassWithTimer.TimerInClass InstanceOfTimer = new ClassWithTimer.TimerInClass(10, false); //InstanceOfTimer.StartTimer(); //for (int x = 0; x < 100; x++) //{ // // let's waste some time // Thread.Sleep(10); //} //InstanceOfTimer.StopTimer(); // } } } catch (Exception ex) { label1.Text = "MIR Reading " + ex.Message; ExceptionLogging.SendExcepToDB(ex); } }
protected void fileUpload_Click(object sender, EventArgs e) { try { int fileUploadCount = 0; int fileReadCount = 0; int fileCount = 0; int alreadyuploadfiles = 0; int unreadcount = 0; foreach (HttpPostedFile htfiles in mirfileUpload.PostedFiles) { try { fileCount++; if (htfiles.FileName != null) { getFileName = Path.GetFileName(htfiles.FileName); htfiles.SaveAs(Server.MapPath("~/UploadedFiles/" + getFileName)); fileUploadCount++; } string path = Server.MapPath(@"~/UploadedFiles"); DirectoryInfo dir = new DirectoryInfo(path); foreach (FileInfo flInfo in dir.GetFiles()) { if (flInfo.Extension == ".MIR") { ConvertMir c = new ConvertMir(); c.ConvertData(flInfo.DirectoryName + "\\" + flInfo.Name, path); fileReadCount++; MIRTable.Rows.Add(getFileName, DateTime.Now); } } } catch { File.Move(Server.MapPath(@"~/UploadedFiles/" + getFileName), Server.MapPath(@"~/ExistingFiles/" + getFileName)); alreadyuploadfiles++; } } string xmlString = string.Empty; using (TextWriter writer = new StringWriter()) { MIRTable.WriteXml(writer); xmlString = writer.ToString(); } SqlConnection objMySqlConn = _doUtilities.GetSqlConnection(); objMySqlConn.Open(); using (SqlBulkCopy SBC = new SqlBulkCopy(objMySqlConn)) { SBC.ColumnMappings.Add("Name", "Name"); SBC.ColumnMappings.Add("Date", "Dates"); SBC.DestinationTableName = "Testing"; SBC.WriteToServer(MIRTable); } DirectoryInfo info = new DirectoryInfo(Server.MapPath(@"~/ExistingFiles")); FileInfo[] files = info.GetFiles("*.MIR"); StringBuilder builder = new StringBuilder(); foreach (FileInfo file in files) { builder.Append(file).Append("<br/>"); } DirectoryInfo Dirinfo = new DirectoryInfo(Server.MapPath(@"~/UploadedFiles")); FileInfo[] Unreadfiles = Dirinfo.GetFiles("*.*"); StringBuilder builders = new StringBuilder(); foreach (FileInfo file in Unreadfiles) { builders.Append(file).Append("<br/>"); unreadcount++; File.Move(Server.MapPath("~/UploadedFiles/" + file), Server.MapPath("~/UnReadfiles/" + file)); } // Array.ForEach(Directory.GetFiles(Server.MapPath("~/UploadedFiles/")), File.Delete); Array.ForEach(Directory.GetFiles(Server.MapPath("~/ExistingFiles/")), File.Delete); int remainingfiles = fileCount - fileUploadCount; Uploadfile.Text = "ToTal Upload File =(" + fileUploadCount + ")<br/>"; readfile.Text = "ToTal Read File =(" + fileReadCount + ")<br/>"; remaining.Text = "UnUpload File =(" + remainingfiles + ")<br/>"; PreviousUplodfiles.Text = "Alreaddy Exist Upload File =(" + alreadyuploadfiles + ")<br/>"; filenames.Text = builder.ToString(); Unreadcount.Text = "Unread Files =(" + unreadcount + ")<br/>"; Unread.Text = builders.ToString(); } catch (Exception) { } }