在Windows资源管理器中,双击PDF可在Adobe Reader中打开文档。完善!
但我的Winforms应用程序中的PROCESS.START(pdfdocumentpath)在IE中打开PDF。是否有某个设置允许PROCESS.START(或其他VB.NET代码)以与Windows资源管理器相同的方式打开文档?
我的一些用户拥有32位计算机,其中一些拥有64位计算机。有些有Adobe Reader,有些有Adobe Acrobat。有些可能是版本或更多版本,有些可能是最新版本。有些人会将产品放在标准位置,有些可能已将其安装在其他位置。
我想要做的是在Adobe Reader中打开文档,如果有的话,打开Adobe Acrobat。
我该如何做到这一点?
答案 0 :(得分:2)
使用try catch。
并且您并不总是需要提供路径。"有些程序可以从名称开始#"
Adobe acrobat = acrobat
Acrobat reader = AcroRd32
Visual studio = devenv
等等
现在代码:)
首先检查文件是否存在If If.Computer.FileSystem.FileExists(FilePath)然后
如果文件存在则执行尝试。"如果不存在MsgBox("找不到文件。")"
首先尝试打开Adobe Acrobat" Process.Start(" acrobat",FilePath)"
如果那个dos不起作用,请再试一次
所以现在尝试打开acrobat reader。" Process.Start(" AcroRd32",FilePath)"
再次,如果这不起作用,请使用捕捉再做一次尝试
但现在只需使用" Process.Start(FilePath)"。
因此,在最后一次捕获中,您告诉用户安装acrobat reader。 :)
Dim FilePath As String = "C:\Test.pdf"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists(FilePath) Then
Try
Process.Start("acrobat", FilePath)
Catch ex As Exception
Try
Process.Start("AcroRd32", FilePath)
Catch ex2 As Exception
Try
Process.Start(FilePath)
Catch ex3 As Exception
MsgBox("Instal Acrobat Reader")
End Try
End Try
End Try
Else
MsgBox("File not found.")
End If
End Sub