Source Code and Samples

Friday, 2 February 2007

Base64 Encode a File


This script will Base64 encode the contents of the file specified and output it to another file called {filename}.b64.

Source Code

$fileName = "File1.txt"
$fileContent = get-content $fileName
$fileContentBytes = [System.Text.Encoding]::UTF8.GetBytes($fileContent)
$fileContentEncoded = [System.Convert]::ToBase64String($fileContentBytes)
$fileContentEncoded set-content ($fileName + ".b64")


Борис Иванов said...

$fileContentEncoded | set-content ($fileName + ".b64")

it's require pipe to work

buyi wen said...

you can try this free online service to encode image to base64 string online.

Cindy Dy said...

I enjoy reading your articles. You really have a wonderful blogs. Keep up the good work. Thank you also for the information!


sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.