c# - 打开文件对话框...值不在预期范围内

标签 c# openfiledialog application-settings

我正在尝试使用 openFileDialog,它一直在工作,直到今天早上我做了一个我认为是简单的更改....

我将 Filter 和 Initial Directory 属性从硬编码字符串更改为应用程序设置,这就是错误出现的地方。据我所知,一切都应该没问题......我会发布新旧代码......

新代码

    private void btnOpenFile_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog ofDialog = new OpenFileDialog();
        ofDialog.Filter = Properties.Settings.Default.openFileFilter;
        ofDialog.FilterIndex = 3;
        ofDialog.Multiselect = false;
        ofDialog.InitialDirectory = Properties.Settings.Default.openFileInitialDirectory;

        bool? fileSelected = ofDialog.ShowDialog();

        if(fileSelected == true)
        {
            selectedFileTxtBx.Text = ofDialog.FileName;
        }

应用程序设置

 Properties.Settings.Default.openFileFilter; = Exe (.exe)|*.exe|MSI (.msi)|*.msi| All (*.*)|*.*
 Properties.Settings.Default.openFileInitialDirectory; = \\\\UNC\\PATH

旧代码

    private void btnOpenFile_Click(object sender, RoutedEventArgs e)
    {
        OpenFileDialog ofDialog = new OpenFileDialog();
        ofDialog.Filter = "Exe (.exe)|*.exe|MSI (.msi)|*.msi| All (*.*)|*.*";
        ofDialog.FilterIndex = 3;
        ofDialog.Multiselect = false;
        ofDialog.InitialDirectory = "\\\\UNC\\PATH";

        bool? fileSelected = ofDialog.ShowDialog();

        if(fileSelected == true)
        {
            selectedFileTxtBx.Text = ofDialog.FileName;
        }
    }

最佳答案

如果内存正常,Properties.Settings.Default.openFileInitialDirectory 实际上应该设置为 \\UNC\PATH,因为字符串已经被转义了。

关于c# - 打开文件对话框...值不在预期范围内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19051918/

相关文章:

c# - 如何使用 Monotouch 对话框显示 UIPickerView?

c# - 为不同项目中的上下文启用项目迁移

c# - 将 C 代码移植到 C#

C# WPF OpenFileDialog 在 XP 中导致崩溃,而不是在 Vista 中

c# - c# asp.net 中的文件夹对话框

c# - 如何更改 .NET 用户设置位置

c# - 使用 MVVM (C# WPF) 如何在应用程序初始化时将设置显示到它们各自的控件中?

c++ - 在不使用数据库的情况下在进程之间共享设置?

c# - 用数字分组格式化十进制数并限制位数

c++ - OpenFileDialog->DialogShow() 结果导致 SQLite 出错