我应该使用AppDomain.CurrentDomain.BaseDirectory或System.Environment.CurrentDirectory? [英] Should I use AppDomain.CurrentDomain.BaseDirectory or System.Environment.CurrentDirectory?

查看:456
本文介绍了我应该使用AppDomain.CurrentDomain.BaseDirectory或System.Environment.CurrentDirectory?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个文件夹2 exe文件,我可以从EXE1按钮运行EXE2。今天,我在观察客户通过远程(终端服务)会话和EXE2运行失败,找不到文件的错误,但EXE1是在同一目录下,当我们检查。所以,我应该使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx\">AppDomain.CurrentDomain.BaseDirectory或<一个href=\"http://msdn.microsoft.com/en-us/library/system.environment.currentdirectory.aspx\">System.Environment.CurrentDirectory?

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?

感谢

推荐答案

如果你想找到在同一目录作为您的应用程序文件, AppDomain.CurrentDomain.BaseDirectory 是正确的选择。

If you want to find files in the same directory as your application, AppDomain.CurrentDomain.BaseDirectory is the correct choice.

Environment.CurrentDirectory 是能够而且将会throught运行应用程序的过程中发生变化的值。例如,使用默认参数,在打开文件对话框中的WinForms将这个值更改为从被选择的文件的目录。

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆