Hi JLCantara
I did'nt andestand Your post.
Anyway I have solved my problem with this code:
Public Function EncodeFileToBase64Binary(strPicPath As String) As String
' read the filestream from filesystem
Const adTypeBinary = 1 ' Binary file is encoded
' Variables for encoding
Dim objXML
Dim objDocElem
' Variable for reading binary picture
Dim objStream As New ADODB.Stream
' Open data stream from picture
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile strPicPath
' Create XML Document object and root node
' that will contain the data
Set objXML = CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.DataType = "bin.base64"
' Set binary value
objDocElem.nodeTypedValue = objStream.Read()
' Get base64 value
EncodeFileToBase64Binary = objDocElem.Text
' Clean all
Set objXML = Nothing
Set objDocElem = Nothing
Set objStream = Nothing
End Function
Public Function decodefromBase64Binary(GetFilePath As String, OutFilePath As String) As Boolean
' read the base64binary from the filesystem
' write the filestrem to filesystem
Const foForReading = 1 ' Open base 64 code file for reading
Const foAsASCII = 0 ' Open base 64 code file as ASCII file
Const adSaveCreateOverWrite = 2 ' Mode for ADODB.Stream
Const adTypeBinary = 1 ' Binary file is encoded
' Variables for reading base64 code from file
Dim objFSO
Dim objFileIn
Dim objStreamIn
' Variables for decoding
Dim objXML
Dim objDocElem
' Variable for write binary picture
Dim objStream
On Error GoTo decodefromBase64Binary_err
' Open data stream from base64 code filr
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileIn = objFSO.GetFile(GetFilePath)
Set objStreamIn = objFileIn.OpenAsTextStream(foForReading, foAsASCII)
' Create XML Document object and root node
' that will contain the data
Set objXML = CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.DataType = "bin.base64"
' Set text value
objDocElem.Text = objStreamIn.ReadAll()
' Open data stream to picture file
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
' Get binary value and write to file
objStream.Write objDocElem.nodeTypedValue
objStream.SaveToFile OutFilePath, adSaveCreateOverWrite
' Clean all
Set objFSO = Nothing
Set objFileIn = Nothing
Set objStreamIn = Nothing
Set objXML = Nothing
Set objDocElem = Nothing
Set objStream = Nothing
decodefromBase64Binary = True
Exit Function
decodefromBase64Binary_err:
decodefromBase64Binary = False
End Function
Regard
Marco Dell'Oca