Opening files with VB.NET program

前端 未结 3 1749
不知归路
不知归路 2020-12-20 07:19

I recently learned how to use VB.NET to set your program as the default for a chosen extension. You would write code to set a registry value. The problem is, when you open t

相关标签:
3条回答
  • 2020-12-20 07:26

    The path to the file is passed to your program as a command line parameter. Your program will need to read the command line parameters and react accordingly.

    Here is some example code demonstrating how to read the command line parameters:

      Sub Main()
        Dim s() As String = System.Environment.GetCommandLineArgs()
        ' write code to open the file here...
        Console.WriteLine(s(1))
      End Sub
    

    To help with debugging this you can specify command-line arguments in the Visual Studio IDE:

    1. With a project selected in Solution Explorer, on the Project menu, click Properties.
    2. Click the Debug tab.
    3. In the Command line arguments field, enter the command-line arguments you wish to use.
    0 讨论(0)
  • 2020-12-20 07:38

    You can also declare your Sub Main to receive the command line arguments:

    Sub Main(Args() As String)
    
    End Sub
    
    0 讨论(0)
  • 2020-12-20 07:39

    The filename is passed to your program by the OS

    Sub Main()
        Dim s() As String = System.Environment.GetCommandLineArgs()
    EndSub
    

    MSDN docs

    0 讨论(0)
提交回复
热议问题