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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to get a application pathi in run time? in C#

How to get a application pathi in run time? in C#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
12 Posts 4 Posters 1 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.
  • B babutkchn

    Hi All, Warm New Year Greetings. Can anyone of you tell me how to get the application path during run time in C#. Please do reply. Regards Babu

    V Offline
    V Offline
    Venkatesh P
    wrote on last edited by
    #2

    If u want to get the path of your application, then use the below code: System.Reflection.Assembly.GetExecutingAssembly().Location Thanks & Regards, Venkat

    B 1 Reply Last reply
    0
    • B babutkchn

      Hi All, Warm New Year Greetings. Can anyone of you tell me how to get the application path during run time in C#. Please do reply. Regards Babu

      Mircea PuiuM Offline
      Mircea PuiuM Offline
      Mircea Puiu
      wrote on last edited by
      #3

      Happy New Year to you, too! Use Application.ExecutablePath and Application.StartupPath, or use the System.Reflection namespace to get the properties of your assembly: System.Reflection.Assembly.GetExecutingAssembly.Location

      SkyWalker

      V B 2 Replies Last reply
      0
      • Mircea PuiuM Mircea Puiu

        Happy New Year to you, too! Use Application.ExecutablePath and Application.StartupPath, or use the System.Reflection namespace to get the properties of your assembly: System.Reflection.Assembly.GetExecutingAssembly.Location

        SkyWalker

        V Offline
        V Offline
        Venkatesh P
        wrote on last edited by
        #4

        HI.. How to get the path of the folder or file that the user has clicked in the windows explorer

        Thanks & Regards, Venkat

        1 Reply Last reply
        0
        • Mircea PuiuM Mircea Puiu

          Happy New Year to you, too! Use Application.ExecutablePath and Application.StartupPath, or use the System.Reflection namespace to get the properties of your assembly: System.Reflection.Assembly.GetExecutingAssembly.Location

          SkyWalker

          B Offline
          B Offline
          babutkchn
          wrote on last edited by
          #5

          Thank you for your kind response.i need to get the path in console application.but in console application Application.ExecutablePath and Application.StartupPath are not working. Is there any other way. babu

          Mircea PuiuM 1 Reply Last reply
          0
          • V Venkatesh P

            If u want to get the path of your application, then use the below code: System.Reflection.Assembly.GetExecutingAssembly().Location Thanks & Regards, Venkat

            B Offline
            B Offline
            babutkchn
            wrote on last edited by
            #6

            Thank you venkat... Babu

            1 Reply Last reply
            0
            • B babutkchn

              Hi All, Warm New Year Greetings. Can anyone of you tell me how to get the application path during run time in C#. Please do reply. Regards Babu

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #7

              Hello, Happy new year! I think "System.Environment.CurrentDirectory" is what you need. All the best, Martin

              Mircea PuiuM 1 Reply Last reply
              0
              • B babutkchn

                Thank you for your kind response.i need to get the path in console application.but in console application Application.ExecutablePath and Application.StartupPath are not working. Is there any other way. babu

                Mircea PuiuM Offline
                Mircea PuiuM Offline
                Mircea Puiu
                wrote on last edited by
                #8

                Of course they are working :-) You just have to add the System.Windows.Forms reference, then add the using System.Windows.Forms; line to your Program.cs file. After that, a line of code like this one: string S = Application.ExecutablePath; will return the information you need.

                SkyWalker

                1 Reply Last reply
                0
                • M Martin 0

                  Hello, Happy new year! I think "System.Environment.CurrentDirectory" is what you need. All the best, Martin

                  Mircea PuiuM Offline
                  Mircea PuiuM Offline
                  Mircea Puiu
                  wrote on last edited by
                  #9

                  Not quite, Martin :-) It returns the directory from which this process starts. During the running, the current directory may change. Then you need to use the Application.ExecutablePath.

                  SkyWalker

                  M 1 Reply Last reply
                  0
                  • Mircea PuiuM Mircea Puiu

                    Not quite, Martin :-) It returns the directory from which this process starts. During the running, the current directory may change. Then you need to use the Application.ExecutablePath.

                    SkyWalker

                    M Offline
                    M Offline
                    Martin 0
                    wrote on last edited by
                    #10

                    Hello!

                    Mircea Puiu wrote:

                    During the running, the current directory may change

                    You mean the path where the exe was called changes? OK, I never took care of that. But, I mainly use "System.Environment.CurrentDirector" because of it's design time support. All the other methods I tested return an obscure design path. All the best, Martin

                    Mircea PuiuM 1 Reply Last reply
                    0
                    • M Martin 0

                      Hello!

                      Mircea Puiu wrote:

                      During the running, the current directory may change

                      You mean the path where the exe was called changes? OK, I never took care of that. But, I mainly use "System.Environment.CurrentDirector" because of it's design time support. All the other methods I tested return an obscure design path. All the best, Martin

                      Mircea PuiuM Offline
                      Mircea PuiuM Offline
                      Mircea Puiu
                      wrote on last edited by
                      #11

                      No, no! The current directory is the same with the executable path when the app starts. You may change the current directory (by using a file dialog for example), and that has nothing to do with the execution path.

                      SkyWalker

                      M 1 Reply Last reply
                      0
                      • Mircea PuiuM Mircea Puiu

                        No, no! The current directory is the same with the executable path when the app starts. You may change the current directory (by using a file dialog for example), and that has nothing to do with the execution path.

                        SkyWalker

                        M Offline
                        M Offline
                        Martin 0
                        wrote on last edited by
                        #12

                        Ohh, Ok, I got it now! I was thinking he needs only the exe path. Thanks for the info! All the best, Martin

                        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