Difference between revisions of "Selecting a text file in C"
From MyWiki
(Created page with "<source lang="csharp"> </source>") |
|||
| Line 1: | Line 1: | ||
<source lang="csharp"> | <source lang="csharp"> | ||
| + | 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); | ||
| + | } | ||
</source> | </source> | ||
Revision as of 11:53, 25 October 2018
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); }