您好,我想使用对话框形式选择文本文件,而不必使用给定的路径。我该怎么做?
我想用 opendialog 替换 opentext?我试过了,但我想使用 streamreader 的流出现错误....
private void button2_Click(object sender, EventArgs e)
{
using (StreamReader reader = File.OpenText("c:\\myparts.txt"))
{
label3.Text = "Ready to Insert";
textBox7.Text = reader.ReadLine();
textBox8.Text = reader.ReadLine();
textBox9.Text = reader.ReadLine();
textBox10.Text = reader.ReadLine();
}
最佳答案
你想要这样的东西吗?
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
using (var reader = File.OpenText(dlg.FileName))
{
...
}
}
关于c# - 将 opentext 更改为 opendialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21891400/