Hello
I am replacing the text inside bookmarks. Everything works fine when the bookmarks have some characters between them. As soon as two bookmarks adjacent (like [bookmark1][bookmark2] ) then the following Exception occurs:
An unhandled exception of type ‘System.InvalidOperationException’ occurred in mscorlib.dllAdditional information: Collection was modified; enumeration operation may not execute.
I suspect that this happen because the two bookmarks “melt together” as soon as I replace the text of one bookmark.
I would prefer to leave the two bookmarks intact, so that I could call my routine again and again, thus refreshing the document data.
How can I meet this requirement ?
// My code:
Aspose.Word.Document doc = new Aspose.Word.Document (@“c:\test.doc”);
foreach (Aspose.Word.Section section in doc.Sections)
{
foreach (Aspose.Word.Bookmark bm in section.Range.Bookmarks)
{
bm.Text = “dummy data”;
}
}
doc.Save (@“c:\test.doc”);