Hi,
I’m getting some strange behavior from Aspose when I try to change the text of a certain bookmark. Essentally I want to loop through a document, and set the text of any bookmark which is simply “#” to empty.
Here is a snippet of my code:
foreach (Aspose.Words.Bookmark bm in doc.Range.Bookmarks)
{
string temp = bm.Text;
string temp2 = bm.Text.Trim();
if (temp2 == "#")
{
bm.Text = "";
}
}
For the problem bookmark in question, I’m finding that bm.Text = “\r”, temp = “#\r” and temp2 = “#”. Then when I try to set bm.Text I get an error:
System.ArgumentException occurred
HResult=0x80070057
Message=Cannot insert a node of this type at this location.
Source=Aspose.Words
StackTrace:
at Aspose.Words.CompositeNode.(Node , Node , Boolean )
at Aspose.Words.CompositeNode.(Node , Node , Node )
at .()
at .( )
at .()
at Aspose.Words.Bookmark.set_Text(String value)
I can’t see any reason why “temp” should ever be different from bm.Text since that’s what its assigned to, but nevertheless that’s what it does! If I put a breakpoint into my code and step through, the error doesn’t occur, which makes me think that this is some kind of weird timing issue in Aspose itself.
I can PM the problem document to anyone who is interested, but my client would rather I not post it on a public forum.
Thanks,
Adam