Get and set .ini file values c #

Suppose you have an .ini file with the following information:


The following functions will allow you to obtain and modify your configuration file in a simple way:

using System.Runtime.InteropServices;
using System.Text;

namespace qualityinfosolutions
    public class Util
        public static extern int GetPrivateProfileString(string section,
                 string key, string def, StringBuilder retVal,
            int size, string filePath);

        public static extern long WritePrivateProfileString(string section,
            string key, string val, string filePath);

Mode of use

//Read Values
StringBuilder count = new StringBuilder();
string stringValue = "";
string file = "C:\\config.ini";

if (File.Exists(file))
     stringValue = count.ToString();
else {
     MsgError("Unable to find file " + file);

//Modify values

Util.WritePrivateProfileString("Data", "Count", 150, file); 

I hope this is useful


También te podría gustar...

Deja una respuesta

Tu dirección de correo electrónico no será publicada.