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

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

问题描述

我在同一个文件夹中有两个 exe 文件,我可以从 exe1 中的一个按钮运行 exe2.今天,我通过远程(终端服务)会话观察客户,exe2 无法运行找不到文件"错误,但我们检查时 exe1 位于同一目录中.所以我应该使用 AppDomain.CurrentDomain.BaseDirectory 还是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 是一个可以并且将会在应用程序运行过程中改变的值.例如,使用默认参数,WinForms 中的 OpenFileDialog 会将此值更改为从中选择文件的目录.

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天全站免登陆