Noob Coder (Visual C#) - Unhandled Exception
Right people, I have recently attempted learning Visual C# with the help of a Sam's Learn in 24 Hours Book. I felt like I had learned just enough to muddle through creating my own simple program that, at the moment, simply lists files in a chosen directory.
However, it spits out an exception when the target path is empty, which I was expecting it to do. Therefore I added an else statement (the relevant section of code is shown below) to display a messagebox informing the user of the problem.
What have I done wrong? The line in bold in the code is the line that VC# does not like.
private void btnGo_Click(object sender, EventArgs e)
if (txtTargetPath != null)
DirectoryInfo dirTarget = new DirectoryInfo(txtTargetPath.Text);
colFiles = dirTarget.GetFiles();
foreach (FileInfo filFiles in colFiles)
txtResults.AppendText(filFiles.Name + "\r\n");
MessageBox.Show("You have not selected a valid folder!");