从本地读取文件,界面如下。
public partial class MainWindow : Window
{
private OpenFileDialog openFileDialog = null;
public MainWindow()
{
InitializeComponent();
openFileDialog = new OpenFileDialog();
openFileDialog.FileOk += openFileDialogFileOk;
}
private void openFileClick(object sender, RoutedEventArgs e)
{
openFileDialog.ShowDialog();
}
private void openFileDialogFileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
string fullPathname = openFileDialog.FileName;
FileInfo src = new FileInfo(fullPathname);
fileName.Text = src.Name;
source.Clear();
TextReader reader = new StreamReader(fullPathname);
string line;
while ((line = reader.ReadLine()) != null)
{
source.Text += line + "\n";
}
reader.Close();
}
}