C# 如何在SaveFileDialog关闭之前验证文件名?
我正在使用SaveFileDialog,希望在允许保存文件之前评估文件是否满足某些条件。如果不符合条件,我不希望在单击“保存”时关闭SaveFileDialog。我认为FileOK可能会工作,但在触发事件时,对话框似乎已经关闭,我看不到任何方法可以阻止它在任何情况下关闭。C# 如何在SaveFileDialog关闭之前验证文件名?,c#,savefiledialog,C#,Savefiledialog,我正在使用SaveFileDialog,希望在允许保存文件之前评估文件是否满足某些条件。如果不符合条件,我不希望在单击“保存”时关闭SaveFileDialog。我认为FileOK可能会工作,但在触发事件时,对话框似乎已经关闭,我看不到任何方法可以阻止它在任何情况下关闭。文件OK是a-您只需将属性设置为true文件OK是a-您只需将属性设置为true从文件OK处理程序尝试这种方法 private void openFileDialog1_FileOk(object sender, CancelE
文件OK
是a-您只需将属性设置为true
文件OK
是a-您只需将属性设置为true
从文件OK处理程序尝试这种方法
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;
}
}
从FileOK处理程序尝试这种方法
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;
}
}
谢谢,这正是我需要的。顺便说一句,你有一个打字错误:“CencelEventArgs”。谢谢,这正是我需要的。顺便说一句,你有一个输入错误:“CencelEventArgs”。