1 // Create OpenFileDialog 2 Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); 3 4 // Set filter for file extension and default file extension 5 dlg.DefaultExt = ".txt"; 6 dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"; 7 8 // Display OpenFileDialog by calling ShowDialog method 9 Nullable<bool> result = dlg.ShowDialog(); 10 11 // Get the selected file name and display in a TextBox 12 if (result == true) 13 { 14 // Open document 15 string filename = dlg.FileName; 16 this.txtPlace.Text = filename; 17 }
Using Open File Dialog in WPF