private void Salvar() { if (string.IsNullOrEmpty(filePath)) { using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.Filter = "Código C|*.c|Todos os arquivos|*.*"; dialog.FileName = ArquivoNome; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var result = dialog.ShowDialog(); if (result == DialogResult.OK) { filePath = dialog.FileName; } } } if (!string.IsNullOrEmpty(filePath)) { using (FileStream fs = new FileStream(filePath, FileMode.Create)) using (StreamWriter writer = new StreamWriter(fs)) CodeDocument.WriteTextTo(writer); } }