日期:2014-05-17 浏览次数:20745 次
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
// openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\
openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
textBox1.Text = System.IO.File.ReadAllText(openFileDialog.FileName, Encoding.Default);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}