C# 在visualc中编辑Ini文件#
我试图用它来编辑一个ini,但我似乎无法获得代码来将ini文件的部分添加到RichTextbox中C# 在visualc中编辑Ini文件#,c#,ini,C#,Ini,我试图用它来编辑一个ini,但我似乎无法获得代码来将ini文件的部分添加到RichTextbox中 if (myIni.GetSection(String.Format("[{0}]", comboBox1.SelectedItem.ToString().ToUpper())) != null); { mySection = new IniFile.IniSection(myIni, String.Format("{0}", comboBo
if (myIni.GetSection(String.Format("[{0}]", comboBox1.SelectedItem.ToString().ToUpper())) != null);
{
mySection = new IniFile.IniSection(myIni, String.Format("{0}", comboBox1.SelectedItem.ToString().ToUpper()));
foreach (IniFile.IniSection.IniKey key in mySection.Keys)
{
richTextBox1.AppendText(String.Format("{0}={1}{2}", key.Name, key.Value, Environment.NewLine));
}
}
我不知道我的代码有什么问题。您可以从windows使用旧的现有ini调用:
[System.Runtime.InteropServices.DllImport("kernel32")]
static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
[System.Runtime.InteropServices.DllImport("kernel32")]
static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
你调试过了吗?
mySection
是否有任何问题?mySection.key
是否包含数据?@RonBeyer如何检查?使用调试器?这是c#编程基础…@RonBeyer的意思是使用控制台、Writeline或IDE(visual studio)的调试功能来检查mySection是否包含正确的数据似乎mySection
的值是{IniFile.IniSection}
和mySection.Keys
的值是{System.Collections.Hashtable.ValueCollection}
。
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString("section", "key", "default", temp, 255, inifilename);
String value = temp.ToString();
WritePrivateProfileString("section", "key", value, inifilename);