How can I confirm the filename before the SaveFileDialog is closed?
I am using SaveFileDialog and want to evaluate if a file meets certain conditions before allowing it to be saved. If that doesn't fit the criteria, I don't want the SaveFileDialog to close when I click Save. I thought FileOK might work, but the dialog looks like it was already closed by the time this event is fired and I see no way to prevent it from closing anyway.
0
a source to share
3 answers
Try this approach from FileOK handler
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
//your conditions...
if (!openFileDialog1.FileName.Equals( "C:\\hello.txt" ) )
{
//if fail, set e.cancel
MessageBox.Show(@"File name must equal c:\hello.txt.");
e.Cancel = true;
}
}
+3
a source to share