Click here to Skip to main content
15,939,243 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have this code viewing text file documents how can change it to be able to view word documents instead of txt file

private void button1_Click(object sender, RoutedEventArgs e)
          // Create OpenFileDialog
          Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

          // Set filter for file extension and default file extension
          dlg.DefaultExt = ".txt";
          dlg.Filter = "Text documents (.txt)|*.txt";

          // Display OpenFileDialog by calling ShowDialog method
          Nullable<bool> result = dlg.ShowDialog();

          // Get the selected file name and display in a TextBox
          if (result == true)
              // Open document
              string filename = dlg.FileName;
              FileNameTextBox.Text = filename;

              Paragraph paragraph = new Paragraph();
              FlowDocument document = new FlowDocument(paragraph);
              FlowDocReader.Document = document;

Word is a proprietary product not designed for providing components to other software developers, not at the time being. At the same time, the present-day Word document format is open, based on the Open XML standard:[^].

Therefore, it can be used to read the Word file and translate it to something else; for WPF, it should better be based on FlowDocument. Please see this article:[^].

You can do your Web search and find other solutions based on similar ideas.

Share this answer
Please go through this page, will help you

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900