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

Free Support Forum - aspose.com

MoveToBookmark returns false for a bookmark in the document

Unable to get MoveToBookmark to work for an existing document. The function always returns false.

Here is my test code:

Document doc = new Document(@"C:\temp\Marvin.docx");

DocumentBuilder builder = new DocumentBuilder();
var myBookmark = doc.Range.Bookmarks["Signature"];
bool status1 = builder.MoveToBookmark(myBookmark.Name);
Assert.That(status1 == true, "MoveToBookmark Signature failed");
builder.Writeln("this is some Signature text");

@jeffmangasarian,
Could you please ZIP and attach your input document ? We will investigate the issue and provide you information on it.

Here is document.Marvin.zip (22.7 KB)

@jeffmangasarian The problem occurs because in your code you do not pass Document object into the DocumentBuilder constructor. Your code should looks like this:

Document doc = new Document(@"C:\temp\Marvin.docx");

DocumentBuilder builder = new DocumentBuilder(doc ); // Pass the Document into the constructor.
var myBookmark = doc.Range.Bookmarks["Signature"];
bool status1 = builder.MoveToBookmark(myBookmark.Name);
Assert.That(status1 == true, "MoveToBookmark Signature failed");
builder.Writeln("this is some Signature text");

When you use DocumentBuilder constructor without parameters it creates an empty document internally. So in your case the builder was not associated with your document.

Thank you. Yes that works.