private void SAL_OpenToolStripButton_Click(object sender, EventArgs e) { StreamReader sr; // Supposing you haven't already set these properties... { var withBlock = OpenTextFileDialog; withBlock.FileName = ""; withBlock.Title = "Open a Program file..."; withBlock.InitialDirectory = @"C:\"; withBlock.Filter = " Program Files|*.*"; } if (OpenTextFileDialog.ShowDialog() == DialogResult.OK) { try { sr = new StreamReader(OpenTextFileDialog.FileName); SAL_TextBoxCodeInput.Text = OpenTextFileDialog.FileName; } catch (Exception ex) { SAL_TextBoxErrorOutput.Text = "The file specified could not be opened." + Constants.vbNewLine + "Error message:" + Constants.vbNewLine + Constants.vbNewLine + ex.Message + Constants.vbNewLine + " File Could Not Be Opened!"; } } }
private void OnLoad_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { OpenTextFileDialog aDlg = new OpenTextFileDialog(); if (aDlg.ShowDialog() != true) { return; } try { _Model.Load(aDlg.FileName, aDlg.CurrentEncoding); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void OnBrowseEmailContent_Click(object sender, RoutedEventArgs e) { OpenTextFileDialog aDlg = new OpenTextFileDialog(); if (aDlg.ShowDialog() != true) { return; } try { _Model.LoadEmailContent(aDlg.FileName, aDlg.CurrentEncoding); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
private void LoadButton_Click(object sender, EventArgs e) { OpenTextFileDialog.ShowDialog(); }