1

我有一个 OpenFileDialog,它为允许的扩展定义了一个过滤器(仅限于 jpg、png 等图像文件)。问题是我们的用户可以输入. 在文件名文本框中,然后这将过滤所有文件。然后我可以毫无问题地选择一个文本文件。除了检查允许扩展的块后面的代码之外,有没有办法让这种情况不发生?这是我创建的可以帮助您理解问题的块,也:

if (!(ImageFileExtensions.Split(new char[] { ',' }).Contains(Path.GetExtension(currentFileNamePath).Replace(".", ""))) )
{
    DialogResult respNotAllowedExtension = MdtUserMessage.ShowError(GenericLogCommon.GenericLogDettType.UserWarning, "The extension of the file is not allowed!" , MessageBoxButtons.OK);
    if (respNotAllowedExtension == DialogResult.OK)
        return false;
}
4

0 回答 0