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?
+2
A:
You can pass it as command line parameter. Than in your application you should analyze command line parameters and load file into WebBrowser.
Alex
2009-11-10 08:28:14
Yea this is what I need, but I'm not sure how to do it.
Nate Shoffner
2009-11-10 08:33:32
1. Modify your main function in the following way: static void Main(string[] args)2. Analyze args array and open file in your browser (e.g. using WebBrowser.navigate())
Alex
2009-11-10 10:19:26
If you do not want to do all this in Main - you can use Environment.GetCommandLineArgs()
Alex
2009-11-10 10:20:55
A:
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)
ck
2009-11-10 08:30:02
I really don't recommend writing to HKCR. The writes get redirected to HKLM anyway. If this is an all user/default machine setting: HKLM (Needs elevated privileges). If this is a per-user setting: HKCU (only user rights needed).
Factor Mystic
2009-11-10 18:13:20
A:
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.
Murph
2009-11-10 08:37:04