单击按钮,打开附件对话框
button click which makes attachment dialog open
大家好,我正在尝试发送附件文件,但附件对话框打不开
但相反,它告诉我“输入字符串的格式不正确
private void proto_Type_AI_Blackhead_God(object sender, RoutedEventArgs e)
{
try
{
OpenFileDialog attachment = new OpenFileDialog();
attachment.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
attachment.Filter = "xml File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif;|Pdf files|*.pdf;|Xml files|*.xml";
if (attachment.ShowDialog() == DialogResult.Value)
{
filename = attachment.FileName;
filename = attachment.SafeFileName;
}
else
{
MessageBox.Show("seriously bad");
}
attachment = null;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我很惊讶你编译了这段代码。
首先,OpenFileDialog.ShowDialog()
returns bool?
,因此请正确检查它(最初是 HasValue
,然后是 Value
的值)。
那么,为什么要覆盖 filename
变量呢?我假设 filename
是一些全局变量。
此外,修复后我没有问题 运行 代码,过滤器字符串在语义上是完全正确的。从逻辑上讲,jpegs、bmps 和 gifs 不是 XML 文件。
大家好,我正在尝试发送附件文件,但附件对话框打不开 但相反,它告诉我“输入字符串的格式不正确
private void proto_Type_AI_Blackhead_God(object sender, RoutedEventArgs e)
{
try
{
OpenFileDialog attachment = new OpenFileDialog();
attachment.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
attachment.Filter = "xml File (*.jpg;*.bmp;*.gif)|*.jpg;*.bmp;*.gif;|Pdf files|*.pdf;|Xml files|*.xml";
if (attachment.ShowDialog() == DialogResult.Value)
{
filename = attachment.FileName;
filename = attachment.SafeFileName;
}
else
{
MessageBox.Show("seriously bad");
}
attachment = null;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我很惊讶你编译了这段代码。
首先,OpenFileDialog.ShowDialog()
returns bool?
,因此请正确检查它(最初是 HasValue
,然后是 Value
的值)。
那么,为什么要覆盖 filename
变量呢?我假设 filename
是一些全局变量。
此外,修复后我没有问题 运行 代码,过滤器字符串在语义上是完全正确的。从逻辑上讲,jpegs、bmps 和 gifs 不是 XML 文件。