How to Decode and Encode MIME data

This function will decode the mime data contained in a string into a BYTE and then it can be saved onto your desktop using the FileStream.

————————————————————————-
Dim byteData As Byte()
byteData = FromBase64(strMimeData)
Dim oFileStream As System.IO.FileStream
oFileStream = New System.IO.FileStream(“c:\temp\” & Me.txtAttachFileName.Text, System.IO.FileMode.Create)
oFileStream.Write(byteData, 0, byteData.Length)
oFileStream.Close()

This function will encode the data contained in a BYTE into MIME data which will be returned as a string
———————————————————————–

Public Function EncodeToBase64(ByVal data() As Byte) As String
If data Is Nothing Then Throw New ArgumentNullException(“data”)
Return Convert.ToBase64String(data)
End Function

This function will decode the MIME data contained in a string  and the binary data will be returned as a BYTE
———————————————————————–

Public Function  DecodeFromBase64(ByVal base64 As String) As Byte()
If base64 Is Nothing Then Throw New ArgumentNullException(“base64”)
Return Convert.FromBase64String(base64)
End Function