private void btSave_Click(object sender, EventArgs e) { FileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Fichiers texte|*.txt|Tous les fichiers|*.*"; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { string path = saveFileDialog.FileName; File file = new File(path); try{ file.write(tbResult.Text); MessageBox.Show("Enregistrement effectué."); } catch (Exception ex){ MessageBox.Show("Une erreur est survenue lors de l'écriture du fichier: " + ex.Message); } } }
private String openFile() { string content = ""; FileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Fichiers texte|*.txt|Tous les fichiers|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string path = openFileDialog.FileName; File file = new File(path); try { content= file.read(); } catch (Exception ex) { MessageBox.Show("Une erreur est survenue lors de l'écriture du fichier: {0}.", ex.Message); } } return content; }