我正在尝试使用openFileDialog,它一直工作到今天早上,当我做出我认为是一个简单的改变....
我将过滤器和初始目录属性从硬编码字符串更改为应用程序设置,这就是错误发生的地方。从我能说的一切都应该没问题......我会发布新旧代码.... / p>
新代码
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;
}
}
答案 0 :(得分:2)
如果内存正常,Properties.Settings.Default.openFileInitialDirectory
实际上应该设置为\\UNC\PATH
,因为字符串已经被转义。