I am using Forms in Visual Studio.I would like to display an error message when save is clicked on the save file dialog without giving the filename. How do I do it?
I've tried the following code but it did not work: I've tried 2 logics. 1)
if (string.IsNullOrEmpty(saveFileDialog1.FileName))
{
MessageBox.Show("Enter the Filename");
}
2) This is the 2nd Logic
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (saveFileDialog1_FileOk == saveFileDialog1.FileName)
{
MessageBox.Show("Enter the Filename");
}
else
{
string name = saveFileDialog1.FileName;
string testvar = textBox1.Text;
File.WriteAllText(name, testvar);
}
}
I want to display an error message when save button is clicked without entering anything in the File Name. I hope the question is clear!