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. Getting path of executing assembly

Getting path of executing assembly

Scheduled Pinned Locked Moved C#
tutorialquestion
6 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 Offline
    D Offline
    danielk_
    wrote on last edited by
    #1

    I am trying to get the path of the executing .exe, but so far with no luck. I have tried Assembly.GetExecutingAssembly().CodeBase but this just returns the path to the .dll does anyone know how to get the path of the .exe? thanks

    M realJSOPR B 3 Replies Last reply
    0
    • D danielk_

      I am trying to get the path of the executing .exe, but so far with no luck. I have tried Assembly.GetExecutingAssembly().CodeBase but this just returns the path to the .dll does anyone know how to get the path of the .exe? thanks

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Application.ExecutablePath ist what you're looking for.

      Regards, mav -- Black holes are the places where God divided by 0...

      B 1 Reply Last reply
      0
      • D danielk_

        I am trying to get the path of the executing .exe, but so far with no luck. I have tried Assembly.GetExecutingAssembly().CodeBase but this just returns the path to the .dll does anyone know how to get the path of the .exe? thanks

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        string path1 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

        string path2 = System.Environment.CurrentDirectory;

        using System.Windows.Forms;
        string path3 = Application.ExecutablePath;

        The value for path1 on my system is "file:\\K:\\VS2008\\ConsoleTester\\ConsoleTester\\bin\\Debug" The value for path2 on my system is "K:\\VS2008\\ConsoleTester\\ConsoleTester\\bin\\Debug" The value for path3 on my system is "K:\\VS2008\\ConsoleTester\\ConsoleTester\\bin\\Debug\\ConsoleTester.exe"

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        1 Reply Last reply
        0
        • M mav northwind

          Application.ExecutablePath ist what you're looking for.

          Regards, mav -- Black holes are the places where God divided by 0...

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

          Bearing in mind this only applies to a Windows Forms application.

          Semicolons: The number one seller of ostomy bags world wide. - dan neely

          1 Reply Last reply
          0
          • D danielk_

            I am trying to get the path of the executing .exe, but so far with no luck. I have tried Assembly.GetExecutingAssembly().CodeBase but this just returns the path to the .dll does anyone know how to get the path of the .exe? thanks

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

            Assembly.GetEntryAssembly().CodeBase

            will give you the full .exe URI. To get the full file system path, use:

            Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), Path.GetFileName(Assembly.GetEntryAssembly().CodeBase));

            Semicolons: The number one seller of ostomy bags world wide. - dan neely

            D 1 Reply Last reply
            0
            • B Brady Kelly

              Assembly.GetEntryAssembly().CodeBase

              will give you the full .exe URI. To get the full file system path, use:

              Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), Path.GetFileName(Assembly.GetEntryAssembly().CodeBase));

              Semicolons: The number one seller of ostomy bags world wide. - dan neely

              D Offline
              D Offline
              danielk_
              wrote on last edited by
              #6

              thanks guys, I've got it working

              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