我如何从NotesStream写入文件(pdf,txt,...)? [英] How can i write file ( pdf,txt,...) from NotesStream?

查看:169
本文介绍了我如何从NotesStream写入文件(pdf,txt,...)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个base64编码的字符串.我想对其进行解码,然后烧毁一个文件以继续进行.我编写此代码:

I have a base64 encoded string. I want to decode it and burn out a file to pass on. I code this:

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文件,它报错并且无法打开. 如何解决?感谢您的帮助!

Examples: attachmentValue = "VG9pIGxhIFF1aQ==" and attachmentName = "file.pdf". When I write a txt file, it works fine. But I write a pdf file, it error and can not open. How to fix it? Thanks for help!

推荐答案

我发现了我的错误. writeText的格式参数错误.

I find out my mistake. writeText had the wrong format parameter.

Call stream.WriteText(attachmentValue, EOL_CRLF)

工作正常.

这篇关于我如何从NotesStream写入文件(pdf,txt,...)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆