public partial class MainWindow : Window
{
private OpenFileDialog openFileDialog = null;
public MainWindow()
{
InitializeComponent();
openFileDialog = new OpenFileDialog();
openFileDialog.FileOk += openFileDialogFileOk;
}
private void openBtn_Click(object sender, RoutedEventArgs e)
{
openFileDialog.ShowDialog();
}
private void openFileDialogFileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
string fullPathName = openFileDialog.FileName;
FileInfo str = new FileInfo(fullPathName);
fileNameText.Text = str.Name;
contentText.Text = "";
TextReader reader = str.OpenText();
string line = reader.ReadLine();
while (line != null)
{
line = reader.ReadLine();
contentText.Text +=line +'\n';
}
reader.Close();
}
}
转载于:https://www.cnblogs.com/CandiceW/p/4204565.html