articles

Home / DeveloperSection / Articles / OpenFileDialog

OpenFileDialog

Anonymous User6426 15-Jul-2010

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

OpenFileDialog

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

OpenFileDialog 

OpenFileDialog

 


Updated 04-Mar-2020
I am a content writter !

Leave Comment

Comments

Liked By