关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

C#读取文件btn代码

发布时间:2020-01-21 17:11:13

C#读取文件的操作需要使用到openFileDialog控件 一个button按钮 和 textbox提示框
button代码如下:
 private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = "C:\\";//初始加载路径为C盘;
            //openFileDialog1.Filter = "文本文件 (*.txt)|*.txt";//过滤你想设置的文本文件类型(这是txt型)
           openFileDialog1.Filter = "文本文件 (*.txt)|*.txt|All files (*.*)|*.*";//(这是全部类型文件)
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = Path.GetFileName(openFileDialog1.FileName);//显示文件的名字
            }
        }


/template/Home/Zkeys/PC/Static