openFileDialog控件的使用!

        private void button1_Click(object sender, EventArgs e)
        {
           //文件对话框显示的初始目录
            openFileDialog1.InitialDirectory = "c:\\";

            //设置过滤条件
            openFileDialog1.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";


            //对话框的返回值为OK时读取数据
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {

                label1.Text = openFileDialog1.FileName;//文件名
                //使用数据流对象读取文件中的数据
                System.IO.StreamReader sr = new
                    System.IO.StreamReader(openFileDialog1.FileName);
                this.textBox1.Text=sr.ReadToEnd();
                sr.Close();
            }
           

        }

 

posted @ 2013-04-28 23:10  J_une  阅读(479)  评论(0编辑  收藏  举报