---
title: "OpenFileDialog"  
description: "Here I’m going to demonstrate the use of  OpenFileDialog in C#.  Example  string strFileName=string.Empty;                         //creationg object"  
author: "Anonymous User"  
published: 2010-07-15  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/86/openfiledialog  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# OpenFileDialog

Here I’m going to demonstrate the use of OpenFileDialog in C#.\

![OpenFileDialog](https://www.mindstick.com/mindstickarticle/7b9c73cc-1423-4f46-9680-76c2a8653b87/images/9fe1e3cd-cab6-4b8d-b444-048c0d91601a.png)

Example

```
 string strFileName=string.Empty;                       //creationg object of SaveFileDialogOpenFileDialog openFileDialog1= new OpenFileDialog();//setting filter of open file dialog box  openFileDialog1.Filter= "Text file|*.txt";//checking whether open button is clicked or not   if (openFileDialog1.ShowDialog()== DialogResult.OK)     {//storing filename opened through openfiledialog box.      strFileName = openFileDialog1.FileName;//creating reader to read open file.     System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog1.FileName);//displaying file contents in message box.      MessageBox.Show(sr.ReadToEnd());//closing stream reader.                sr.Close();    } 
```

![OpenFileDialog](https://www.mindstick.com/mindstickarticle/7b9c73cc-1423-4f46-9680-76c2a8653b87/images/da73e917-10c5-4e9c-ad7b-2caeb0aca416.png)

![OpenFileDialog](https://www.mindstick.com/mindstickarticle/7b9c73cc-1423-4f46-9680-76c2a8653b87/images/476994a9-9f70-4306-8b87-7685fde47214.png)\

---

Original Source: https://www.mindstick.com/articles/86/openfiledialog

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
