Combining word documents

Hi,

I require to combine my word documents to one document. Does the current version support direct combining of documents, like doc.Append(anotherDoc) ? Or is it possible to add “Filialdokumente” (sorry, I don’t know the english synonym for that)?

If not I will have to copy/move the sections, right? I read in another thread posted here that the overall size of such “combined” documents (or any document at all) is restricted to a size barrier. Has this changed?

Direct appending of documents is not currently supported.

You need to use ImportNode to copy sections from one document into another:

private void buttonAppendTest_Click(object sender, System.EventArgs e)
{
    string fn1 = Application.StartupPath + "\\" + "doc1.doc";
    string fn2 = Application.StartupPath + "\\" + "doc2.doc";
    Document doc1 = new Document(fn1);
    Document doc2 = new Document(fn2);
    AppendDoc(doc1, doc2);
    doc1.Save(Application.StartupPath + "\\" + "doc1 + 2.doc");
}

private void AppendDoc(Document dstDoc, Document srcDoc)
{
    for (int i = 0; i < srcDoc.Sections.Count; i++)
    {
        //First need to import the section into the destination document,
        //this translates any document specific lists or styles.
        Section section = (Section)dstDoc.ImportNode(srcDoc.Sections, true);
        dstDoc.Sections.Add(section);
    }
}

I don’t know of any size limitation for this process. If you have seen this information here on the forums please give me a reference.

Ok thanks for the input. Here is the reference.

That was almost two years ago. The situation has significantly improved since then.

I can’t get this code to work,

private void AppendDoc(Document dstDoc, Document srcDoc)
{
    for (int i = 0; i < srcDoc.Sections.Count; i++)
    {
        //First need to import the section into the  destination document,
        //this translates any document specific lists or  styles.
        Section section = (Section)dstDoc.ImportNode(srcDoc.Sections, true);
        dstDoc.Sections.Add(section);
    }
}

I have included a reference in my project and added the namespace to my
class by “using Aspose;” but I am constantly being told that Document
is not a namespace or object, Section is not a namespace, reference or
object etc etc etc.

And I even get told that is not a namespace.

Any help?

p.s. can an option be added to these forums in order to remove the emoticons from posts.

Document, Section and most of the other classes belong to Aspose.Words namespace (Aspose.Word for versions before 3.5). You need to include

using Aspose.Words;

line in your project.

Thanks, I am still not able to get this to work however.

This is what I have placed as my code,

private void AppendDoc(Document dstDoc, Document srcDoc)
{
    for (int i = 0; i < srcDoc.Sections.Count; i++)
    {
        //First need to import the section into the destination document,
        //this translates any document specific lists or styles.
        Section section = (Section)dstDoc.ImportNode(srcDoc.Sections, true);
        dstDoc.Sections.Add(section);
    }
}

private void btnFinish_Click(object sender, System.EventArgs e)
{
    // Main Build and Retrieval Area!!
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    // Specify font formatting for the hyperlink.
    builder.Font.Color = System.Drawing.Color.Black;
    // Display our selected vars.
    builder.Writeln(mySource);
    builder.Writeln(myDest);
    builder.Writeln(myInitials);
    builder.Writeln(myName);
    builder.Writeln(myPeriod);
    string myDesktop = "C:\\Documents and Settings\\Administrator\\Desktop";
    string fn1 = myDesktop + "\\" + "doc1.doc";
    string fn2 = myDesktop + "\\" + "doc2.doc";
    Document doc1 = new Document(fn1);
    Document doc2 = new Document(fn2);
    AppendDoc(doc1, doc2);
    doc.Save("C:\\Documents and Settings\\Administrator\\Desktop\\testing.doc");
    this.Close();
}

Please ignore the references to the 5 myVars in the writeln functions.
My main problem is that doc1 and doc2 are not being inserted into the
new document.

Please take attention that you code appends ‘doc2.doc’ to ‘doc1.doc’, but saves quite another file ‘testing.doc’.

Thanks Miklovan, I think I am just having one of those days