
Way 01 使用win32控件OpenFileDialog
1 2 3 4 5 6 7
|
Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.DefaultExt = ".xml"; ofd.Filter = "xml file|*.xml"; if (ofd.ShowDialog() == true) { Console.WriteLine("if"); }
|
类似的还有 Microsoft.Win32.SaveFileDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
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; Console.WriteLine(openFileDialog1.FileName); }
//File FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog(); folderBrowserDialog.Description = "Please select Data Folder"; if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { Console.WriteLine("WCNBB"); }
|
Way 03 使用win32 api
1
|
BOOL WINAPI GetOpenFileName( __inout LPOPENFILENAME lpofn)
|
1 2 3
|
var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = true; CommonFileDialogResult result = dialog.ShowDialog();
|
近期评论