打开文件:
var dialog = new OpenFileDialog { Multiselect = false }; var result = dialog.ShowDialog(); if (result == true) { using (var stream = dialog.File.OpenRead()) { var buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); var xaml = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length); ............................. ................................ } }
保存文件:
var dialog = new SaveFileDialog();
dialog.Filter="文本文件(*.txt)|*.txt"; var result = dialog.ShowDialog(); //dialog.Filter = "文本文件|*.txt"; if (result == true) { using (var stream = dialog.OpenFile()) { Byte[] fileContent = Encoding.UTF8.GetBytes(saveXaml+strAll.ToString()); stream.Write(fileContent, 0, fileContent.Length); stream.Close(); } }