Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Hi,I'm trying to viewing word in DocumentViewer what should I adding to this code to be able to view the word document?
C#
private void button1_Click(object sender, RoutedEventArgs e)
{
    // Create OpenFileDialog 
    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

   
    dlg.DefaultExt = ".doc";
    dlg.Filter = "Word documents|*.doc;*.docx";

    
    Nullable<bool> result = dlg.ShowDialog();

   
    if (result == true)
    {
        // Open document 
        string filename = dlg.FileName;
        FileNameTextBox.Text = filename;

        var document = DocX.Load(filename);

        string contents = document.Text;

     
    } 
}
Posted
Comments
Zoltán Zörgő 17-Nov-14 12:48pm    
Not like that. But have you even tried to look for a solution for yourself? I doubt. Since there are several out there. Even on this site. You just have to enter some words in google. Really. You might start here: http://www.faxt.com/blog/post/2009/01/04/Working-with-Docx-using-Silverlight-and-WPF-XBAP.aspx

1 solution

Word is a proprietary application, but its file format is based on the open standard, Open XML:
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats[^].

So, it possible to read the data and map it to some other component; in WPF, the best candidate would be the class FlowDocument.

Please see these articles:
http://www.c-sharpcorner.com/UploadFile/mahesh/viewing-word-documents-in-wpf[^],
Show Word File in WPF[^].

—SA
 
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