We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Words - have a document content replace a known string in another document

We are evaluating Aspose.Words, for a simple job of taking an entire document and injecting it instead of a pre-known string in another document.

the Document.Range.Replace() does not provide a decent enough solution as it only accepts strings, thereby ruining the formatting of the injected document content.

Using your examples we’ve been able to concatenate two documents perfectly, but that’s not exactly what we’re after.

foreach (Section srcSection in document2)
Node dstSection = document1.ImportNode(srcSection, true, mode);

Hi Stu,

Can you please share your input documents and a sample document to show your expected output?

Best Regards,

Hey, thanks for replying.

There is no need for an example document, we need exactly what is shown on at the bottom of your documentation page named: Inserting a Document During Replace at:


unfortunately we're using an old 8years old version of aspose.words and the IReplacingCallback interface does not exist on it. so trying to do it manually.

using the forums and your blessed documentation, managed to get this done in a way by taking the document, splitting it to two documents at the exact position of the string, then, concatenate all three documents into one document.

Not sure its the most efficient way of doing so, but it seems to be almost flawless.
only one thing, when concatenated it creates three different pages.

srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;

Seems to do nothing, no matter how it's being played with,
the concatenation always creates a new page per document
(using the code from the first post to join them)

So still struggling a bit.

Hi Stu,

Older than one year releases are not available for download and you are using a very old version (8 years old) so we will not be able to test anything with that release.

Also, thousands of new features and fixes have been added since then so we will recommend using the latest version in your case to produce your desired output.

Best Regards,