private string strSec = ""; //INI文件名 /// <summary> /// 自定义读取INI文件中的内容方法 /// </summary> /// <param name="Section">键</param> /// <param name="key">值</param> /// <returns></returns> private string ContentValue(string Section, string key) { StringBuilder temp = new StringBuilder(1024); SaveRecord.GetPrivateProfileString(Section, key, "", temp, 1024, strFilePath); return(temp.ToString()); }
private void button2_Click(object sender, EventArgs e) { try { //根据INI文件名设置要写入INI文件的节点名称 //此处的节点名称完全可以根据实际需要进行配置 strSec = Path.GetFileNameWithoutExtension(strFilePath); SaveRecord.WritePrivateProfileString(strSec, "Name", "123", strFilePath); SaveRecord.WritePrivateProfileString(strSec, "Sex", "五十字五十字", strFilePath); MessageBox.Show("写入成功"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }