Hi there,
Thanks for that clarification Roman.
As Roman explained there is no issue with that character as it's expected in the Range facade. That should of clicked at the time but I was too busy focusing on the range and not actual cause of the issue. My apologises for leading you in a circle.
The actual issue occurs because the bookmark has been inserted into a blank paragraph. This is the cause of the empty paragraph and not the character seen at the end of the range in the second document.
To remove this empty paragraph you can check for the block level node where the document is inserted and remove it if empty. Please see the code below, I'm assuming you're using the InsertDocument method provided in the documentation here.
Document doc1 = new Document("doc1.dot");
Document doc2 = new Document("doc2.dot");
BookmarkStart bookmarkstart = doc.Range.Bookmarks["IID"].BookmarkStart;
InsertDocument(bookmarkstart.ParentNode, doc2);
doc.Save("Document out.docx");
public static void InsertDocument(Node insertAfterNode, Document srcDoc)
{
// Make sure that the node is either a pargraph or table.
if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) &
(!insertAfterNode.NodeType.Equals(NodeType.Table)))
throw new ArgumentException("The destination node should be either a paragraph or table.");
// We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.ParentNode;
CompositeNode originalInsertNode = (CompositeNode)insertAfterNode;
// This object will be translating styles and lists during the import.
NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.KeepSourceFormatting);
// Loop through all sections in the source document.
foreach (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)
{
// Let's skip the node if it is a last empty paragarph in a section.
if (srcNode.NodeType.Equals(NodeType.Paragraph))
{
Paragraph para = (Paragraph)srcNode;
if (para.IsEndOfSection && !para.HasChildNodes)
continue;
}
// 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;
}
}
if(string.IsNullOrEmpty(originalInsertNode.ToTxt().Trim()))
originalInsertNode.Remove();
}
Thanks,
Adam Skelton
Programming Writer
Aspose Auckland Team