none
Get all lines from MS Word header and footer using Interop PIA in C# RRS feed

  • Question

  • I am trying to get all lines from the header and footer in a word doc. I am using the following code:

    HeaderFooter header = this.Doc.Sections[1].Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
    string text = header.Range.Text;

    But the Range.Text property always seems to return the last line. If my header has:

    Header line 1

    Header line 2

    Header line 3

    My code always return "Header line 3". I get similar results for the footer. I have tried calling header.Range.WholeStory(). I have tried calling header.Range.Paragraphs and tried iterating over the Paragraphs collection. I am at a complete loss. The documentation on MSDN is cryptic and I can't find my way through it. Any help would be appreciated.

    FWIW: I am writing a utility in C# to verify that each document a large library of word documents conforms to a company wide template. The template calls for the header and footer to contain certain information (title, document number, date, etc). Each datum will also be checked against a regex. I know the use of fields, bookmarks, etc. would be elegant but I am afraid the documents I am working with simply have the information embedded as text in the header and the footer.

    (I posted the same question on SO here: http://stackoverflow.com/questions/38175889/get-all-lines-from-ms-word-header-and-footer-using-interop-pia-in-c-sharp)

    Monday, July 4, 2016 1:52 AM

Answers

All replies

  • Hi dFlatttttttttt,

    you had got the solution by yourself and you had posted that solution on Stack overflow where you created a thread for the same issue on the above mentioned link in your original post.

    so i would recommend you to post the same Answer here on this thread and update the status of the thread.

    so that other member can know you had already got the answer for your issue.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 4, 2016 11:57 PM
    Moderator
  • Solution for the above mentioned issue is posted on the link below by the dFlatttttttttt.

    To get the solution please visit link below.

    Get all lines from MS Word header and footer using Interop PIA in C#

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 14, 2016 9:02 AM
    Moderator