示例#1
0
 /// <summary>
 /// 写入
 /// </summary>
 /// <param name="sectionName">section 节点名称</param>
 /// <param name="key">key 值</param>
 /// <param name="value">value 值</param>
 public void Write(string sectionName, string key, string value)
 {
     try
     {
         //根据INI文件名设置要写入INI文件的节点名称
         //此处的节点名称完全可以根据实际需要进行配置
         strFileName = Path.GetFileNameWithoutExtension(strFilePath);
         IniHelper.WritePrivateProfileString(sectionName, key, value, strFilePath);
     }
     catch
     {
         throw new Exception("配置文件不存在或权限不足导致无法写入");
     }
 }
示例#2
0
 /// <summary>
 /// 读取
 /// </summary>
 /// <param name="sectionName">section 节点名称</param>
 /// <param name="key">key 值</param>
 /// <returns>value 值</returns>
 public string Read(string sectionName, string key)
 {
     if (File.Exists(strFilePath)) //读取时先要判读INI文件是否存在
     {
         strFileName = Path.GetFileNameWithoutExtension(strFilePath);
         //return ContentValue(strFileName, key);
         StringBuilder outValue = new StringBuilder(1024);
         IniHelper.GetPrivateProfileString(sectionName, key, "", outValue, 1024, strFilePath);
         return(outValue.ToString());
     }
     else
     {
         throw new Exception("配置文件不存在");
     }
 }