Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. File associations & File Types Editor

File associations & File Types Editor

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestionworkspace
20 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kreskowiak

    All you have to do to test your app with command line arguments is go to the Project menu, select Properties, click on the Configuration Properties folder on the left, then select the Debugging item. On the right, you'll find a blank for command line parameters. Just fill it in with the full path of the file your trying to use (without the quotes around it.) RageInTheMachine9532

    N Offline
    N Offline
    nvmoss
    wrote on last edited by
    #11

    OK, now we are getting somewhere! I can see the path string, but it includes BOTH the path to the application executable and the file whose path I put into the command line as you described. The error is probably the result of 2 drive letters and 2 colons. What am I doing wrong? Thanks again!

    D 1 Reply Last reply
    0
    • N nvmoss

      OK, now we are getting somewhere! I can see the path string, but it includes BOTH the path to the application executable and the file whose path I put into the command line as you described. The error is probably the result of 2 drive letters and 2 colons. What am I doing wrong? Thanks again!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #12

      nvmoss wrote: The error is probably the result of 2 drive letters and 2 colons. Nope...The problem is that your using Environment.CommandLine. It will return the ENTIRE command line, including the command that started your app. The solution is use Environment.GetCommandLineArgs(). This will return an array of Strings, the first of which, index 0, will be the command that started the app. Index 1 will be the first argument:

      |----------- Index 0 --------------| |------------------- Index 1 ------------------------|
      C:\Program Files\myCompany\myApp.exe C:\Documents and Settings\userID\Desktop\fileToUse.txt

      Dim cmdArgs As String()
      cmdArgs = Environment.GetCommandLineArgs()

      cmdArgs(0) will be "C:\Program Files\myCompany\myApp.exe" and cmdArgs(1) will be "C:\Documents and Settings\userID\Desktop\fileToUse.txt", of course, without the quotes. RageInTheMachine9532

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        nvmoss wrote: The error is probably the result of 2 drive letters and 2 colons. Nope...The problem is that your using Environment.CommandLine. It will return the ENTIRE command line, including the command that started your app. The solution is use Environment.GetCommandLineArgs(). This will return an array of Strings, the first of which, index 0, will be the command that started the app. Index 1 will be the first argument:

        |----------- Index 0 --------------| |------------------- Index 1 ------------------------|
        C:\Program Files\myCompany\myApp.exe C:\Documents and Settings\userID\Desktop\fileToUse.txt

        Dim cmdArgs As String()
        cmdArgs = Environment.GetCommandLineArgs()

        cmdArgs(0) will be "C:\Program Files\myCompany\myApp.exe" and cmdArgs(1) will be "C:\Documents and Settings\userID\Desktop\fileToUse.txt", of course, without the quotes. RageInTheMachine9532

        N Offline
        N Offline
        nvmoss
        wrote on last edited by
        #13

        Thanks! I tried the GetCommandArgs(), but arg 1 is only "C:\Documents" I tried a few more args (2,3, etc) and found that everytime there is a space in the path, a new argumant is created. I checked and the %1 in the File Type Arguments Prperty is in double quotes. Am I doing something wrong?

        D 1 Reply Last reply
        0
        • N nvmoss

          Thanks! I tried the GetCommandArgs(), but arg 1 is only "C:\Documents" I tried a few more args (2,3, etc) and found that everytime there is a space in the path, a new argumant is created. I checked and the %1 in the File Type Arguments Prperty is in double quotes. Am I doing something wrong?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #14

          Check the File Type association in Explorer first. I'll bet that the quotes are missing. The symptoms you are running into (spaces dictate new argument) say that this is exactly what the problem is. RageInTheMachine9532

          N 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Check the File Type association in Explorer first. I'll bet that the quotes are missing. The symptoms you are running into (spaces dictate new argument) say that this is exactly what the problem is. RageInTheMachine9532

            N Offline
            N Offline
            nvmoss
            wrote on last edited by
            #15

            Did you mean File Types in Explorer, or in the Argument Property of File Types in the Setup project of my application? I checked both. In Explorer, the "Open With" application is my application, and the Argument Property in the Setup Project is "%1". Is there another explaination? Thanks!

            D 1 Reply Last reply
            0
            • N nvmoss

              Did you mean File Types in Explorer, or in the Argument Property of File Types in the Setup project of my application? I checked both. In Explorer, the "Open With" application is my application, and the Argument Property in the Setup Project is "%1". Is there another explaination? Thanks!

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #16

              In Explorer... Open an Explorer window, on say C:, and go to the Tools menu, pick Folder Options, and click on the File Types tab. Then scroll down to your file extension and click on it. Click on the Advanced button, then click on the Open action and the Edit button. In the "Application used to perform action:" box you should see something like this, but for your app:

              C:\WINDOWS\system32\NOTEPAD.EXE "%1"

              If the quotes are not around the %1, you'll run into the problem that your having. RageInTheMachine9532

              N 1 Reply Last reply
              0
              • D Dave Kreskowiak

                In Explorer... Open an Explorer window, on say C:, and go to the Tools menu, pick Folder Options, and click on the File Types tab. Then scroll down to your file extension and click on it. Click on the Advanced button, then click on the Open action and the Edit button. In the "Application used to perform action:" box you should see something like this, but for your app:

                C:\WINDOWS\system32\NOTEPAD.EXE "%1"

                If the quotes are not around the %1, you'll run into the problem that your having. RageInTheMachine9532

                N Offline
                N Offline
                nvmoss
                wrote on last edited by
                #17

                Thanks! I looked as you suggested and the quotes are there. However, there are also quotes around the path to the executable that opens the application. I notice that there are no quotes around this path in your example. Should I remove these quotes in Explorer?

                D 1 Reply Last reply
                0
                • N nvmoss

                  Thanks! I looked as you suggested and the quotes are there. However, there are also quotes around the path to the executable that opens the application. I notice that there are no quotes around this path in your example. Should I remove these quotes in Explorer?

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #18

                  Nope. They stay there. When you test your app, put the quotes around the complete path in the Command line args under Project/Properties/Debugging. Opps! My bad. RageInTheMachine9532

                  N 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    Nope. They stay there. When you test your app, put the quotes around the complete path in the Command line args under Project/Properties/Debugging. Opps! My bad. RageInTheMachine9532

                    N Offline
                    N Offline
                    nvmoss
                    wrote on last edited by
                    #19

                    Thanks! It works now. However, if you open the ap by double clicking on a file, then double click on another file, a second instance of th app opens. is there a way to just add a second MDI Child to the first app instead, or is this the expected behavior? Thanks again, everyone has been very persistent and very helpful!

                    D 1 Reply Last reply
                    0
                    • N nvmoss

                      Thanks! It works now. However, if you open the ap by double clicking on a file, then double click on another file, a second instance of th app opens. is there a way to just add a second MDI Child to the first app instead, or is this the expected behavior? Thanks again, everyone has been very persistent and very helpful!

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #20

                      That's expected unless you code it otherwise. Your app is going to have to check for a previous instance that is already running. THis code cample is right out of the VB.NET docs:

                      ' Visual Basic .NET
                      Function PrevInstance() As Boolean
                      If Ubound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
                      Return True
                      Else
                      Return False
                      End If
                      End Function

                      You'll also have to write a mechanism so the app can communicate with another instance of itself. Look into Call Context or Asynchronous Remoting for some examples. They will look kind of wierd and you'll be wondering why your using http to send this stuff back and forth, but it's right. You'll be sending the full filename from the new instance to the old one. RageInTheMachine9532

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups