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

Free Support Forum - aspose.com

I am not able to get the bookmark content in 2 scenarios using Aspose Word


I am not able to get the bookmark content in 2 scenarios using Aspose Word

1) If the source document has only one bookmark
2)I am able to get all the bookmarks content except last bookmark content, If the source document has more than one bookmark.

This is the code I am using…Please look into this
// Load in the document
string mDataDir = @“C:\4.docx”;
Document doc = new Document(mDataDir);
    <span style="color:green;">// Retrieve the bookmark from the document.</span>
    Aspose.Words.<span style="color:#2b91af;">Bookmark</span> bookmark = doc.Range.Bookmarks[<span style="color:#a31515;">"Bookmark1"</span>];

    <span style="color:green;">// We use the BookmarkStart and BookmarkEnd nodes as markers.</span>
    <span style="color:#2b91af;">BookmarkStart</span> bookmarkStart = bookmark.BookmarkStart;
    <span style="color:#2b91af;">BookmarkEnd</span> bookmarkEnd = bookmark.BookmarkEnd;

    <span style="color:green;">// Firstly extract the content between these nodes including the bookmark. </span>
    <span style="color:#2b91af;">ArrayList</span> extractedNodesInclusive = ExtractContent(bookmarkStart, bookmarkEnd, <span style="color:blue;">true</span>);
    <span style="color:#2b91af;">Document</span> dstDoc = GenerateDocument(doc, extractedNodesInclusive);
    dstDoc.Save(mDataDir + <span style="color:#a31515;">"TestFile.BookmarkInclusive Out.doc"</span>);

    <span style="color:green;">// Secondly extract the content between these nodes this time without including the bookmark.</span>
    <span style="color:#2b91af;">ArrayList</span> extractedNodesExclusive = ExtractContent(bookmarkStart, bookmarkEnd, <span style="color:blue;">false</span>);
    dstDoc = GenerateDocument(doc, extractedNodesExclusive);
    dstDoc.Save(mDataDir + <span style="color:#a31515;">"TestFile.BookmarkExclusive Out.doc"</span>);</pre></div><div><br></div><div>Please find my attached sample word document for your reference.</div><div><br></div><div>I would greatly appreciate it if you kindly provide the solution at earliest.</div><div><br></div><div>Thanks,</div>

Hi Srini,

Thanks for your inquiry. Perhaps, you are using an older version of Aspose.Words; as with Aspose.Words v14.11.0, I am unable to reproduce this problem on my side. I would suggest you please upgrade to the latest version of Aspose.Words i.e. v14.11.0 and let us know how it goes on your side. I hope, this will help.