Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "ReadTextFileAndSort" and then click OK
Step 2: Design your form as below

Step 3: Add code to button click event handler as below
private void btnOpen_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Text Documents(*.txt)|*.txt", ValidateNames = true, Multiselect = false })
{
if (ofd.ShowDialog() == DialogResult.OK)
{
//Read text file
string[] lines = System.IO.File.ReadAllLines(ofd.FileName);
List<int> list = new List<int>();
foreach (string s in lines)
{
list.Add(Convert.ToInt32(s));
listReadFile.Items.Add(s);
}
//Sort list
list.Sort();
foreach (int x in list)
listSort.Items.Add(x);
}
}
}
VIDEO TUTORIALS