Home > DeveloperSection > Articles > OpenFileDialog

OpenFileDialog


C# C# 
Ratings:
0 Comment(s)
 3616  View(s)
Rate this:

OpenFileDialog box in C#.NET

Here I’m going to demonstrate the use of OpenFileDialog in C#.

Example

 

string strFileName=string.Empty;                       

//creationg object of SaveFileDialog

OpenFileDialog 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();

            }


Don't want to miss updates? Please click the below button!

Follow MindStick