app.config:
1<appSettings>
2 <!--数据库连接字符串-->
3 <add key="ConnectionString" value="Data Source=192.168.1.1;InitialCatalog=DataBase;Persist Security Info=True;User ID=sa;Password=sa" />
4 <!--服务器地址-->
5 <add key="ServerIP" value="192.168.1.2" />
6 <!--考试子系统路径-->
7 <add key="exePath" value="C:\\Program Files\\Exam\\Exam.exe"/>
8 <!--风格设置-->
9 <!--可选风格 vista1.ssk、MP10.ssk、MSN.ssk、OneBlue.ssk、vista1_green.ssk、XPBlue.ssk-->
10 <add key="skinName" value="XPBlue.ssk" />
11 <!--自动更新升级-->
12 <add key="AutoUpdate" value="false" />
13</appSettings>
C#Code:
读取app.config配置
1 private void GetSystemArgs()
2 {
3 string path = AppDomain.CurrentDomain.BaseDirectory + @"\\SC.exe.config";
4 if (!File.Exists(path))
5 return;
6 XmlDocument xmlDoc = new XmlDocument();
7 xmlDoc.Load(path);
8 XmlNode root = xmlDoc.DocumentElement;
9 XmlNodeList xmlNodes = root.SelectNodes("appSettings/add");
10 XmlNode nodeConnectionString = xmlNodes[0];
11 XmlNode nodeServerIP = xmlNodes[1];
12 XmlNode nodeAutoUpdate = xmlNodes[4];
13 string ConnectionString = nodeConnectionString.Attributes["val |