/ Published in: C#
Useful for sending files past filters via email.
Expand |
Embed | Plain Text
private void btnEncode_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtInFile.Text)) { FileMode.Open, FileAccess.Read); fs.Read(filebytes, 0, Convert.ToInt32(fs.Length)); string encodedData = Convert.ToBase64String(filebytes, Base64FormattingOptions.InsertLineBreaks); txtEncoded.Text = encodedData; } } private void btnDecode_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtOutFile.Text)) { byte[] filebytes = Convert.FromBase64String(txtEncoded.Text); FileMode.CreateNew, FileAccess.Write, FileShare.None); fs.Write(filebytes, 0, filebytes.Length); fs.Close(); } }
Comments
Subscribe to comments
You need to login to post a comment.

I need implementation that source in visual c# 2005,,please,,, send me at : [email protected]
thanks very much.....
Yea, it works great until you throw Russian or Arabic or Chinese or anything not ASCII at it. Doesn't ANYBODY know how to actually decode Base64? Microsoft obviously doesn't.
What are you talking about, this isn't for text, it's for binary. The file you end with is binary identical to the file you start with.
Turning binary data into an ASCII string is the definition of Base64, languages don't come into play, it's a string of gibberish bytes.