C # Read ini

Source: Internet
Author: User
Using System;
Using System. IO;
Using System. Runtime. InteropServices;
Using System. Text;

Namespace WindowsApplication6
{
/// <Summary>
/// Summary of iniClass.
/// </Summary>
// TODO: add the constructor logic here
Public class INIClass
{
Public string inipath;
[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 );
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "INIPath"> file path </param>
Public INIClass (string INIPath)
{
Inipath = INIPath;
}
/// <Summary>
/// Write the INI File
/// </Summary>

/// <Param name = "Section"> Project name (for example, [TypeName]) </param>
/// <Param name = "Key"> Key </param>
/// <Param name = "Value"> Value </param>

Public void IniWriteValue (string Section, string Key, string Value)
{


WritePrivateProfileString (Section, Key, Value, this. inipath );
}
/// <Summary>
/// Read the INI File
/// </Summary>

/// <Param name = "Section"> Project name (for example, [TypeName]) </param>
/// <Param name = "Key"> Key </param>

Public string IniReadValue (string Section, string Key)
{

StringBuilder temp = new StringBuilder (500 );

Int I =
GetPrivateProfileString (Section, Key, "", temp, 500, this. inipath );
Return temp. ToString ();
}
/// <Summary>
/// Verify whether the file exists
/// </Summary>
/// <Returns> Boolean value </returns>
Public bool ExistINIFile ()
{
Return File. Exists (inipath );
}
}

//
}

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.