I have a TextBox
named textbox1
and a Button
named button1
.
When I click on button1
I want to browse my files to search only for image files (type jpg, png, bmp...).
And when I select an image file and click Ok in the file dialog I want the file directory to be written in the textbox1.text
like this:
textbox1.Text = "C:\myfolder\myimage.jpg"
This question is related to
c#
wpf
textbox
openfiledialog
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;
Source: Stackoverflow.com