I want to display the latest text file that has been created in the richtextbox. The name for each text file is having a datetime.
I'm having a problem to display the data from latest txt file into the richtextbox.
This is the example of text file that has been created.
This is my code at this moment :
- private void CheckSN()
- {
- string strComputerName = Environment.MachineName.Substring(4);
- string Path = $@"Z:\FC\Share\PC\TR-{strComputerName}\SS\SN\{strComputerName}_DataFile.txt";
- string logPath = $@"Z:\FC\Share\PC\TR-{strComputerName}\SS\SysLog\SystemLog_{DateTime.Now:ddMMyyyy-hhmm}.txt";
- if (File.Exists(Path))
- {
- var data = File
- .ReadAllLines(Path)
- .Select(x => x.Split('='))
- .Where(x => x.Length > 1)
- .ToDictionary(x => x[0].Trim(), x => x[1]);
- using (StreamWriter tw = File.CreateText(logPath))
- {
- tw.WriteLine("Read the details..\n");
- tw.WriteLine("Name: {0}", data["Name"]);
- tw.WriteLine("Emp ID {0}", data["EmpID"]);
- tw.WriteLine("---------------------------------------------\n");
- }
- }
-
- private void richTextBox1_TextChanged(object sender, EventArgs e)
- {
- string strComputerName = Environment.MachineName.ToString().Substring(4);
- string logPath = $@"Z:\FC\Share\PC\TR-{strComputerName}\SS\SysLog\SystemLog.txt";
- richTextBox1.Text = File.ReadAllText(logPath, Encoding.Default);
- }
How can I display the latest text file that has been created (SystemLog_01102020-1040) in the richtextbox?