asp.net ini file read-write class _ Practical skills

Source: Internet
Author: User
Tags int size
Copy Code code as follows:

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

Namespace Common
{
<summary>
INI file read-write class.
</summary>
public class INIFile
{
public string path;

Public INIFile (String INIPath)
{
Path = 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);


[DllImport ("kernel32")]
private static extern int getprivateprofilestring (string section, string key, String Defval, byte[] retVal, int size, stri ng FilePath);


<summary>
Write INI file
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<param name= "Value" ></param>
public void Iniwritevalue (string section,string key,string Value)
{
WritePrivateProfileString (Section,key,value,this.path);
}

<summary>
Reading INI file
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<returns></returns>
public string Inireadvalue (String section,string Key)
{
StringBuilder temp = new StringBuilder (255);
int i = getprivateprofilestring (Section,key, "", temp, 255, this.path);
Return temp. ToString ();
}
Public byte[] Inireadvalues (string section, string key)
{
byte[] temp = new byte[255];
int i = getprivateprofilestring (section, Key, "", temp, 255, this.path);
return temp;

}


<summary>
Delete all the paragraphs under the INI file
</summary>
public void Clearallsection ()
{
Iniwritevalue (Null,null,null);
}
<summary>
Delete all keys under personal paragraph in INI file
</summary>
<param name= "section" ></param>
public void Clearsection (string section)
{
Iniwritevalue (Section,null,null);
}
}
}

Not too much content, do tricks is still used.
Related Article

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.