2017. 2. 14. 09:19

using System.Runtime.InteropServices;       


        [DllImport("kernel32")]

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

        [DllImport("kernel32")]

        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size,             string filePath);


        private string FilePath = AppDomain.CurrentDomain.BaseDirectory + "init.ini";


// ini 파일에 쓰기

private void WriteIni(string section, string key, string value)

        {

            WritePrivateProfileString(section, key, value, FilePath);

        }


        // ini파일에서 읽기

        private string Readini(string section, string key)

        {

            StringBuilder temp = new StringBuilder(255);

            int ret = GetPrivateProfileString(section, key, "", temp, 255, FilePath);            

            return temp.ToString();

        }




         textBox.Text = Readini("Section 값", "Key 값"); //이렇게 읽고

         WriteIni("Section 값", "Key 값", textBox.Text); //이렇게 쓴다.

'언어 > C#' 카테고리의 다른 글

Tray Application  (0) 2017.07.13
C# 한글 인코딩  (0) 2017.06.18
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] 걸린 시간 체크  (0) 2016.06.08
[C#] ListView item 삭제  (0) 2016.03.22
Posted by 까망후니