Search code examples
vb.netmedia-playerfilenamesfilepath

VB.NET get path from the file the user opened


I am developing a media player based on WMP. If the user sets my media player as the default player to play .avi files for example, then clicks a random .avi file, my player will start successfully, however it will not load the file that the user opened. So thats why I need a code that will get the path of the file the user opened, so that I can make the player load that file automatically after it has been started.


Solution

  • Use the My.Application.CommandLineArgs property. This gets you a list of commandline arguments. Launching a file from the explorer usually provides the path to the clicked file as the only argument, so use it like:

    If My.Application.CommandLineArgs IsNot Nothing AndAlso _
       My.Application.CommandLineArgs.Count > 0 Then
        Dim UserFile As String = My.Application.CommandLineArgs(0)
        PlayFile(UserFile)
    End If