gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:03:02 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com