Ok here is a code I am working on. I am trying to get an exception so that way if they dont have something in the box to save it will pop up and not let them move on till the put something there. Now I know when I run my program and click the save button its tells me this
ArgumentException was unhandled
what does that mean. I know it says empty path name is not legal. But the path is whatever the user wants. I have been messing around with this and im trying to figure out what to do but still kinda confused. So what is the best way to try to go about it. Do I have to make a class for it to work or can I just add into my code. I got the other part fixed with the try and catch but I can not get it to work on this one or maybe I have putting it in the wrong spot.
private void Save_Click(object sender, EventArgs e)
{
string path = txtFilePath.Text;
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
foreach (string lines in employeeList.Items)
sw.WriteLine(lines);
}
else
{
using (StreamWriter sw = File.AppendText(path))<--This is
where is says Arugment exception was unhandled.
{
foreach (var item in employeeList.Items)
sw.WriteLine(item.ToString());
}
}
}
}
Wrap the code in a try catch statement and in the catch you can generate a message to the user (maybe a javascript alert box)
Pseudo code…