OpenFileDialog in C#.Net windows application

Let us discuss on OpenFileDialog in C#.Net windows application.

OpenFileDialog in C#.Net windows application

OpenFileDialog class provides a dialog box that enables the user to select one or more files.

OpenFileDialog allows users to browse folders and select files. It is available in Windows Forms and can be used with C# code. It displays the standard Windows dialog box. The results of the selection can be read in your C# code.

In this example we will see whenever a user will select an image through the OpenFileDialog, the image will appear in the picture box.

So First Drag and drop a picture box and a button to the form. Then in the button click event write the below code.

private void button1_Click(object sender, EventArgs e)
OpenFileDialog dlg = new OpenFileDialog();
dlg.Title = “Open Photo”;
dlg.Filter = “jpg files (*.jpg)|*.jpg|All files (*.*)|*.*”;
if (dlg.ShowDialog() == DialogResult.OK)
pictureBox1.Image = new Bitmap(dlg.OpenFile());

Once user selects an image, the image will appear.

You may like following C#.Net tutorials:

Hope this C#.Net tutorial exlains OpenFileDialog in C#.Net windows application.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site