Visual C# | FileDialogs and StreamReaders 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.

Software ==> Visual C#  (79 exercises)
Version ==> Any version of C#
Topic ==> FileDialogs and StreamReaders  (1 exercise)
Level ==> Average difficulty
Subject ==> C# training
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!

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post