Read from textfile and fill in textbox

67

Read from textfile and fill in textbox -

private void Form1_Load(object sender, EventArgs e)
{
    string line = "";
    System.IO.StreamReader file = new System.IO.StreamReader(@"FilePathWithNameAndExtension");
    while (!file.EndOfStream)
    {
        line += file.ReadLine() + "&"; //adding distinct value so that we can split them as a line.
    }
    string[] newLines = line.Split('&'); //storing lines in array.
    txtUserName.Text = newLines[1].Split(':')[1].ToString(); //newLines[1] represent to UserName that means we will extract from second line which is storing the username.
    txtCountry.Text = newLines[2].Split(':')[1].ToString();
    txtMemberShip.Text = newLines[3].Split(':')[1].ToString();
}

Comments

Submit
0 Comments