获取当前应用程序配置文件的文件路径 [英] Get the file path of current application's config file
本文介绍了获取当前应用程序配置文件的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我问这个问题的原因是我想为 Remoting 实例化创建一个帮助器类,并希望将适当的 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 还是 WinForms 的情况下获取 Win 和 Web 应用程序的配置文件的名称?
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屋!
查看全文