Selecting a text file in C

From MyWiki
Revision as of 12:57, 25 October 2018 by George2 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
OpenFileDialog dialog = new OpenFileDialog();
           dialog.Filter =
              "txt files (*.txt)|*.txt|All files (*.*)|*.*";
           dialog.InitialDirectory = "C:\\";
           dialog.Title = "Select a text file";
           if (dialog.ShowDialog() == DialogResult.OK)
           {
               string fname = dialog.FileName;
                         richTextBox1.Text= System.IO.File.ReadAllText (fname);
 
           }#

Some notes
dialog.filename gives the file including path
dialog.SafeFilename gives only the filename