(VBScript) Base64 Encode a File
VBScript to Base64 encode the contents of a file.
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' Get the contents of a file into a base64 encoded string:
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.FileAccess")
set fac = CreateObject("Chilkat.FileAccess")
strBase64 = fac.ReadBinaryToEncoded("c:/data/something.pdf","base64")
If (fac.LastMethodSuccess <> 1) Then
outFile.WriteLine(fac.LastErrorText)
WScript.Quit
End If
' Now write the string to a file:
success = fac.WriteEntireTextFile("c:/data/something_pdf_base64.txt",strBase64,"us-ascii",0)
If (success <> 1) Then
outFile.WriteLine(fac.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Success!")
outFile.Close
|