Exercise: Use a StreamReader and FileDialog

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!

Category ==> Visual C Sharp 2010  (65 exercises)
Topic ==> FileDialogs and StreamReaders  (1 exercise)
Level ==> Average difficulty
Course ==> WinForms using Visual C#
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Someone has hidden the word Kilroy in one of the forms in the folder above - your task is to find it!  First, create a form called frmHuntKilroy containing a single clickable button. 

Attach code to this button to display an OpenFileDialog, allowing a user to choose one or more code files (use the filter *.cs):

Visual C Sharp 2010 exercise - FileDialogs and StreamReaders (image 1)

Set the FileDialog's MultiSelect property, to allow multiple file selection

When a user selects one or more code files, extend your code to:

  • Open each file using a StreamReader object
  • Read through the lines in the file looking for the text Kilroy; then
  • Close the file

Eventually you should find the word you're looking for, and display the name of the file in which you found it:

Visual C Sharp 2010 exercise - FileDialogs and StreamReaders (image 2)

Sorry - you'll have to find out yourself!

That's it!

This page has 0 threads Add post