海海日记-冯海滨博客

您现在的位置是:首页 > C# > 正文

C#

web.config / App.config 更名,改名,改位置解决方案

happyfhb2012-10-31C#3860

 

web.config / App.config 更名,改名,改位置解决方案
Web.config/ App.config / *.exe.config都默认在应用程序集的相同目录下,.net configuration非常依赖这个配置文件,如果我们想把它移到其他目录,比如”C:"Documents and Settings"myusername"Application Data"”下,而又不影响.net 2.0 configuration等等所有依赖这个配置文件的等你哦关系,怎么做呢?可

以设置AppDomain的属性,将此代码加入到 Program.cs 里面  Application.Run(new Form1()); 之前即可。切记要加入到之前。

string newConfigFilePath =     
@"C:\Documents and Settings\myusername\Application Data\MyApp\MyApp.config";     
           
if(System.AppDomain.CurrentDomain.SetupInformation.ConfigurationFile != newConfigFilePath)     
                    AppDomain.CurrentDomain.SetData ( "APP_CONFIG_FILE", newConfigFilePath );

 

平淡中储蓄成长

发表评论

评论列表

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~