J'ai une chaîne encodée en base64. Je veux le décoder et brûler un fichier à transmettre. Je code ceci:Comment puis-je écrire un fichier (pdf, txt, ...) à partir de NotesStream?
Function DecodeBase64(attachmentValue As String,attachmentName As String) As String
Dim result As String
Dim s As New NotesSession
Dim fileOut As String
Dim fout As Integer
Dim foutOpen As Integer
Dim stream As NotesStream
Dim dc As NotesDocumentCollection
'fout = Freefile
fileOut = "C:\ExportFileLotus\" + attachmentName
'Open fileOut For Output As fout
'foutOpen = True
Set db = s.CurrentDatabase
Set doc = db.CreateDocument
s.ConvertMIME = False ' Do not convert MIME to rich text
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader(attachmentName)
Call header.SetHeaderVal("MIME document")
Set stream = s.CreateStream
Call stream.WriteText(attachmentValue,EOL_NONE)
If stream.Bytes = 0 Then
Messagebox fileInput,,"File has no content"
Goto ExitSub
End If
'Call body.SetContentFromText(stream, "text/plain;charset=UTF-8", ENC_BASE64)
'Call body.SetContentFromText(stream, "charset=UTF-8", ENC_BASE64)
Call body.SetContentFromBytes(stream, "", ENC_BASE64)
Call body.DecodeContent()
stream.Open fileOut, "binary"
body.GetContentAsBytes stream, True
stream.Close
'Print #fout, body.ContentAsText
'Close #fout
DecodeBase64 = fileOut
ExitSub:
s.ConvertMIME = True ' Restore conversion
End Function
Exemples: attachmentValue = "VG9pIGxhIFF1aQ ==" et ATTACHMENTNAME = "fichier.pdf". Lorsque j'écris un fichier txt, cela fonctionne très bien. Mais j'écris un fichier pdf, il erreur et ne peut pas ouvrir. Comment le corriger? Merci pour l'aide!
Pour combien de temps cette fonction est-elle disponible? Appelez stream.WriteText (attachmentValue, EOL_CRLF) .Elle fonctionne correctement –