Example

[Data base]-------->Section Value.

Path=""--->value you can write.

Also u can read data from same way.

Code

First import some dll of the system.

  1. [DllImport("kernel32")]
  2. private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
  3. [DllImport("kernel32")]
  4. private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
  5. /// <summary>
  6. /// this constructor we have to give path of ini file
  7. /// </summary>
  8. /// <param name="INIPath">string</param>
  9. public IniFile(string INIPath)
  10. {
  11. path = INIPath;
  12. }
  13. /// this constructor will take default spm.ini file
  14. /// </summary>
  15. public IniFile()
  16. {
  17. path = Application.StartupPath + @ "\Info.ini";
  18. }
  19. /// it use to write value in given section and key
  20. /// </summary>
  21. /// <param name="Section">string</param>
  22. /// <param name="Key">string</param>
  23. /// <param name="Value">string</param>
  24. public void IniWriteValue(string Section, string Key, string Value)
  25. {
  26. WritePrivateProfileString(Section, Key, Value, this.path);
  27. }
  28. /// <summary>
  29. /// read value from given section and key
  30. /// </summary>
  31. /// <param name="Section">string</param>
  32. /// <param name="Key">string</param>
  33. /// <returns>string</returns>
  34. public string IniReadValue(string Section, string Key)
  35. {
  36. StringBuilder temp = new StringBuilder(255);
  37. int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
  38. return temp.ToString();
  39. }
To write the value in the Ini or text file with Header and value:

write the value in the Ini or text file

To Read the Data from the Text Or .ini File:

Read the Data from the Text