How to get exception if source of cross reference not exist

Hi,

We are using Aspose words dll 10.5 .0 to produce highly customized
documents.

In our application the document may have cross - refernce to figure / tables.We are generting the output document by using ASpose HTML from the input document.

Now if there is a scenario in which the source (text/figure/table) to a reference is missing (In the attached document there is no source correcponding to “Figure 2” at page 2 ) then if we manually do “updateField” in the generated document it gives “Error! Reference source not found.” because the Figurte 2 does not exists in the input document.

We are using the code available at : https://forum.aspose.com/t/102957 to
get the REF as a hyperlink in our HTML

So please let us know through this code (in the above link) is there any way we can get the clue/exception if no source exists for a reference.

Thanks,
Samanvay

Hi
Thanks for your request. Sure you can. REF fields usually point to bookmarks. Upon converting REF fields to HYPERLINK you extract name of the bookmark (see the code). So you should simply check whether the document contain bookmark with the specified name:
https://reference.aspose.com/words/net/aspose.words/bookmarkcollection/
Best regards,

Hi

Thanks for your quick response.

Can you please share the code with us how can we achive this or any link which show how we throw the exception if bookmark is not preasent in input document.

Thanks
Samanvay.

Hi
Thanks for your request. Sure, here is a code:

string bookmarkName = "test";
Document doc = new Document("test.doc");
// Throw an exception of the document does not contain bookmarks with specified name.
if (doc.Range.Bookmarks[bookmarkName] == null)
    throw new ArgumentException("There is no bookmark with specified name in the document.");

Best regards,