1
所以目前我得到的用户决定文件路径是这样的:如何设置默认路径,然后我按下WPF中的ShowDialog按钮?
private void Button_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".xml";
dlg.Filter = "XML files (*.xml)|*.xml";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
// Open document
string xmlFile = dlg.FileName; // this required full path.
}
}
它工作正常,但通常默认路径为.exe
定位文件夹,需要去改变它。我该怎么做?
当你做.ShowDialog()时你想改变对话框打开的目录吗? – Josh
你到底在问什么?你想设置在OpenFileDialog中打开的初始目录吗?目前还不清楚“通常默认路径是.exe定位文件夹”的含义。 –