Search code examples
c#ms-wordadd-in

while reading the word document,need to add invisible text into it


I am developing a word add-in, for some purpose i need to read a word document.So according to my business purpose am reading the document by each paragraph and storing each paragraph from the word into a data table and i need to add a text "VERIFIED" into that paragraph for some purpose. My problem is how to store that word "VERIFIED" in a paragraph. I have treied adding in two manner

  • Hidden Text and
  • Comments For each paragraph in word i have tried these two ways,In this above ways the disadvantage is " User can easily edit or delete the text,if i added in the above mentioned ways". So is there anyother ways to meet my requirement.?

Solution

  • I would suggest to use ContentControl (CC) in your situation. There are few possibilities how you could take advantage of CC but, in my opinion, best option is to wrap each verified paragraph into CC.

    The following code is written in Word-VBA which you can easily convert into C# code:

    Dim par As Paragraph
    
    'set reference to appropriate paragraph
    Set par = ActiveDocument.Paragraphs(2)
    
    Dim cc As ContentControl
    Set cc = ActiveDocument.ContentControls.Add( _
                wdContentControlRichText, par.Range)
    
    cc.Tag = "VERIFIED"
    
    'options
    'disable deletion of CC
    cc.LockContentControl = True
    
    'disable edition of CC
    cc.LockContents = True