Leading blank page

I am merging multiple documents together and my final output seems to have a blank page always at the top and I cant seem to get rid of it.

Maybe the way I am going about merging the documents have something to do with it.

This is how I start off in the code:

I create my 'doc' document using a Template from the example (after setting it up per my project):

Document doc = new Document(System.IO.Path.Combine(DocPath, "MergeTemplate.doc"));

Then it goes into a loop, and if its the first loop I need to setup the Table of contents, so I have to generate it from code

before I generate it I create another 'doc' document like so:

//Open the template document

Document doc3 = new Document(System.IO.Path.Combine(DocPath, "WWHTemplate.doc"));

//Once the builder is created, its cursor is positioned at the beginning of the document.

DocumentBuilder builder = new DocumentBuilder(doc3);

//generate the TOC

bool toc = BuildTOC(builder);

Could this be way the leading page is blank and the TOC is actually the second page?

I tried using the main 'DOC' that I declared at first instead of createing doc3, but the blank page was the second page now instead of the first.

Any clue why it does this? Im not adding any pagebreaks before this code, but the blank page does seem to move when I use 'doc' instead of 'doc3'.

sorry if this is vague, cant think of a better way to explain it.

EDIT: Also note that the way I am saving this is doc3.save(), not doc.save()

I then add the saved filename to an Arraylist, because in the end of the loop I take that arraylist and loop through it, and call AppendDoc() with that filename.

Please attach the document illustrating the problem. I’ll check what could be done.

I emailed a link for you to download because it was too big to post.

Im sure you noticed this as well but thought I would be mentioning again. I opened the word document that I sent you and hit the show/hide paragraph symbol on the menu bar and noticed that the first page has a Section Break (Next Page) in it.

I tried doing a builder.movetodocumentstart() and tried to find a way to delete it. Because I actually deleted that section break and everything is normal now.

can you specify a way to delete that section break? It's not in my template and I dont see anywhere in my code where I am adding a blank page to the document. the first thing that gets added is the TOC.

Thanks for the help.

Use doc.FirstSection.Remove() to remove the first section of the document.

Thanks for the help, especially this late at nite. Awesome support you guys have.

I actually used this about 5 minutes ago, was going to come here to tell you I fixed it.

I will try your method too, im sure its a better way and the right way.

but I did this:

DocumentBuilder docTOC = new DocumentBuilder(dstDoc);

docTOC.Document.Sections.Clear();

I did this in the AppendDoc() method and before the dstDoc.ImportNodes is being used.

Ill try yours now and see what I get, im sure it works better.

Thanks again for the support this late at nite, u deserve a raise hehe.

Please mind it is better to remove the first section of the resulting document in the very end of the document generation process, not in the beginning.

Point taken, thanks for the help. Unless you say otherwise I will place that code before I do the save method.