Open File Dialog with file types : Open File Dialog : GUI Windows Form C# Source Code


Custom Search

C# Source Code » GUI Windows Form » Open File Dialog »

 

Open File Dialog with file types









    

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

namespace nsClassLib
{
    using System;
    using System.IO;
    using System.Windows.Forms;
    
    public class clsMainOpenFileDialog
    {
        [STAThread]
        static public void Main ()
        {
            OpenFileDialog ofn = new OpenFileDialog ();
            ofn.Filter = "C Sharp Files (*.cs)|*.cs|Text Files (*.txt)|*.txt";
            ofn.Title = "Type File";
            while (true)
            {
                if (ofn.ShowDialog () == DialogResult.Cancel)
                    return;
                FileStream strm;
                try
                {
                    strm = new FileStream (ofn.FileName, FileMode.Open, FileAccess.Read);
                    StreamReader rdr = new StreamReader (strm);
                    while (rdr.Peek() >= 0)
                    {
                         string str = rdr.ReadLine ();
                         Console.WriteLine (str);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show ("Error opening file", "File Error",
                                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                ofn.Title = "Next File to Type";
            }
        }
    }
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo GUI Windows Form
» Open File Dialog