选择文件获取地址

 private void button1_Click(object sender, EventArgs e)
        {
            //OpenFileDialog dlg = new OpenFileDialog(); 

            OpenFileDialog fileDialog1 = new OpenFileDialog();
            fileDialog1.InitialDirectory = "d:\\";//初始目录
            fileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";//文件的类型
            fileDialog1.FilterIndex = 1;
            fileDialog1.RestoreDirectory = true;
            if (fileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = fileDialog1.FileName;
            }
            else
            {
                textBox1.Text = "";
            }

        }

posted @ 2014-05-07 15:05  yufeiyunsui  阅读(263)  评论(1编辑  收藏  举报