private void bOpenFileDialog_Click(object sender, RoutedEventArgs e) { // Create an instance of the open file dialog box. OpenFileDialog openFileDialog1 = new OpenFileDialog(); // Set filter options and filter index. openFileDialog1.Filter = "All Files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = true; // Call the ShowDialog method to show the dialog box. // bool? userClickedOK = openFileDialog1.ShowDialog(); // Process input if the user clicked OK. if (openFileDialog1.ShowDialog() == true) using (StreamReader reader = openFileDialog1.File.OpenText()) { val = reader.ReadToEnd(); tbResults.Text = openFileDialog1.File.Name; reader.Close(); } } private void bSaveFileDialog_Click(object sender, RoutedEventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "XML Files (.xml)|*.xml"; dlg.DefaultExt = "*.xml"; // if the user doesn't cancel if (dlg.ShowDialog() == true) { try { // create a StreamWriter over the base stream returned by SaveFileDialog's OpenFile() method using (StreamWriter writer = new StreamWriter(dlg.OpenFile())) { writer.Write(val); writer.Close(); } MessageBox.Show("File Save Successful"); } catch (Exception ex) // catch all, ideally you should catch specific exceptions in most-specific to general { MessageBox.Show(ex.ToString()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)