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. How to figure out what is root folder of my program at start up? [modified]

How to figure out what is root folder of my program at start up? [modified]

Scheduled Pinned Locked Moved C#
tutorialquestion
12 Posts 6 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.
  • T TrooperIronMan

    So I want to poll for example if program is in "C:\prog1\" I want to put this path in string at program start up, so i can manipulate files accoring to that as root folder?

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #3

    Application.ExecutablePath, I believe. It's something like that.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

    T D 2 Replies Last reply
    0
    • T TrooperIronMan

      It actually happened to me few times some files ended who know where when I only set file names in program and no path... (all work fine with absolute path but I don't want to hard code it) so I want to prevent this behavior?

      J Offline
      J Offline
      justintimberlake
      wrote on last edited by
      #4

      string originalPath =System.Reflection.Assembly.GetExecutingAssembly().CodeBase; will this work for you. this gives full path of ur exe file u have to parse to get the path only.

      1 Reply Last reply
      0
      • C Christian Graus

        Application.ExecutablePath, I believe. It's something like that.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        T Offline
        T Offline
        TrooperIronMan
        wrote on last edited by
        #5

        Thank you both, I tried

        Christian Graus wrote:

        Application.ExecutablePath,

        and it work just fine, I'll try other method too. Does anyone know maybe why XMLTextWriter write file who know where sometimes if only file name is specified (and it's almost random, sometimes it end up where it need to be)? This way it work fine

        C 1 Reply Last reply
        0
        • T TrooperIronMan

          So I want to poll for example if program is in "C:\prog1\" I want to put this path in string at program start up, so i can manipulate files accoring to that as root folder?

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

          Try Application.ExecutablePath There is also and another property which return the applications folder. Sorry currently i don't have access to VS

          1 Reply Last reply
          0
          • C Christian Graus

            Application.ExecutablePath, I believe. It's something like that.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            D Offline
            D Offline
            David Domingues
            wrote on last edited by
            #7

            I use Application.StartupPath...

            Contact me! Please feel free to visit my site

            T 1 Reply Last reply
            0
            • T TrooperIronMan

              Thank you both, I tried

              Christian Graus wrote:

              Application.ExecutablePath,

              and it work just fine, I'll try other method too. Does anyone know maybe why XMLTextWriter write file who know where sometimes if only file name is specified (and it's almost random, sometimes it end up where it need to be)? This way it work fine

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #8

              If you don't specify a path, the working directory will be used.  It's usually the same, but not always.

              Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

              T 1 Reply Last reply
              0
              • C Christian Graus

                If you don't specify a path, the working directory will be used.  It's usually the same, but not always.

                Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                T Offline
                T Offline
                TrooperIronMan
                wrote on last edited by
                #9

                Yeah for example if array list is same on serialization like one I deserialized in (data didn't change) than it remain same, but if I added something to it... then it isn't go figure...

                1 Reply Last reply
                0
                • D David Domingues

                  I use Application.StartupPath...

                  Contact me! Please feel free to visit my site

                  T Offline
                  T Offline
                  TrooperIronMan
                  wrote on last edited by
                  #10

                  I'll try this also... although other solution work nice... but as they say there is always more than one way to do something in programming

                  1 Reply Last reply
                  0
                  • T TrooperIronMan

                    So I want to poll for example if program is in "C:\prog1\" I want to put this path in string at program start up, so i can manipulate files accoring to that as root folder?

                    R Offline
                    R Offline
                    Radu Sorin
                    wrote on last edited by
                    #11

                    kinda' late but maybe it will help ... Application.StartupPath

                    T 1 Reply Last reply
                    0
                    • R Radu Sorin

                      kinda' late but maybe it will help ... Application.StartupPath

                      T Offline
                      T Offline
                      TrooperIronMan
                      wrote on last edited by
                      #12

                      Radu Sorin wrote:

                      kinda' late but maybe it will help ... Application.StartupPath

                      Thanks... it's not late all things I do in C# for now are only my learning so more I know better... I'll implement all options to see if there is any difference...

                      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