Free Support Forum -

Insert document at bookmark not working

I am trying to insert insertme.doc into ProductSOSTemp1.doc at bookmark 'ScopeOfSupply'. I am not getting any errors but the document is not being inserted.

Here is my code:

private void button2_Click(object sender, EventArgs e)


InsertDocument(@"c:\testing\ProductSOSTemp1.doc",@"c:\testing\insertme.doc","ScopeOfSupply",@"c:\testing\newdoc.doc",@"c:\program files\cooper power systems\eagle admin install\");


public void InsertDocument(String afterNode, String doc, String bmark, String NewDoc, String sLicense)


Aspose.Words.License license = new Aspose.Words.License();


Node insertAfterNode;

Aspose.Words.Document dstDoc = new Aspose.Words.Document(afterNode);

LoadFormat format = Aspose.Words.Document.DetectFileFormat(doc);

Aspose.Words.Document srcDoc;

if (format == LoadFormat.Unknown)


//If format is unknown, maybe this is HTML (issue #3955)



srcDoc = new Aspose.Words.Document(doc, LoadFormat.Html, string.Empty);




throw new ArgumentException("Input file format is unknown");





srcDoc = new Aspose.Words.Document(doc);




insertAfterNode = dstDoc.Range.Bookmarks[bmark].BookmarkStart.ParentNode;




throw new ArgumentException("Invalid arguments - AsposeComWrapper");


// We need to make sure that the specified node is either pargraph or table.

if (!((insertAfterNode.NodeType == NodeType.Paragraph) ||

(insertAfterNode.NodeType == NodeType.Table)))

throw new ArgumentException("The destination node should be either paragraph or table.");

// We will be inserting into the parent of the destination paragraph.

CompositeNode dstStory = insertAfterNode.ParentNode;

// This object will be translating styles and lists during the import.

NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document,


// Loop through all sections in the source document.

foreach (Aspose.Words.Section srcSection in srcDoc.Sections)


// Loop through all block level nodes (paragraphs and tables) in the body of the section.

foreach (Node srcNode in srcSection.Body)


// Do not insert node if it is a last empty paragarph in the section.

Aspose.Words.Paragraph para = srcNode as Aspose.Words.Paragraph;

if ((para != null) && para.IsEndOfSection && !para.HasChildNodes)


// This creates a clone of the node, suitable for insertion into the destination document.

Node newNode = importer.ImportNode(srcNode, true);

// Insert new node after the reference node.

dstStory.InsertAfter(newNode, insertAfterNode);

insertAfterNode = newNode;






Thanks for your inquiry. Actually “insertme.DOC” it is not a .DOC it is HTML. If you try open/save this HTML using MS Word and then insert into the destination document the problem disappears. Please let me know in case of any issues. I will be glad to help you.

Best regards,

Furthermore, this HTML is not valid. There is an extra table without rows and cells..



<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta name="GENERATOR" content="Microsoft FrontPage 4.0">

<meta name="ProgId" content="FrontPage.Editor.Document">




<table border="1" width="100%" cellpadding="0" cellspacing="0">

<table border="0" width="100%" cellpadding="0" cellspacing="0">


<td width="70%">

<font face="Arial">14400V 150KVAR 2BU-22in./22in. 125BIL 60HZ</font>







Removing the extra table fixed it… Thank You!!!