As Ak

As Ak

  • NA
  • 65
  • 6.8k

Display data from txt file to richtextbox

Sep 30 2020 1:23 AM
I want to be able to display data from .txt file up into a richtextbox.
 
This is the code I have at the moment:
  1. private void getDetails()
  2. {
  3.        
  4.     string Path = $@"Z:\IT\Shares\PC\DA-0123\SD\SDD\DataFile.txt";
  5.     if (File.Exists(Path))
  6.     {
  7.         var data = File
  8.         .ReadAllLines(Path)
  9.         .Select(x => x.Split('='))
  10.         .Where(x => x.Length > 1)
  11.         .ToDictionary(x => x[0].Trim(), x => x[1]);

  12.         using (StreamWriter tw = File.AppendText($@"Z:\IT\Shares\PC\DA-0123\SD\Files\SysLog.txt"))
  13.         {
  14.             //I want this data being displayed in richTextBox
  15.             tw.WriteLine("Details..\n");
  16.             tw.WriteLine("Name: {0}", data["Name"]);
  17.             tw.WriteLine("Emp ID: {0}", data["Emp ID"]);
  18.             tw.WriteLine("---------------------------------------------\n");
  19.        }
  20.    }
  21. }

Answers (1)