Users Pricing

articles

home / developersection / articles / openfiledialog

OpenFileDialog

Anonymous User 7007 15 Jul 2010 Updated 04 Mar 2020

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

 


I am a content writter !


1 Comments


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md