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

C#
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();
              paragraph.Inlines.Add(System.IO.File.ReadAllText(filename));
              FlowDocument document = new FlowDocument(paragraph);
              FlowDocReader.Document = document;
          }
      }
Posted

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: http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats[^].

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:
http://www.c-sharpcorner.com/UploadFile/mahesh/viewing-word-documents-in-wpf[^].

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

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

"http://www.c-sharpcorner.com/UploadFile/mahesh/viewing-word-documents-in-wpf/"
 
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