开发者

Get the file path of current application's config file

开发者 https://www.devze.com 2023-01-02 12:45 出处:网络
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 RemotingConfig

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.

Is there a way I could get the name of the config file for both Win and Web apps without chec开发者_开发百科king if the application is Web or WinForms?


You can use the ConfigurationFile property on the SetupInformation for AppDomain.CurrentDomain.

This will get either the web.config or and app.config (yourprogram.exe.config) location.

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile


I've used

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...


To find the location of executing application

System.Reflection.Assembly.GetExecutingAssembly().Location;

Don't know about web case.

0

精彩评论

暂无评论...
验证码 换一张
取 消