3

I am using windows forms web browser control in my forms application and having issues with displaying .doc or .docx file.

All the pdf files seems to work fine but when I select word file it comes up with file down load dialog with open, save and cancel options.

The code I am using here is

  Try
        If (dlgOpen.ShowDialog() = DialogResult.OK) Then
            If (File.Exists(dlgOpen.FileName)) Then
                 wbPreview.Navigate(dlgOpen.FileName)
            End If
        End If
  Catch ex As Exception
        MsgBox(ex.Message, MsgBoxStyle.Critical)
  End Try

Then I tried using Microsoft WebBrowser control as describes in How to use the WebBrowser control in Visual Basic to open an Office document where I ended up with the same issue. Any ides of working this out?

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99

3 Answers3

1

There's a solution to this, but I'm not sure how practical it is. It incurs modifications to the user registry (although it doesn't require admin rights):

  • Determine the most recent ProgID of Microsoft Word. HKEY_CLASSES_ROOT\Word.Document\CurVer has it. For example, it contains Word.Document.12.
  • Add/update the following keys and values under HKEY_CURRENT_USER\Software\Classes\Word.Document.12:
REGEDIT4

[HKEY_CURRENT_USER\Software\Classes\Word.Document.12]
@="Microsoft Word Document"
"BrowserFlags"=dword:80000024
"EditFlags"=dword:00010000

[HKEY_CURRENT_USER\Software\Classes\Word.Document.12\CLSID]
@="{F4754C9B-64F5-4B40-8AF4-679732AC0607}"
  • Now WebBrowser will load .DOC and .DOCX files in-place. This is a hack which is barely documented, more info.

  • You should save any existing registry values and put the new ones in upon WebBrowser.Navigating, then restore the originals upon WebBrowser.Navigated. This idea has been verified with Office 2010 and IE10.

noseratio
  • 59,932
  • 34
  • 208
  • 486
1

Found this workaround on microsoft support

For applications that require Office files to open inside the Web browser window, use the following workaround. However, this Internet Explorer feature may not exist in future operating systems that are later than Windows Vista.

Full article can be found here A new window opens when you try to view a 2007 Microsoft Office program document in Windows Internet Explorer 7 or Internet Explorer 8

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99
-1

The main problem is the web browser doesn't know how to open a docx file, so instead it offers it up as a download. Have it open in the computer's default viewer for that file type.

Community
  • 1
  • 1
bruestle2
  • 727
  • 1
  • 8
  • 22