Append to DocumentBuilder

Hi
I need to know how to append Document content with DocumentBuilder.
Here By am attaching a word template.In the template i have three lines
using DocumentBuilder i need to add table after the tree lines and i need to how to delete the table from the template using DocumnetBuilder
Regards
Ajeesh

Hi Ajeesh,

Thank you for inquiry. Please follow up the documentation link below to append multiple documents.

Joining and Appending Documents

code snippet to delete table:

// Create document object
Document doc = new Document("d:/temp/temp.docx");
// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];
// Get the table that this bookmark is contained in.
Table table = (Table) bookmark.BookmarkStart.GetAncestor(NodeType.Table);
// Remove the table
table.Remove();

Hope this will help. In case of any ambiguity, please let me know.

hi
Actually i don’t want to append two separate douments,if check my template you will understand,i have h tamplate with some content, i need to display the template with existing content plus new content
Ex: in template i have
Company Name
Project name
After this line i need to add a new content as a Table

Hi
Ajeesh,

Thanks for your inquiry. First of all, please note that DocumentExplorer is a very useful tool which easily enables us to see the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. Below is the DOM structure of your document as viewed with DocumentExplorer:

Also, you can achieve what you need by using the following code snippet:

Document doc = new Document(@"c:\test\Template.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToParagraph(2, 0);

// We call this method to start building the table.
builder.StartTable();
builder.InsertCell();
builder.Write("Row 1, Cell 1 Content.");

// Build the second cell 
builder.InsertCell();
builder.Write("Row 1, Cell 2 Content.");

// Call the following method to end the row and start a new row.
builder.EndRow();

// Signal that we have finished building the table.
builder.EndTable();

doc.Save(@"c:\test\out.docx");

If we can help you with anything else, please feel free to ask.

Best Regards,