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. C#
  4. Get file that spawned the application.

Get file that spawned the application.

Scheduled Pinned Locked Moved C#
toolstutorialquestion
5 Posts 3 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.
  • C Offline
    C Offline
    cmarcus
    wrote on last edited by
    #1

    Hey Ya'll.. I'm building a little analyzer utility that will analyze text files automatically. Currently you have to click the Open Files button to load a file to analyze. I'd like to mod this program so that if you double click the file you want to analyze, it will spawn the analyzer and automatically analyze the contents of the clicked file. I've set my PC to always Open With the analyzer when you click on the files with my extension, but I'm at a loss on how to get the filename / path of the file that spawned it. Can anyone point me in the right direction? Thanks in advance -Chris

    S J C 3 Replies Last reply
    0
    • C cmarcus

      Hey Ya'll.. I'm building a little analyzer utility that will analyze text files automatically. Currently you have to click the Open Files button to load a file to analyze. I'd like to mod this program so that if you double click the file you want to analyze, it will spawn the analyzer and automatically analyze the contents of the clicked file. I've set my PC to always Open With the analyzer when you click on the files with my extension, but I'm at a loss on how to get the filename / path of the file that spawned it. Can anyone point me in the right direction? Thanks in advance -Chris

      S Offline
      S Offline
      Stephan Samuel
      wrote on last edited by
      #2

      Chris, I'm going to assume that you've set the file type in Folder Options in Explorer to load your application automatically. In the Advanced dialog, you get the command line to run. Using %1 on the command line should give you the FQ path to the file that was double-clicked. Change "c:\program files\myapp\myapp.exe" to "c:\program files\myapp\myapp.exe" %1 Make your Main() into Main(string[] args), and args should contain the path/file that was clicked on. Stephan

      C 1 Reply Last reply
      0
      • C cmarcus

        Hey Ya'll.. I'm building a little analyzer utility that will analyze text files automatically. Currently you have to click the Open Files button to load a file to analyze. I'd like to mod this program so that if you double click the file you want to analyze, it will spawn the analyzer and automatically analyze the contents of the clicked file. I've set my PC to always Open With the analyzer when you click on the files with my extension, but I'm at a loss on how to get the filename / path of the file that spawned it. Can anyone point me in the right direction? Thanks in advance -Chris

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        It should be passing the filename as the first argument to your app. void Main(string[] args) { // args[0] should contain your filename if double clicked from explorer under default setup for associating extesions with executables } Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

        1 Reply Last reply
        0
        • S Stephan Samuel

          Chris, I'm going to assume that you've set the file type in Folder Options in Explorer to load your application automatically. In the Advanced dialog, you get the command line to run. Using %1 on the command line should give you the FQ path to the file that was double-clicked. Change "c:\program files\myapp\myapp.exe" to "c:\program files\myapp\myapp.exe" %1 Make your Main() into Main(string[] args), and args should contain the path/file that was clicked on. Stephan

          C Offline
          C Offline
          cmarcus
          wrote on last edited by
          #4

          Got it.. Seems to be working great! Thanks a lot!! -Chris

          1 Reply Last reply
          0
          • C cmarcus

            Hey Ya'll.. I'm building a little analyzer utility that will analyze text files automatically. Currently you have to click the Open Files button to load a file to analyze. I'd like to mod this program so that if you double click the file you want to analyze, it will spawn the analyzer and automatically analyze the contents of the clicked file. I've set my PC to always Open With the analyzer when you click on the files with my extension, but I'm at a loss on how to get the filename / path of the file that spawned it. Can anyone point me in the right direction? Thanks in advance -Chris

            C Offline
            C Offline
            cmarcus
            wrote on last edited by
            #5

            What was working is now not! I'm not exactly sure where the problem resides, but after I built my installer, and installed the application on my PC everything seemed to be fine. Then when I click the log file to analyze, it keeps opening back up using notepad. So I went to Open With.., and browsed to my .exe, and checked the option to always open files with this extention. When I double click the file now I get a critical error stating that the LOG file I double clicked and it's path is not a valid Win32 Application. How do I reset the target so that when I click the log file, it uses my .exe as the application?

            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