C# - 关联文件类型并在WebBrowser控件中打开它?

时间:2009-11-10 08:24:25

标签: c# file browser file-association

如何打开文件(比如说.html文件)并将其加载到WinForm应用程序的WebBrowser控件中?我正在谈论右键单击该文件并选择使用我的应用程序打开它。有什么想法吗?

3 个答案:

答案 0 :(得分:2)

您可以将其作为命令行参数传递。在应用程序中,您应该分析命令行参数并将文件加载到WebBrowser中。

答案 1 :(得分:0)

我从来没有在Windows中预先填充Open With菜单,我总是手动添加新项目。

如果你想创建一个完整的关联,这里有一些代码:

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

(对不起VB,它是从interwebs偷来的)

答案 2 :(得分:0)

我假设您要做的是以编程方式创建文件关联 - 为此,您需要在注册表中创建相应的条目。

有一篇文章介绍了如何通过codeproject here

中的代码完成此操作

或者,您可以使用安装程序创建关联。