Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am new at ASP.NET programming. My problem is about merging word documents in server. When user sends a request, the program will merge all word documents,which is in one x folder in server. Then, it will send this merged word document to user. How can I do it? Can you give me some advice about it?

Thanks,
Posted

hi

you can use third party dll for it

aspose dll

hope it will help:)
 
Share this answer
 
 
Share this answer
 
Comments
Çağlar Tolga Tetik 3-Jan-12 4:23am    
Thanks. But I forgot to say it. I have to use open XML.
Hi,

if you want to concatenate multiple C# DOCX files, you can do it easily with this C# / VB.NET Word component, and then ASP.NET export to Word so user can download the final document with a browser.

Here is a sample C# code:
C#
// Use the component in free mode.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");

// Create document instance that will contain all concatenated input documents.
var finalDocument = new DocumentModel();

// For each input document.
foreach (string filePath in filePaths)
{
  // Load an input document.
  var document = DocumentModel.Load(filePath, LoadOptions.DocxDefault);

  // Import and add every input document section to the final document.
  foreach (var section in document.Sections)
    finalDocument.Sections.Add(finalDocument.Import(section, true));
}

// Microsoft Packaging API cannot write directly to Response.OutputStream.
// Therefore we use temporary MemoryStream.
using (MemoryStream documentStream = new MemoryStream())
{
  finalDocument.Save(documentStream, SaveOptions.DocxDefault);

  // Stream file to browser.
  Response.Clear();
  Response.ContentType = "application/vnd.openxmlformats";
  Response.AddHeader("Content-Disposition", "attachment; filename=Document.docx");

  documentStream.WriteTo(Response.OutputStream);

  Response.End();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900