FileOk Action

image_pdfimage_print
   
 
using System;
using System.IO;
using System.Windows.Forms;

class FileDialogApp {
    private static OpenFileDialog ofd;

    static void Main(string[] args) {
        ofd = new OpenFileDialog();
        string s = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory()));

        ofd.InitialDirectory = s;
        ofd.FileOk += new System.ComponentModel.CancelEventHandler(ofd_OK);
        ofd.ShowDialog();
    }
    public static void ofd_OK(object sender,
        System.ComponentModel.CancelEventArgs e) {
        StreamReader sr = new StreamReader(ofd.FileName);
        string s;
        while ((s = sr.ReadLine()) != null) {
            Console.WriteLine(s);
        }
        sr.Close();
    }
}