컴퓨터 이야기/c#

File Name을 선택해서 Text 파일 읽기

golfin 2018. 6. 9. 16:15


File Name을 선택해서 Text 파일 읽기


            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Open License File";
            dlg.Filter = "License File (*.lic)|*.lic";
            dlg.FileName = Application.StartupPath + "\\..\\..\\" + filename;

            string ActivationKey;
            if (dlg.ShowDialog() != DialogResult.OK) return false;
            try
            {
                System.IO.StreamReader ObjReader = new System.IO.StreamReader(dlg.FileName);
                ActivationKey = ObjReader.ReadLine();
                ObjReader.Close();
            }
            catch (Exception ex) //General exception
            {
                MessageBox.Show(ex.Message);
                return false;
            }