05 Laboratory Exercise 2
05 Laboratory Exercise 2
Laboratory Exercise
Reading a File
Objectives:
Software Requirement:
Procedures:
1. Get your previous program (05 Laboratory Exercise 1) from your instructor. This is a continuation of
your previous laboratory exercise.
2. Do not open the previous activity. Create a separate program that opens a text file from a specific folder.
This program only contains a single form named FrmOpenFile. See Figure 1.
Figure 1. FrmOpenTextFile
3. Follow the given design in Figure 1. See Table 1 for the names of the control that contains function.
Forms/Controls Name
Form FrmOpenTextFile
Forms/Controls Name
ListView lvShowText
Button btnOpen
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Browse Text Files";
openFileDialog1.DefaultExt = "txt";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.ShowDialog();
path = openFileDialog1.FileName;
using (StreamReader streamReader = File.OpenText(path)) {
string _getText = "";
while ((_getText = streamReader.ReadLine()) != null) {
Console.WriteLine(_getText);
lvShowText.Items.Add(_getText);
}
}
7. Run the program to check the output and analyze the given code.
Challenge Exercise:
1. In this challenge exercise, open your previous project and another form named FrmStudentRecord.
3. The Register button in FrmStudent should go back to the FrmRegistration. The Find button will look
for the text file in the specified directory, while the Upload button will only display a message box
“Successfully Uploaded!” and will clear the ListView’s existing content.
5. Inform your instructor once you’re done with the Challenge Exercise as this will be recorded.
Grading Rubric: