我用的VS2012,发过来文件怕你打不开,把代码发上来,你复制一下就行了
using System.IO;
private void btnread_Click(object sender, EventArgs e)
{
try
{
//打开一个文件对话框
ofd.Filter = "文本文件(*.txt)|*.txt";
ofd.Title = "打开文本文件";
ofd.InitialDirectory = "C:\\Users\\Administrator\\Documents";
ofd.ShowDialog(this);
//读取选定的文本文件到textbox
textBox1.Text = ofd.FileName;
StreamReader sr = new StreamReader(ofd.FileName);
textBox2.Text = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btndel_Click(object sender, EventArgs e)
{
try
{
File.Delete(textBox1.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}