0

在 Silverlight 中设置 OpenFileDialog 控件的过滤属性时,有什么办法可以通过扩展名和部分文件名过滤文件?例如,如果我只想显示以字母 A 开头并具有扩展名 .dat 的文件,如何设置过滤器属性。请记住,我可能有其他具有相同扩展名的文件以不同的字母开头。我不想展示那些。感谢您的回复。

4

1 回答 1

0

非常老的问题,但我有类似的问题,这对我来说是这样的:

 private void BrowseExcelFileButton_Click(object sender, RoutedEventArgs e)
    {
        //This needs to be before try statement othervise exception is thrown ("Dialogs must be user-initiated")
        OpenFileDialog openFileDialog = new OpenFileDialog();
        try
        {

            openFileDialog.Filter = "Excel Files (*.xls,*.xlsx)|*.xls;*.xlsx|All Files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;

            if (openFileDialog.ShowDialog() == true)
            {
               ...
            }
        }
        catch (Exception ex)
        {
            ...
        }
    }
于 2019-06-12T09:22:41.167 回答