Windows Forms: How to Read text file and Sort list in C#
By FoxLearn 7/4/2017 9:55:52 PM 6.81K
How to read text (*.txt) file and sort list/array data in C#
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
- How to Create Multiple pages on the Form using Panel control in C#
- How to insert Math Equation to RichTextBox in C#
- How to Send and Receive email in Microsoft Outlook using C#
- How to Print Windows Form in C#
- How to Use Form Load and Button click Event in C#
- How to use Advanced Filter DataGridView in C#
- How to use TagListControl in C#
- How to use Error Provider in C#
Categories
Popular Posts
How to Download Chromedriver for Selenium
08/29/2024
C# Tutorial
07/20/2024
How to Download Microsoft SQL Server
06/22/2024
What is ARM architecture?
04/01/2024