Hi we are having issue when updated to newer version of Aspose.Words.
It appears to exhibit different behaviour on new version: when section break is essentially remove by removing the bookmark containing it, it remove the previous sections header/footer in the new version, which we want to keep, and the header/footer is preserved on the older version.
Here is the simplified code:
Bookmark? bmToRemove = null;
foreach(var bm in doc.Range.Bookmarks)
{
if (bm.Name == "FSR")
{
bmToRemove = bm;
}
}
if (bmToRemove is not null)
{
bmToRemove.Text = "";
bmToRemove.Remove();
}
@DougT Aspose.Words behavior has indeed changed in this respect since version 18.8. It has become similar to MS Word behavior, and you can verify this by running
ActiveDocument.Bookmarks("FSR").Range.Delete
Just like MS Word, Aspose.Words moves the contents of the first section to the second one along with the header/footer, while leaving the attributes of the document root section. Actually, your Header is not deleted, you can see it via setting
after deleting the bookmark. However, please, keep in mind that you may need to copy other section attributes (such as page sizes) in case they had different values āābefore this deletion.
Yes Iāve tested the code you provided to put the header back, looks like the header are still there, but the PageSetup was merged back to the section following it? I think it could be the work around I am looking.
I also agree that what the new version of Aspose doing seems mapping Words behaviour, for example, when I delete the bookmark/Sectionbreak using Microsoft Words, the header/footer also disappeared, to me thatās exactly the new Aspose is doing. but I am still trying to understand the exact changes caused the change of behaviour and trying to reverse the change for our case, as there are documents to be modified and some are tricky to get right and testing.
On the other hand I donāt agree with you that the change is from version 18.8, Iāve testing a few different versions of Aspose.Words, and based on my test, the behaviour is maintained until version 21.10. Please see my attached project which using version 21.9 and the header are still maintained, but not on version 21.10.
I do not state that the changes were carried out in version 18.8, I pointed out that the behavior has changed since then.
The difference from the previous behavior is that the content of the previous section is moved to the next one, and not vice versa. To demonstrate the difference Iāve attached your modified document to the post. I changed the root section PageSize there, you can run the code on the current and the old versions and see the difference. So to keep the behavior similar to the old version, you will need to copy the values from the previous section to the new one. BookmarkSecbrkInputEdtd.docx (14.0 KB)
So in the newer version, when the sections get merged, all the content from the section before the section break atomically inherent style form the later section, is that right?
I think Iāll have to copy the content from later section into the previous section, then delete the later section, basically reverse the new behaviour by code.
You donāt need to copy the content of the sections, Aspose.Words code does it for you, this is not a completely obvious and safe task. To achieve the previous behavior, you need to copy the PageSetup. Copy PrevSection.PageSetup values to NextSection.PageSetup. It is safe.
I am having issue with the approach you suggested, I got error message āCS0200 Property or indexer āSection.PageSetupā cannot be assigned to ā it is read onlyā.