获取当前应用程序的配置文件中的文件路径 [英] Get the file path of current application's config file
本文介绍了获取当前应用程序的配置文件中的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我之所以问这个问题是,我想创建一个辅助类的远程实例,并希望通过适当的app.exe.config(或web.config文件),文件路径 RemotingConfiguration.Configure
方法,根据调用者。
The reason I asked this question is that I wanted to create a helper class for Remoting instantiation, and wanted to pass the appropriate app.exe.config (or web.config) file path to the RemotingConfiguration.Configure
method, depending on the caller.
有没有办法,我能得到的双赢和Web应用在配置文件的名称,而不检查,如果应用程序是基于Web或的WinForms?
Is there a way I could get the name of the config file for both Win and Web apps without checking if the application is Web or WinForms?
推荐答案
我用
string folder = System.Web.HttpContext.Current != null ?
System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_data") :
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
没有问题,但也许有一些极少数的情况下,我不知道......
without problems, but maybe there is some corner cases I don't know about...
这篇关于获取当前应用程序的配置文件中的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文