Zayko in the Net

Personal blog of Vitaly Zayko

NAVIGATION - SEARCH

Another way to get path to a running assembly or how to get list of command line arguments in a non console App?

There is an another way how to get path to a running assembly from itself besides I mentioned here. Use this simple snippet:

string[] cmd = Environment.GetCommandLineArgs();
string path_to_assembly = cmd[0];
/* cmd[1] and above contains command line arguments is any */

Resulting array is at least one element length or longer. First element of this array always contains path to the assembly. As a side effect – you can get command line params beginning from second element.

Unfortunately doesn’t work in .NET Compact Framework.

Technorati Tags: ,