Issue Table Of Content Related Issue

How can use ‘do not show in table of content’ setting using code during generate the template.
And why Table of content is not update after using the below code.

worddoc.UpdateFields();
worddoc.UpdatePageLayout();

plz suggest how can achieve this using code to given below image.

It is only update to heading in left menu not in Table of content plz see below screen shot.

@RiteshK10 Could you please attach your input document here for testing? We will check the issue and provide you more information.
Your code is correct. To update TOC you should use Document.UpdateFields and Document.UpdatePageLayout methods.