111,120
社区成员
发帖
与我相关
我的任务
分享
using(StreamReader sr = new StreamReader(path,Encoding.Default))//这里的Encoding是你文本的编码
{
textBox2.Text = sr.ReadToEnd();
}
string path;
path= Path.GetDirectoryName(Application.ExecutablePath) + "\\"+ dataGridView1.CurrentRow.Cells[4].Value .ToString ();
string stype = path.Substring(path.LastIndexOf("."));//上面是路径,没有问题
if (stype == ".txt")
{
if (!File.Exists(path))
{
MessageBox.Show("文件不存在或已经删除");
}
else
{
FileStream fs = File.OpenRead(path);
StreamReader sr = new StreamReader(fs,Encoding.Default);
textBox2.Text = sr.ReadToEnd();
}
}
else
{
MessageBox.Show("只能阅读.txt文件,其他文件请下载");
}