Free Support Forum - aspose.com

Autonumber formatting issue with ImportNode

This line of code...

public static void CombineDocuments(Aspose.Words.Document parentDoc, Aspose.Words.Document subDoc, bool startOnNewPage)

{

int count = 0;

foreach (Section srcSection in subDoc)

{

Section dstSection = null;

dstSection = (Section)parentDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);

Get's the following error with the attached doc if it uses an autonumber. If it doesn't everything works fine.

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at Aspose.Words.Lists.ListLevelCollection.get_Item(Int32 index)
at Aspose.Words.Lists.ListCollection.?(? ?, Int32 ?, Boolean ?)
at Aspose.Words.StyleCollection.?(? ?, Style ?, Style ?)
at Aspose.Words.StyleCollection.?(? ?, Style ?)
at Aspose.Words.Lists.ListCollection.?(? ?, Int32 ?, Boolean ?)
at Aspose.Words.NodeImporter.ImportNode(Node srcNode, Boolean isImportChildren)
at Aspose.Words.NodeImporter.?(CompositeNode ?, CompositeNode ?, Boolean ?)
at Aspose.Words.NodeImporter.ImportNode(Node srcNode, Boolean isImportChildren)
at Aspose.Words.NodeImporter.?(CompositeNode ?, CompositeNode ?, Boolean ?)
at Aspose.Words.NodeImporter.ImportNode(Node srcNode, Boolean isImportChildren)
at Aspose.Words.DocumentBase.ImportNode(Node srcNode, Boolean isImportChildren, ImportFormatMode importFormatMode)
at Systrends.TMS.Business.DocumentGeneration.CombineDocuments(Document parentDoc, Document subDoc, Boolean startOnNewPage) in C:\Documents and Settings\Davids\My Documents\Visual Studio 2008\Projects\tms\trunk\business\DocumentGeneration.cs:line 1291

I have attached copies of the documents that work and that do not work. I tested this with 8.2.1, 8.2.2, and 9.0 and all the get same error.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce the problem on my side. I used the following code for testing:

Document dst = new Document(@"Test001\DocumentWorking.doc");

Document src = new Document(@"Test001\DocumentNotWorking.doc");

dst.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);

dst.Save(@"Test001\out.doc");

Please try using Document.AppendDocument built-in method to combine documents.

Hope this helps.

Best regards.

Thank you for testing it. I changed to Document.AppendDocument and it still happened. I didn’t give you the original document it was being combined with. I will put together a test winform app and give it to you.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you please attach your original documents here or create a simple application which will allow me to reproduce the problem on my side? I will check it and provide you more information.

Best regards,