如何从NotesStream中编写文件(pdf,txt,...)?

时间:2017-08-21 12:18:25

标签: pdf lotus-notes lotus-domino lotus

我有一个base64编码的字符串。我想解码它并烧掉一个文件来传递。我编码:

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

示例:attachmentValue =" VG9pIGxhIFF1aQ =="和attachmentName =" file.pdf"。 当我写一个txt文件时,它工作正常。但是我写了一个pdf文件,它出错了,无法打开。 怎么解决?谢谢你的帮助!

2 个答案:

答案 0 :(得分:1)

为pdf文件设置内容类型为<appSettings> <add key="SenderEmail" value="abc@gmail.com" /> <add key="SenderPassword" value="********" /> </appSettings>

application/pdf

答案 1 :(得分:1)

我发现了自己的错误。 writeText格式参数错误。

Call stream.WriteText(attachmentValue, EOL_CRLF)

工作正常。