winform 项目获取app.config 中appSettings节点数据

时间:2023-03-09 02:54:01
winform 项目获取app.config 中appSettings节点数据
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="StartUpgrade.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<!-- checkin 文件夹和文件名 -->
<add key="checkin-filefolder" value="D:\NotePad++\"/>
<add key="checkin-filefolder-name" value="npp.6.1.3.Installer.exe"/> <!-- 出钞 文件夹和文件名 -->
<add key="outmoney-filefolder" value="D:\NotePad++\"/>
<add key="outmoney-filefolder-name" value="npp.6.1.3.Installer.exe"/> <!-- 入钞 文件夹和文件名 -->
<add key="inmoney-filefolder" value="D:\NotePad++\"/>
<add key="inmoney-filefolder-name" value="npp.6.1.3.Installer.exe"/> <!-- 字节数组 -->
<add key="bytearrary" value="10240"/>
<add key="upload-path" value="E:\Projects\Hotels\StartUpgrade\StartUpgrade\File\"/>
<add key="upload-url" value="http://192.168.1.200:8077/UpgradeFiles/"/>
</appSettings>
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
<applicationSettings>
<StartUpgrade.Properties.Settings>
<setting name="StartUpgrade_IStartUpgrade_UpgradeFile" serializeAs="String">
<value>http://192.168.1.155:8013/DataService/WebService/Interface/UpgradeFile.asmx</value>
</setting>
</StartUpgrade.Properties.Settings>
</applicationSettings> </configuration>

然后在winform中cs文件里这样调用:

        /// <summary>
/// 获取配置文件里appsettings的数据
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public string GetAppsettingStr(string str)
{
AppSettingsReader appReader = new AppSettingsReader();
return appReader.GetValue(str, typeof(string)).ToString();
}