Click here to Skip to main content
16,020,537 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
Hi this is my code:

C#
private void button1_Click(object sender, EventArgs e)
{
    String strFileName;

    //Find the Office document.
    openFileDialog1.FileName = "";
    openFileDialog1.ShowDialog();
    strFileName = openFileDialog1.FileName;

    //If the user does not cancel, open the document.
    if (strFileName.Length != 0)
    {
        Object refmissing = System.Reflection.Missing.Value;
        oDocument = null;
        webBrowser1.Navigate(strFileName);
    }
}


here i used webbrowser control for loading word document files.but this code not load a wordfile in my application...here my document file displayed separately..so please tell how can i load word documents in my webbrowser control using c# windows application.
Posted
Comments
Sergey Alexandrovich Kryukov 3-Aug-12 14:09pm    
Why? What requirements can justify such risky investment?
--SA

Bad idea. Word is a proprietary product. Not only the customers will have to pay for the license, there would be a vendor lock-in (http://en.wikipedia.org/wiki/Vendor_lock-in[^]) on the product, no compatibility, nothing good.

Think about: 1) HTML; 2) System.Windows.Forms.RichTextBox; 3) System.Windows.Controls.RichTextBox; 4) WPF Flow Document; 5) something else.

Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx[^],
http://msdn.microsoft.com/en-us/library/aa970909.aspx[^].

[EDIT]

At the same time, Word file format compatibility is the easier problem. After all, OpenOffice, LibreOffice and other products support all versions of the format, please see:
http://en.wikipedia.org/wiki/OpenOffice.org[^],
http://en.wikipedia.org/wiki/LibreOffice[^].

If you would like to support only the newer Office Open XML, the format itself is available and is standardized under ECMA-376 and ISO/IEC 29500:2008:
http://en.wikipedia.org/wiki/Office_Open_XML[^],
http://en.wikipedia.org/wiki/Office_Open_XML_software[^].

Please see the comparison chart on Office Open XML software:
http://en.wikipedia.org/wiki/Comparison_of_Office_Open_XML_software[^].

As some source code is available and open, you can use it.

—SA
 
Share this answer
 
v5
Comments
Kenneth Haugland 3-Aug-12 14:19pm    
Very good. 5.
Sergey Alexandrovich Kryukov 3-Aug-12 14:24pm    
Thank you, Kenneth. By the way, just updated with a big [EDIT] on Office Open XML.
--SA
 
Share this answer
 
To display a Word document you need to embed the Word OCX and read its documentation. Obviously, this requires that the user's machine has Word on it. A web browser, including the IE in the WebBrowser object, will typically start an external program to open this kind of document.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-12 14:16pm    
That's right (voted 5). That's why I recommended to consider different alternatives -- please see my answer.
--SA

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