C #. Net ini file Operation

Source: Internet
Author: User

 

 Using System;
Using System. Text;
Using System. Runtime. InteropServices;

Namespace Pub. Class
{
/// <Summary>
/// INI File Operation
/// </Summary>
Public class IniFile
{
# Region private member
Private string path;
[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 );
# Endregion

# Region Constructor
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "INIPath"> file name </param>
Public IniFile (string INIPath) {path = INIPath ;}
# Endregion

# Region WriteValue
/// <Summary>
/// Write data to the INI File
/// </Summary>
/// <Param name = "Section"> node </param>
/// <Param name = "Key"> name </param>
/// <Param name = "Value"> Value </param>
Public void WriteValue (string Section, string Key, string Value)
{
WritePrivateProfileString (Section, Key, Value, this. path );
}
# Endregion

# Region ReadValue
/// <Summary>
/// Read data to the INI File
/// </Summary>
/// <Param name = "Section"> node </param>
/// <Param name = "Key"> name </param>
/// <Returns> data </returns>
Public string ReadValue (string Section, string Key)
{
StringBuilder temp = new StringBuilder (255 );
Int I = GetPrivateProfileString (Section, Key, "", temp, 255, this. path );
Return temp. ToString ();
}
# Endregion
}

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.