TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
As Ak
NA
65
7.6k
Display data from latest text file into richtextbox
Sep 30 2020 9:41 PM
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?
Reply
Answers (
4
)
Download file from s3 bucket and save in a shared folder
Deserialize json string into object in c#