how to open selected files through the default application of the file in VB 2010?

前端 未结 2 1798
温柔的废话
温柔的废话 2021-01-19 02:16

I have Windows application written in VB 2010.Here, user may select any file from open dialog.So, I want to open the file in corresponding application.for example, suppose u

2条回答
  •  孤街浪徒
    2021-01-19 02:55

    Shell and the Windows API CreateProcess() are for starting executable files. If you're loading a document/file then these are handled by ShellExecute() and can be initiated in .NET using the Process.UseShellExecute property:

    Private Function ShellExecute(ByVal File As String) As Boolean
      Dim myProcess As New Process
      myProcess.StartInfo.FileName = File
      myProcess.StartInfo.UseShellExecute = True
      myProcess.StartInfo.RedirectStandardOutput = False
      myProcess.Start()
      myProcess.Dispose()
    End Function
    

    Taken from the #VB wiki.

提交回复
热议问题