NateShoffner
NateShoffner

Reputation: 16829

C# - Associate a file type and open it within WebBrowser control?

How would I be able to open a file (lets say an .html file) and load it into the WebBrowser control on my WinForm application? I'm talking about right clicking on the file and choosing to open it with my application. Any ideas?

Upvotes: 1

Views: 1104

Answers (3)

Murph
Murph

Reputation: 10190

I'm assuming what you want to do is create a file association programmatically - to do this you need to create the appropriate entries in the registry.

There is an article on how this might be done from code at codeproject here

Alternatively you can create associations with an installer.

Upvotes: 0

cjk
cjk

Reputation: 46425

I've never had the Open With menu prepopulated in Windows, its always been populated by me adding new items manually.

If you want to create a full association, here is some code:

Public Sub associate(EXT As String, FileType As String, _
   FileName As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject("wscript.shell")
b.regwrite "HKCR\" & EXT & "\", FileType
b.regwrite "HKCR\" & FileType & "\", "MY file"
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", FileName
b.regwrite "HKCR\" & FileType & "\shell\open\command\", _
   FileName & " %L"
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName

End Sub

(sorry about the VB, its stolen from teh interwebs)

Upvotes: 0

Alex
Alex

Reputation: 95

You can pass it as command line parameter. Than in your application you should analyze command line parameters and load file into WebBrowser.

Upvotes: 2

Related Questions