1-) C# RMOS - .ini dosyası okuma ini okuma kütüphanesi
// kaynak https://stackoverflow.com/questions/217902/reading-writing-an-ini-file
2-) kullanımı
private void button1_Click(object sender, EventArgs e)
{
var MyIni = new IniFile("ayarlar1.ini");
MyIni.Write("id", "100","server");
MyIni.Write("sifre", "http://www.google.com","server");
string id = MyIni.Read("id", "server").ToString();
Console.WriteLine(id);
}
3-) kütüphane
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
namespace WindowsFormsApplication3
{
public class IniFile
{
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.ToString();
}
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;
}
}
}