Step 1

Create an Empty Project -> Add Page
Step2

Add a Button and change the name to Browse .
Step3

Add a DataGridView Control Inside the Form -> Add a OpenFile Dialog in bottom of the Page.
Step4

Double click on Browse Button and go to the Code View.


Step5

Please follow the below code.
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
  4. {
  5. String sLine = "";
  6. try
  7. {
  8. //Pass the file you selected with the OpenFileDialog control to
  9. //the StreamReader Constructor.
  10. System.IO.StreamReader FileStream = new System.IO.StreamReader(openFileDialog1.FileName);
  11. //You must set the value to false when you are programatically adding rows to
  12. //a DataGridView. If you need to allow the user to add rows, you
  13. //can set the value back to true after you have populated the DataGridView
  14. dataGridView1.AllowUserToAddRows = false;
  15. //Read the first line of the text file
  16. sLine = FileStream.ReadLine();
  17. //The Split Command splits a string into an array, based on the delimiter you pass.
  18. //I chose to use a semi-colon for the text delimiter.
  19. //Any character can be used as a delimeter in the split command.
  20. string[] s = sLine.Split(';');
  21. //In this example, I placed the field names in the first row.
  22. //The for loop below is used to create the columns and use the text values in
  23. //the first row for the column headings.
  24. for (int i = 0; i <= s.Count() - 1; i++)
  25. {
  26. DataGridViewColumn colHold = new DataGridViewTextBoxColumn();
  27. colHold.Name = "col" + System.Convert.ToString(i);
  28. colHold.HeaderText = s[i].ToString();
  29. dataGridView1.Columns.Add(colHold);
  30. }
  31. //Read the next line in the text file in order to pass it to the
  32. //while loop below
  33. sLine = FileStream.ReadLine();
  34. //The while loop reads each line of text.
  35. while (sLine != null)
  36. {
  37. //Adds a new row to the DataGridView for each line of text.
  38. dataGridView1.Rows.Add();
  39. //This for loop loops through the array in order to retrieve each
  40. //line of text.
  41. for (int i = 0; i <= s.Count() - 1; i++)
  42. {
  43. //Splits each line in the text file into a string array
  44. s = sLine.Split(';');
  45. //Sets the value of the cell to the value of the text retreived from the text file.
  46. dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[i].Value = s[i].ToString();
  47. }
  48. sLine = FileStream.ReadLine();
  49. }
  50. //Close the selected text file.
  51. FileStream.Close();
  52. }
  53. catch (Exception err)
  54. {
  55. //Display any errors in a Message Box.
  56. System.Windows.Forms.MessageBox.Show("Error: " + err.Message, "Program Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  57. }
  58. }
  59. }
Step6

Once everything is finished, then click on Debug button and see the output .