Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1021611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:20:09+00:00 2026-05-16T11:20:09+00:00

I am trying to retrieve the value of all fields in a word document

  • 0

I am trying to retrieve the value of all fields in a word document via office automation using c#. The code is shown below however if the field is a drop-down then the value of the range text is always empty even though I know it is populated. If it is a simple text field then I can see the range text. How do I get the selected drop down item? I feel there must be something quite simple that I’m doing wrong…

private void OpenWordDoc(string filename) {
  Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
  Document doc = app.Documents.Open(filename, ReadOnly: true, Visible: false);

  foreach (Field f in doc.Fields) {
    string bookmarkName = "??";
    if (f.Code.Bookmarks.Count > 0) {
      bookmarkName = f.Code.Bookmarks[1].Name; // have to start at 1 because it is vb style!
    }
    Debug.WriteLine(bookmarkName);
    Debug.WriteLine(f.Result.Text); // This is empty when it is a drop down field
  }
  doc.Close();
  app.Quit();
}
  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:20:10+00:00Added an answer on May 16, 2026 at 11:20 am

    Aha – If I scan through FormFields instead of Fields then all is good…

    foreach (FormField f in doc.FormFields) { 
      string bookmarkName = "??"; 
      if (ff.Range.Bookmarks.Count > 0) { 
        bookmarkName = ff.Range.Bookmarks[1].Name; // have to start at 1 because it is vb style! 
      } 
      Debug.WriteLine(bookmarkName); 
      Debug.WriteLine(ff.Result); // This is empty when it is a drop down field 
    } 
    

    Problem solved. Phew.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve a value from an Array. Here is the code:
I am trying retrieve user name from the code through graph api, the below
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I am trying to store/retrieve a value that is stored in the Application Settings.
I am trying to retrieve the correct value from an ArrayList of objects (.NET
I'm trying to retrieve mulitple checked value, which are being showed in JSP dynamically,
I am trying edit the header cell value when using a grid view in
I'm trying to export ALL records from a Visual Collection to excel. My code
I am trying to retrieve the value of a dropdown list by specifying its
I'm trying to find the best way to retrieve fields from a table, depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.