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

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

问题描述

我有两个exe文件在同一个文件夹,我可以运行exe2从一个按钮exe1。今天我通过远程(终端服务)会话观察客户,exe2无法运行文件未找到错误,但是当我们检查时exe1在同一个目录中。所以我应该使用 AppDomain.CurrentDomain.BaseDirectory 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屋!

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