none
Word Paragraph.ID property save and retain RRS feed

  • Question

  • Hi,

    I am working on the C# Word document addin and trying to insert predefined text as paragraph. This is working all good, but when the document the loaded again, i wanted to read all those insert paragraph.

    I tried using Word Paragraph.ID and tried saving unique guid in it. But when the document is loaded again. paragraphid is null.

    Is there any other field i can use to save some unique id with paragraph and later use it when the doc is opened again.

    regards


    Pushpendra

    Wednesday, September 7, 2016 7:26 PM

All replies

  •  

    According to Paragraph.ID property,

    It returns or sets the identifying label for the specified object when the current document is saved as a Web page.

    Microsoft Word does not store the ID property setting for a Range object. If you set the ID property and then return its value, the returned value will be an empty string.

     

    Since the paragraph is read by the ordinal position, and we couldn’t identify the specific paragraph by its properties, I suggest you use content controls to save predefined text.

    Please visit How to: Add Content Controls to Word Documents

    Friday, September 9, 2016 11:26 AM
    Moderator
  • Content controls is not helping here as per my requirement. What i have is set of predefined paragraph  which i am displaying in the right pane of WORD. Users can select any of those  (displayed on the right side) and insert them in the document. So ideally, user is inserting predefined paragraph in the document. I just wanted to somehow read it even later when the document is save and opened elsewhere. Can i associate any custom properties here and save it with the document.

    Pushpendra

    Thursday, September 22, 2016 3:38 PM
  •  

    I think you could use AutoText. Add predefined paragraph into AutoTextEntries, you could retrieve them since they are stored in the templates.

    You could visit AutoTextEntries.Add Method (Word) &  AutoTextEntries.Item Method (Word)

        private void AddAutoText_Click(object sender, RibbonControlEventArgs e)
            {
                Range rng = Globals.ThisDocument.Application.Selection.Range;
                var tem = Globals.ThisDocument.Application.ActiveDocument.get_AttachedTemplate();
                AutoTextEntries autoTexts = tem.AutoTextEntries;
                AutoTextEntry newautoText = autoTexts.Add("New Auto Text", rng);
              
            }
    
            private void ReadAutoText_Click(object sender, RibbonControlEventArgs e)
            {
                var tem = Globals.ThisDocument.Application.ActiveDocument.get_AttachedTemplate();
                AutoTextEntries autoTexts = tem.AutoTextEntries;
                foreach (AutoTextEntry autoText in autoTexts)
                {
                    System.Windows.Forms.MessageBox.Show(autoText.Name + autoText.Value);
                    //System.Diagnostics.Debug.Print(autoText.Name + autoText.Value);
                }
            }



    Friday, September 23, 2016 11:08 AM
    Moderator