首页 文章

将多个Aspose.words生成的文档发送到客户端计算机

提问于
浏览
0

我有一个.NET应用程序,使用Aspose.words dll以.docx或.pdf格式构建4个文档 . 我现在面临的挑战是如何在发电后立即向客户提供所有4份文件 . 有没有人以前做过这个,如果有的话,你是怎么做到的?我能够将单个文件发送到客户端,但是当我尝试发送多个文件时,客户端只接收代码中指定的最后一个文件 . 例如:

Dim CLdoc As New Document("C:/Temp/Cover Letter.docx")
Dim CLbuilder As New DocumentBuilder(CLdoc)

'Build CLDoc content

Dim MTdoc As New Document("C:/Temp/Master Terms.docx")
Dim MTbuilder As New DocumentBuilder(MTdoc)

'Build MTDoc content

CLdoc.Save(Response, "iama.docx", ContentDisposition.Inline, Nothing)
MTdoc.Save(Response, "iama1.docx", ContentDisposition.Inline, Nothing)

发送给客户端的唯一文档是“iama1.docx” . 如何让应用程序同时发送?我有一个想法是将两个文件发送到zip存档并将其发送给客户端,但我真的不知道如何实现这一点 . 有任何想法吗?

编辑

使用Ionic Zip我尝试将生成的文件保存到内存流中,将其添加到zip存档并保存到磁盘(暂时用于测试;我最终将zip存档发送到客户端计算机) . 我现在的问题是我添加的.docx文件是空白/空的 . 我是如何将生成的文件保存到内存流中的?

Dim CLdoc As New Document("C:/Temp/Cover Letter.docx")
Dim CLbuilder As New DocumentBuilder(CLdoc)

'Build CLDoc content

Dim MTdoc As New Document("C:/Temp/Master Terms.docx")
Dim MTbuilder As New DocumentBuilder(MTdoc)

'Build MTDoc content    

Dim CLDocStream As New MemoryStream
Dim MTDocStream As New MemoryStream

CLdoc.Save(CLDocStream, SaveFormat.docx)
MTdoc.Save(MTDocStream, SaveFormat.docx)

Using zip1 As New ZipFile()

    zip1.AddEntry("CL.docx", CLDocStream)
    zip1.AddEntry("MT.docx", MTDocStream)
    zip1.Save("c:/Temp/test.zip")

End Using

3 回答

  • 0

    如果您的程序在客户端的PC上运行,那么您可以使用 Process.Start(filename) 使用已注册的应用程序(例如Word或Adobe Reader)加载文档

  • 1

    我找到了解决方案 . 我在我的zip存档中获取空文件的原因是,当我将条目添加到zip存档时,内存流的位置位于流的末尾 . 当我在添加条目之前将内存流指向流的开头时,它就像一个魅力 . 修改后的代码(包括将zip存档流式传输到客户端):

    Dim CLdoc As New Document("C:/Temp/Cover Letter.docx")
    Dim CLbuilder As New DocumentBuilder(CLdoc)
    
    'Build CLDoc content
    
    Dim MTdoc As New Document("C:/Temp/Master Terms.docx")
    Dim MTbuilder As New DocumentBuilder(MTdoc)
    
    'Build MTDoc content    
    
    Dim CLDocStream As New MemoryStream
    Dim MTDocStream As New MemoryStream
    
    CLdoc.Save(CLDocStream, SaveFormat.docx)
    MTdoc.Save(MTDocStream, SaveFormat.docx)
    
    CLDocStream.Seek(0, SeekOrigin.Begin)
    MTDocStream.Seek(0, SeekOrigin.Begin)
    
    Dim ZipStream As New MemoryStream()
    
    Response.Clear()
    Response.ContentType = "application/zip"
    Response.AddHeader("Content-Disposition", "attachment;filename=Docs.zip")
    
    Using zip1 As New ZipFile()
    
        zip1.AddEntry("CL.docx", CLDocStream)
        zip1.AddEntry("MT.docx", MTDocStream)
        zip1.Save(Response.OutputStream)
    
    End Using
    
    ZipStream.WriteTo(Response.OutputStream)
    Response.End()
    
  • 0

    我在Aspose担任社交媒体开发人员 . 检查以下示例,以便在生成后立即将文档发送到客户端 .

    Document doc = new Document("input.doc");
    
    //Do you document processing
    
    //Send the generated document using Response Object.
    doc.Save(Response, "output.doc", ContentDisposition.Inline, null);
    

相关问题