Simple Text editor – Need to save as Binary format [closed]

First create some placeholder for binary extension :

const string BINARY_EXTENSION = "bin";

In btnSaveFile_Click() You can modify the save functionality with:

if ( filename.EndsWith(BINARY_EXTENSION))
    File.WriteAllBytes(filename, Encoding.UTF8.GetBytes(tbEditor.Text)); // Or choose something different then UTF8
else
    File.WriteAllText(filename);

And inside your btnOpenFile_Click you can do the same :

if ( filename.EndsWith(BINARY_EXTENSION))
    tbEditor.Text = Encoding.UTF8.GetString(File.ReadAllBytes(filename); // Or choose something different then UTF8
else
    tbEditor.Text = File.ReadAllText(filename);

Leave a Comment