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

Free Support Forum - aspose.com

Layout's update affects the document tree

Dear Sir or Madam,

Here is my scenario.

  1. Create a table.
  2. Append with this table the last section’s body.
  3. Verify that table.ParentNode is this body.
  4. Call UpdatePageLayout.
    After this call table.ParentNode == null. Is it expected behavior? In my understanding any operation on layout shouldn’t affect the document tree. Is there any way to avoid setting ParentNode to null in this case?

Regards,
Alex ParentLink.zip (272.6 KB)

@AlexanderNovickov,

Please use the Table.EnsureMinimum(); method before appending it to Body. Here is sample code to get the expected behavior:

Document d = new Document("E:\\ParentLink\\test1.docx");

Table t = new Table(d);
t.EnsureMinimum();
d.LastSection.Body.Tables.Add(t);
if (t.ParentNode == null)
{
    throw new InvalidOperationException("First check");
}
d.UpdatePageLayout();
if (t.ParentNode == null)
{
    throw new InvalidOperationException("Second check");
} 

Hope, this helps.

Hi Awais,

Thank you for you reply, but I am afraid this workaround is not acceptable as it just adds an extra row (which I do not need) into my table. My opinion is that any operation on Layout (which is performed by Aspose and to which I am as a developer don’t have any access) shouldn’t change my document’s tree.

Regards,
Alex

@AlexanderNovickov,

We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-18225. We will further look into the details of this requirement/problem and will keep you updated on the status of the linked issue.

@AlexanderNovickov,

Regarding WORDSNET-18225, we have completed the work on your issue and concluded to close this issue as ‘Not a Bug’. Please see following analysis details:

This is by Aspose.Words’ design. Table is empty and is removed by validator. Aspose.Words throws a warning message for such scenario (see Receive Warnings). If table would have some rows with paragraphs inside, it would not then be removed.