---
title: "OpenFileDialog Control in C#.Net"  
description: "An OpenFileDialog control is used to select a file. OpenFileDialog provide files to the user and retrieves the user's file selection back to the progr"  
author: "Pushpendra Singh"  
published: 2011-01-24  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/419/openfiledialog-control-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# OpenFileDialog Control in C#.Net

An [OpenFileDialog](https://www.mindstick.com/forum/1564/use-openfiledialog-to-get-path-of-open-database-c-sharp) [control](https://yourviews.mindstick.com/view/83439/bipartisan-gun-control-bill-passed-in-us-after-decades) is used to select a file. OpenFileDialog provide files to the user and retrieves the user's file [selection](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) back to the program.\

## How to use OpenFileDialog Control

[Drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) OpenFileDialog control from toolbox on the [window Form](https://www.mindstick.com/forum/527/how-to-pass-datagridview-s-cells-value-to-another-window-form).

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/2928ffce-3dc2-4ace-8290-49b947832e7e.png)

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/dfdc29e2-9714-4007-aa4f-1696d874f9ec.png)

Drag and drop PictureBox and Button.

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/b475a599-f0a6-4e50-a533-1e45a4cf7920.png)

## Code:

Write code in Button click event.

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/0b5ba7dc-386f-4ab2-aeb1-18db91ae3745.png)

[Double click](https://www.mindstick.com/forum/156225/differentiate-between-google-adword-and-double-click) on [Click event](https://www.mindstick.com/forum/424/how-to-call-form_paint-event-on-button-click-event) to open [Button click](https://www.mindstick.com/forum/568/check-condion-before-post-page-on-button-click-in-jquery-or-javascript) [event handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question).

```
private void btnOpenFile_Click(object sender, EventArgs e){        // OpenFileDialog will open        openFileDialog1.ShowDialog();        // selected Image will show in the pictureBox        pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);}
```

**Run the [project](https://yourviews.mindstick.com/story/1788/things-to-ensure-your-construction-project-is-successful)**

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/e882fa6a-59e1-4b03-8110-faf398cb578b.png)

When you click SelectImage button then OpenFileDialog will open.

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/112b3e70-3d04-4b59-8582-77b6ed3a38ca.png)

Select Image which you want to show in the PictureBox. When you select Image and click open then selected Image will show in PictureBox on the Form.

![OpenFileDialog Control in C#.Net](https://www.mindstick.com/mindstickarticle/0db38380-f77c-40a9-a6a9-40d13ec883c4/images/ef09d89e-531d-4647-9281-35c084b8ec34.png)

---

Original Source: https://www.mindstick.com/articles/419/openfiledialog-control-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
