Checking checkbox using bookmark

Hello,


I'm trying to checking checkbox inside a word document using bookmark to get to the checkbox.

Only checkbox form field (legacy) are recognized, but i could got them with bookmark. I change the checked status and save. Opening the word, checkbox are unchecked. I can change text and add image using bookmark, but for checkbox i don't find how to do it.

In fact, i can have checked box if i delete the bookmark content and add a new checkbox, but i'm also loosing formatting.


My code :


internal void Checkbox(BookmarksNavigator bookmarkNavigator, string BookName)

        {

            bookmarkNavigator.MoveToBookmark(BookName);

            TextBodyPart part = bookmarkNavigator.GetBookmarkContent();

            var body = part.BodyItems[0] as WParagraph;

            var item = body.ChildEntities.FirstItem;

            var check = item as WCheckBox;

            check.Checked = true;

             //// I tried theses command too

            //check.CalculateOnExit = true;

            //check.Update();

        }

After i save the stream and open the doc.




7 Replies 1 reply marked as answer

LB Lokesh Baskar Syncfusion Team September 21, 2021 10:45 AM UTC

Hi Gregory,

Thank you for contacting Syncfusion support. 

From the given details we have found that your requirement is to check the check box using bookmark Navigator. We have prepared the sample application to achieve your requirement. Please find the sample from the below link.
https://www.syncfusion.com/downloads/support/forum/168999/ze/ConsoleCoreSample-703528298.zip

In the above sample we have done the following things.
1. Loaded the input template document. 
2. Created the bookmark navigator instance to access the bookmark content and after retrieved of WCheckBox, the check box is checked.
3. After modified the check box status, replace the TextBodyPart using bookmark navigator to get reflect the changes in the DOM level of word document.

Please refer the UG documentation link given below.
https://help.syncfusion.com/file-formats/docio/working-with-form-fields#check-box

Regards,  
Lokesh B 



GR gregory September 22, 2021 09:13 AM UTC

Thank this indeed working !

Although, it's erase content after the checkbox.

In this lighty modified word document, content after checkbox are erased, even other checkbox with another bookmark.







LB Lokesh Baskar Syncfusion Team September 23, 2021 09:12 AM UTC

Hi Gregory, 

Thank you for your update.  

We have tried to reproduce the reported issue content after checkbox are erased, but the issue has not reproduced at our end. So could you please share us the input Word document, simple sample application which reproduce the issue and screenshot of the issue. This will be more helpful for us to replicate the same problems at our end. Thereby, we will proceed further and share the appropriate solution at the earliest.

Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same.

Regards, 
Lokesh B 
 



GR gregory September 23, 2021 10:19 AM UTC

Sorry, didn't notice the link wasn't present in my post.


https://easyupload.io/vzvw8s


Before

before.png


After

after.png



LB Lokesh Baskar Syncfusion Team September 24, 2021 05:01 PM UTC

Hi Gregory, 

Thank you for your update.  

If your requirement is to check the checkbox for a particular named bookmark means, then you can iterate the paragraph items has checkbox and check the checkbox based on the particular bookmark name. We have prepared the sample application to achieve your requirement. Please find the sample from the below link. 
https://www.syncfusion.com/downloads/support/forum/168999/ze/ConsoleCoreSample-1080216764.zip

In the above sample we have done the following things.
1. Loaded the input template document.  
2. Iterates the paragraph items which contain checkbox and then check the checkbox based on the particular bookmark name.
3. Saves the Word document.

Regards,   
Lokesh B  


Marked as answer

GR gregory September 25, 2021 08:15 AM UTC

It's working perfectly.


Thank you for your excellent support.



LB Lokesh Baskar Syncfusion Team September 27, 2021 08:04 AM UTC

Hi Gregory, 
 
Thank you for your update. 
 
We are glad to know that your problem has been fixed. 
 
Please let us know if you have any other questions and we will be happy to assist you as always. 
 
Regards, 
Lokesh B 


Loader.
Up arrow icon