我应该使用AppDomain.CurrentDomain.BaseDirectory还是System.Environment.CurrentDirectory? [英] Should I use AppDomain.CurrentDomain.BaseDirectory or System.Environment.CurrentDirectory?
问题描述
谢谢
如果要在与应用程序相同的目录中查找文件, AppDomain.CurrentDomain.BaseDirectory
是正确的选择。
Environment.CurrentDirectory
是一个可以并将在运行应用程序的过程中进行更改的值。例如,使用默认参数,WinForms中的OpenFileDialog将将此值更改为从中选择文件的目录。
I have two exe files in the same folder, I can run exe2 from a button in exe1. Today I was observing a customer over a remote (terminal services) session and exe2 failed to run 'File not found' error, yet exe1 was in the same directory when we checked. So should I be using AppDomain.CurrentDomain.BaseDirectory or System.Environment.CurrentDirectory?
Thanks
If you want to find files in the same directory as your application, AppDomain.CurrentDomain.BaseDirectory
is the correct choice.
Environment.CurrentDirectory
is a value that can and will change throught the course of running your application. For instance, using default parameters, the OpenFileDialog in WinForms will change this value to the directory where the file was selected from.
这篇关于我应该使用AppDomain.CurrentDomain.BaseDirectory还是System.Environment.CurrentDirectory?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!