private void btnSaveInFile_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); Assembly asm = Assembly.GetExecutingAssembly(); string path = Path.GetDirectoryName(asm.Location); saveFileDialog1.InitialDirectory = @path; saveFileDialog1.Title = "Save text Files"; saveFileDialog1.CheckFileExists = false; saveFileDialog1.CheckPathExists = true; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; string filename = "test" + ".txt"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { filename = saveFileDialog1.FileName; } else { return; } byte[] output; output = algoritham.Crypt(utf8.GetBytes(tbData.Text)); this.tbDecode.Text = Encoding.UTF8.GetString(output); File.WriteAllBytes(filename, output); }