您的位置:首页 > 移动开发

c# how to make app use a specified configure file

2016-09-24 02:08 363 查看
      //Main method

public static void Main(string[] args)
{
if(args != null && args.Length > 0)
{
string clientConfigFile = args[0];

if(!File.Exists(Environment.CurrentDirectory  + "\\" + clientConfigFile))
{
throw new Exception("client config file: " + clientConfigFile + " does not exist!");
}

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = clientConfigFile;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
Utils.Section = section;
}
else
{
throw new Exception("No config file specified!");
}
}

</pre><p></p><p></p><p>       //Utils.cs</p><p>    <pre name="code" class="csharp">  public class Utils
{
public static AppSettingsSection Section = null;

public static String ListURL
{
get
{
return Section.Settings[SourceName + "ListURL"].Value;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: