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 Application directory from console program

Get Application directory from console program

Scheduled Pinned Locked Moved C#
csharpquestion
6 Posts 5 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.
  • S Offline
    S Offline
    Soundman32 2
    wrote on last edited by
    #1

    I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?

    B P S A 4 Replies Last reply
    0
    • S Soundman32 2

      I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?

      B Offline
      B Offline
      Brady Kelly
      wrote on last edited by
      #2

      System.Reflection.Assembly execAsm = System.Reflection.Assembly.GetExecutingAssembly(); string asmPath = execAsm.CodeBase.Replace("file:///", "").Replace('/', '\\'); MessageBox.Show(asmPath);

      S 1 Reply Last reply
      0
      • B Brady Kelly

        System.Reflection.Assembly execAsm = System.Reflection.Assembly.GetExecutingAssembly(); string asmPath = execAsm.CodeBase.Replace("file:///", "").Replace('/', '\\'); MessageBox.Show(asmPath);

        S Offline
        S Offline
        Soundman32 2
        wrote on last edited by
        #3

        I'd just got to that point, but I'm using : System.Reflection.Assembly.GetExecutingAssembly().Location Thanks.

        1 Reply Last reply
        0
        • S Soundman32 2

          I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Application.ExecutablePath works anyway, try it before you discard it. "We learn more from our mistakes than we do from getting it right the first time."

          1 Reply Last reply
          0
          • S Soundman32 2

            I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?

            S Offline
            S Offline
            Stefan Prodan
            wrote on last edited by
            #5

            That's easy, just use AppDomain.CurrentDomain.BaseDirectory to get the running directory and add to it your console application name and you have a path just like Application.ExecutablePath.

            http://stefanprodan.wordpress.com

            1 Reply Last reply
            0
            • S Soundman32 2

              I am writing a C# console program that needs to read a file from the same directory as the application. I can't use the current directory as that is not the same as the application directory. Normally I would use Application.ExecutablePath, but console apps don't derive from Application. Ideas?

              A Offline
              A Offline
              AFSEKI
              wrote on last edited by
              #6

              Application.ExecutablePath or Environment.CurrentDirectory for your need ;) Hope this helps...

              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