3

I'm trying to make my program have the ability to display a Microsoft Word file on a form but not having any luck in doing so. I want to be able to open the file and display it on the form as a Read-Only. So basically just display it's contents. Various users on the web have recommended displaying files in the WebBrowser control (under toolbox). I have tried this but failed to get it working. My end goal is to be able to annotate on top of the web browser (or something of similar manner) and subsequently save the annotations along with the opened file.

I'm not that experienced in the C# language too so any help on how to achieve my problem would be greatly appreciated.

user513951
  • 12,445
  • 7
  • 65
  • 82
Lloyd
  • 435
  • 3
  • 12
  • 29

2 Answers2

6

You need a DOCX viewer control. My company recently gave away our multi-format WinForms viewer control as a free product - XtremeDocumentStudio .NET Free. It can display DOCX and is available on NuGet. It does not require a Web Browser control for embedding an online viewer or Word software installed locally. http://www.nuget.org/packages/XtremeDocumentStudio.NETFree/

enter image description here

gn1
  • 526
  • 2
  • 5
  • 1
    Hi, I've installed the package onto my computer and into my project but I'm not sure how would I get the documentViewer to display on my form. There is no option for it under the toolbar? – Lloyd Feb 16 '15 at 16:55
  • 1
    I've seen a video that the DocumentViewer option is displayed at the bottom of the toolbar under General? But I have no options there – Lloyd Feb 16 '15 at 17:04
  • It says under Manage NuGet Packages that it has been fully installed too which is odd. I have also run the code to activate the free edition – Lloyd Feb 16 '15 at 17:23
  • ok so I managed to browse for the component .dll and got it appearing in the toolbox. But when I pass a file path for it to open I get an error saying: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in Gnostice.Free.Documents.Controls.WinForms.dll Additional information: Exception has been thrown by the target of an invocation. What could be causing this issue? – Lloyd Feb 16 '15 at 19:27
  • You just need to right-click on the tab and add select "Choose items" to add the viewer component to the Toolbox. – gn1 Feb 20 '15 at 03:29
  • You may also need to register at PDFOne downloads page and get a free license key. The license key needs to be used in the constructor. – gn1 Feb 20 '15 at 03:30
  • The reflection issue was fixed in the Nuget package recently. Please get a fresh copy and add the new DLLs to your project. – gn1 Feb 20 '15 at 04:26
  • 1
    This solution is *not* free for open source projects. – Kelson Ball Aug 23 '16 at 20:46
  • 1
    As of 1.08.2020 it's no longer free. Their pricing starts at $450.00 for a single developer PRO license. I wish I would've been able to get it when it was free. I simply can't afford their requested price. Looking at their site, it appears to be very much worth what they're asking. https://www.gnostice.com/XtremeDocumentStudio_dot_NET.asp – Gregbert Jan 10 '20 at 22:09
1

There are some good links that might help you. First, you will find a closely related or similar question here And in that conversation someone posted the following link which is about how to build a user control for displaying Word documents in a webbrowser control.

I also found another article here about how to integrate Excel in a Windows Form application using WebBrowser. But Excel is used as an example and you may be able to adapt it to Word.

Community
  • 1
  • 1
alainlompo
  • 4,414
  • 4
  • 32
  • 41
  • I have tried the first two links and I couldn't get the code working :/ – Lloyd Feb 15 '15 at 12:06
  • Interop is sensitive and adaptations are required from one version to the other. Here is one of the founding articles regarding opening office documents in .Net apps. It is targeting VS 2005 though. http://support2.microsoft.com/?scid=kb%3Ben-us%3B304662&x=11&y=11 – alainlompo Feb 15 '15 at 15:54