OpenFileDialog

 

打开一个文件

        private void button1_Click(object senderEventArgs e)
        {
            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                label1.Text = openFileDialog1.FileName;
                System.IO.StreamReader str = new System.IO.StreamReader(openFileDialog1.FileName);
                textBox1.Text = str.ReadToEnd();
                str.Close();
            }
        }

 

 

 

打开多个文件

        private void button1_Click(object senderEventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                foreach (var FileName in openFileDialog1.FileNames)
                {
                    listView1.Items.Add(FileName);
                }
            }
        }





posted @ 2013-12-03 21:28  XE2011  阅读(219)  评论(0编辑  收藏  举报