C # process INI File class inimanager

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. runtime. interopservices;
Using system. text;

Namespace meidushav1.business
{
 
Public class inimanager
{

/* prototype
* bool writeprivateprofilestring (
lpctstr lpappname, // It is a field name in the INI file.
lptstr lpkeyname, // It is a key name under lpappname. Generally, it is a variable name.
lpctstr lpstring, // It is the key value, that is, the value of the variable, but it must be of the lpctstr or cstring type.
lpctstr lpfilename // file path
*);

*/
[Dllimport ("Kernel32")]
Private Static extern long writeprivateprofilestring (string section, string key, string Val, string filepath );

/* DWORD getprivateprofilestring (
Lptstr lpappname,
Lptstr lpkeyname,
Lptstr lpdefault, // If the INI file does not contain the field name or key name specified by the first two parameters, this value is assigned to the variable.
Lptstr lpreturnedstring,
DWORD nsize,
Lptstr lpfilename
*);*/

[Dllimport ("Kernel32")]
Private Static extern int getprivateprofilestring (string section, string key, string def, stringbuilder retval, int size, string filepath );

Private string filepath;

Public inimanager (string filepath)
{< br> This. filepath = filepath;
}

Public void write (string section, string key, string value)
{< br> try
{< br> writeprivateprofilestring (section, key, value, filepath);
}< br> catch (exception ex)
{< br> throw new exception (ex. tostring ();
}< BR >}

Public String read (string section, string key)
{
Try
{
Stringbuilder temp = new stringbuilder (255 );
Int I = getprivateprofilestring (section, key, String. Empty, temp, 255, filepath );
Return temp. tostring ();
}
Catch (exception ex)
{

Throw new exception (ex. tostring ());
}
}
}

 


}

Code
1

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.