How to figure out what is root folder of my program at start up? [modified]
-
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?
Application.ExecutablePath, I believe. It's something like that.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
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?
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.
-
Application.ExecutablePath, I believe. It's something like that.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
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
-
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?
-
Application.ExecutablePath, I believe. It's something like that.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
I use Application.StartupPath...
Contact me! Please feel free to visit my site
-
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
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
-
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
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...
-
I use Application.StartupPath...
Contact me! Please feel free to visit my site
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
-
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?
kinda' late but maybe it will help ... Application.StartupPath
-
kinda' late but maybe it will help ... Application.StartupPath
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...