Possible Duplicate:
How do I find out what directory my console app is running in with C#?
How to get current working directory of a console that runs a program so I could resolve relative paths passed as program args?
Lets say I've put my program here: c:\tools\program.exe
But I'm invoking it from various places. Lets say I'm here: C:\Users\Me\Documents\
and I run this command program.exe --src=somefile.txt --dest=subdir\otherfile.txt
Environment.CurrentDirectory
and System.Reflection.Assembly.GetExecutingAssembly().Location
will return c:\tools
but I would like to be able to resolve somefile.txt
and subdir\oterfile.txt
paths that are relative to C:\Users\Me\Documents\
.
====== UPDATE ======
Thank you for your help. It seems that
Environment.CurrentDirectory
works as expected. It turned out that in my case the problem was caused by Xenocode's Postbuild tool (now called Spoon Virtual Application Studio) that I occasionally use to "pack" all program's files (including dlls, config, etc.) into one executable. It's very handy, but in this case the "virtualization" feature messed up my program'sEnvironment
variables. I've managed to solve that issue.