I have a question and don't quite understand. I've read the article Reading/writing an INI file And I have applied it to my project. but I cannot read the data in my .int file.
This is the code I use
var MyIni = new IniFile("config.ini");
string id = MyIni.Read("id").ToString();
string url = MyIni.Read("url").ToString();
string token = MyIni.Read("token").ToString();
This is the class I use "IniFile.cs"
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
// Change this to match your program's normal namespace
namespace MyProg
{
class IniFile // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);
public IniFile(string IniPath = null)
{
Path = new FileInfo(IniPath ?? EXE + ".ini").FullName;
}
public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}
public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}
public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}
public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}
public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
}
this is the information in my "IniFile.ini"
id=5eb3c344a9e9486ebb3450cd
url=https:https://demo.cti.com/
token=FO_KO7XTNe6tamWL9PlFG7L5gbGObl4z
I put my file "IniFile.ini" in the "debug" folder of my project. Hope everyone help me, what was wrong with me? thanks so much!