So the title might be bit misleading, but what I wanted to accomplish is reading an array of files and then combine them into one, which is where I am now.
The problem is that I have a catch that looks for the exception "FileNotFoundException", when this is called I want to continue my try statement (Using "continue") but let the user know that the file is missing.
My setup is a class that is called from a form (It's in the form where the error should show up)
I thought about creating an event that can be registered from my form, but is that the right way?
public void MergeClientFiles(string directory)
{
// Find all clients
Array clients = Enum.GetValues(typeof(Clients));
// Create a new array of files
string[] files = new string[clients.Length];
// Combine the clients with the .txt extension
for (int i = 0; i < clients.Length; i++)
files[i] = clients.GetValue(i) + ".txt";
// Merge the files into directory
using (var output = File.Create(directory))
{
foreach (var file in files)
{
try
{
using (var input = File.OpenRead(file))
{
input.CopyTo(output);
}
}
catch (FileNotFoundException)
{
// Its here I want to send the error to the form
continue;
}
}
}
}