WPF没有像Winform这样的OpenFileDialog控件,所以我们需要引用System.Windows.Forms;
之后就跟Winform中的一样了
System.Windows.Forms.OpenFileDialog openFileDialog1 =
new
System.Windows.Forms.OpenFileDialog();
openFileDialog1.InitialDirectory =
"c:\\"
;
openFileDialog1.Filter =
"txt files (*.txt)|*.txt|All files (*.*)|*.*"
;
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory =
true
;
if
(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//此处做你想做的事 ...=openFileDialog1.FileName;
}
|