Relative Paths (or CurrentDirectory) wrong if called with arguments?

Hello Community,

i got a very strange behaviour here.

For example, i am working in the directory: C:\Test. When I call my assembly, abc.exe, the Environment.CurrentDirectory (or all relative paths) are C:\Test.
Now, my file takes files as arguments (like an Editor). So when i drag and drop a file (test.txt) on my exacutable, the Environment.CurrentDirectory variable (and relative Paths) change to my default User directory which is something like C:\Files and Settings\Username\... and so on

Why does this happen
How can i get the Path, where the File is located

I am working on .Net 2.0 beta 2

Thanks in advance!!!
Your help is very appreciated.

Thomas


Answer this question

Relative Paths (or CurrentDirectory) wrong if called with arguments?

  • Michael Miller

    Maybe this will work for you:
    this.GetType().Assembly.Location

  • Joenormal

     You need to view the command line arguments and not the environment path when a user drops a file on the executable. As to why CWD defaults to the user is unknown to me...most likely its a default location for shared document access.

    Examplestatic void Main(string[] args)
    {

        Console.WriteLine("CWD: " + Environment.CurrentDirectory);

        foreach (string arg in args)
            Console.WriteLine(arg);

        Console.ReadLine();

    }


    Output
    CWD: C:\Documents and Settings\OmegaMan
    C:\FilterLog.log



  • Relative Paths (or CurrentDirectory) wrong if called with arguments?