Sunday, March 6, 2011

Opening Files With Their Associated Program Using Visual Basic.net

A while back I needed to include a video in a visual basic windows forms application i was building. I didn't want to add a third party control even though that wouldn't have been a bad solution. Instead I just wanted to include the files with the software and have the launch on the end users computer using Windows Media Player or whatever video software they had. So I came up with the easy solution below. You can set the file to be opened with windows explorer, and the computer will find and open the file in whatever application the user has set up on their machine to handle that file type. In the example below I used a .wmv video file.

Dim FilePath As String = "\jrconvvidoes\FinalOverview.wmv"
Process.Start("Explorer", FilePath)

If you are deploying the file with the visual studio one click installer, you need to use the following code to access the file in the application folder.


Dim FilePath As String = My.Application.Info.DirectoryPath & "\jrconvvidoes\FinalOverview.wmv"
Process.Start("Explorer", FilePath)

No comments:

Post a Comment