C # INI File Operations

Source: Internet
Author: User

 

Using System;
Using System. IO;
Using System. runtime. interopservices;
Using System. text;

namespace operateini
{< br> Public class INIFILE
{< br> private string inifilename;

[dllimport ( " Kernel32 " )]
private static extern int getprivateprofileint ( string lpappname, string lpkeyname,
int ndefault, string lpfilename );

[Dllimport ( " Kernel32 " )]
Private   Static   Extern   Int Getprivateprofilestring ( String Lpappname, String Lpkeyname,
String Lpdefault, stringbuilder lpreturnedstring, Int Nsize, String Lpfilename );

[dllimport ( " Kernel32 " )]
private static extern bool writeprivateprofilestring ( string lpappname,
string lpkeyname, string lpstring, string lpfilename );

Public INIFILE ( String Filename)
{
Inifilename = Filename;
}

Public   Int Readini ( String Section, String Key, Int Default)
{
Return Getprivateprofileint (section, key, default, inifilename );
}

Public   String Readini ( String Section, String Key, String Default)
{
Stringbuilder temp =   New Stringbuilder ( 1024 );
Int REC = Getprivateprofilestring (section, key, default, temp, 1024 , Inifilename );
Return Temp. tostring ();
}

Public VoidWriteini (StringSection,StringKey,IntIntvalue)
{
Writeprivateprofilestring (section, key, intvalue. tostring (), inifilename );
}

Public void writeini ( string section, string key, string strvalue)
{< br> writeprivateprofilestring (section, key, strvalue, inifilename );
}< BR >}< br>

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.