Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Thu Feb 27, 2020 6:13 pm

How do you determine if a bookmark exists in a document or not?

matthewlewis
 
Posts: 2
Joined: Thu Feb 27, 2020 11:37 am

Fri Feb 28, 2020 2:39 am

Hi,

Thanks for your inquiry.
You could collect the bookmark with the code document.Bookmarks, then determine if there are bookmarks in the document.
Code: Select all
            Document document = new Document(FilePath + @"Example.docx");
            var bookmarkcount = document.Bookmarks.Count;
            if (bookmarkcount > 0)
            {
                //This means there are bookmarks in your document.
            }

Any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3067
Joined: Tue Sep 06, 2016 8:30 am

Fri Feb 28, 2020 10:47 am

Hi,

Thanks for the reply - would I be able to tell if a specific bookmark was within a document, for example if 'bookmark1' exists in document1.dotx?

Kind Regards

Matt

matthewlewis
 
Posts: 2
Joined: Thu Feb 27, 2020 11:37 am

Mon Mar 02, 2020 2:08 am

Hi Matt,

Thanks for your information.
Please refer to following code:
Code: Select all
            Document document = new Document(FilePath + @"Example.docx");
            var bookmark = document.Bookmarks.FindByName("bookmark1");
            if (bookmark == null)
            {
                //There is no bookmark named "bookmark1"
            }
            else
            {
                //The bookmark "bookmark1" exists in document
            }


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3067
Joined: Tue Sep 06, 2016 8:30 am

Fri Mar 06, 2020 8:25 am

Hi,

Hope you are doing well.
Has your issue been resolved? Could you please give us some feedback at your convenience?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3067
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc