I hope someone can explain why Directory.GetCurrentDirectory () returns different results depending on how to pass command-line arguments to the application (done using args and dragging the folder through the application. EXE)
To jump straight into it, consider this piece of code:
public class Program { static void Main(string[] args) { Console.WriteLine("The current directory is {0}", Directory.GetCurrentDirectory()); if(args != null && args.Any()) Console.WriteLine("Command line arguments are {0}", String.Join(", ", args)); Console.ReadLine(); } }
If you create and run it using the command line as shown below, the result will be what you expected. It will display the current directory in which the application is located.
C:\Projects\ArgumentTest\ApplicationA\bin\Debug\ApplicationA.exe C:\mydirectory The current directory is C:\Projects\ArgumentTest\ApplicationA\bin\Debug\ Command line arguments are C:\mydirectory
If you create and run this program by dragging files or folders through the application, you get different results. Instead of returning the expected result, instead of Directory.GetCurrentDirectory () it returns the path to the first file that you drag and drop through the application.
Currently, I have work for this problem, I really want to understand why this is happening.
Additional Information:
- .NET 4.5
- Windows 2012R2 (virtual machine)
- Full administrator rights on the machine.
Hope someone can give some insight.
source share