I am using a SaveFileDialog and would like to evaluate whether a file meets certain conditions before allowing it to be saved. If it doesn't meet the criteria, I don't want the SaveFileDialog to close when "Save" is clicked. I thought the FileOK might work, but the dialog looks like it is already closed by the time that event is fired, and I don't see a way to prevent it from closing in any case.
+3
A:
FileOK
is a CancelEventHandler
- you just have to set the Cancel
property of the CancelEventArgs
to true
.
Daniel Brückner
2009-05-11 19:21:41
Thanks, that was exactly what I needed. BTW, you have a typo: "CencelEventArgs".
Andy Stampor
2009-05-11 19:28:56
+2
A:
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;
}
}
Steve
2009-05-11 19:29:32