Open file dialog and select a file using WPF controls and C# Open file dialog and select a file using WPF controls and C# wpf wpf

Open file dialog and select a file using WPF controls and C#


Something like that should be what you need

private void button1_Click(object sender, RoutedEventArgs e){    // Create OpenFileDialog     Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();    // Set filter for file extension and default file extension     dlg.DefaultExt = ".png";    dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";     // Display OpenFileDialog by calling ShowDialog method     Nullable<bool> result = dlg.ShowDialog();    // Get the selected file name and display in a TextBox     if (result == true)    {        // Open document         string filename = dlg.FileName;        textBox1.Text = filename;    }}


var ofd = new Microsoft.Win32.OpenFileDialog() {Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"}; var result = ofd.ShowDialog();if (result == false) return;textBox1.Text = ofd.FileName;