c# how to make app use a specified configure file
2016-09-24 02:08
363 查看
//Main method
public static void Main(string[] args)
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; } } }
相关文章推荐
- How to make Windows Form app truly Full Screen (and to hide Taskbar) in C#? 转
- How to make a USB stick use ISO image file in debian
- Regular Expression in C# - How to make use of Expresso
- 1201833 - How to configure Crystal Reports to use an SAPLogon.ini file
- NDoc: How to Make Good Use of Your XML Comments?
- How to use C# code to get the windows components
- how to make a JAR file
- Install and configure Gnupg &amp; Use Gnupg to encrypt file in PHP
- 在iPhone应用中如何使用随机数(How to Use Random Numbers in Your iPhone App)
- NDoc: How to Make Good Use of Your XML Comments?
- How to use InterfaceInterceptor of Unity with configuration file
- How to use GDI+?simle introduction about configure
- How to use GCC to build DLL by DEF file in MinGW?
- How to use an ActiveX script task to import data into a new Excel file
- How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings
- NDoc: How to Make Good Use of Your XML Comments?
- How to use sendmail to configure SMTP server
- How To Use LoadImage() to Read a BMP File(转载)
- How to use Events in the Context of C#
- how to make a authorware file in an environment without authorware