C # Read and write INI file

Source: Internet
Author: User

Write data in Ini file
[DllImport ("kernel32")]
private static extern long WritePrivateProfileString (string section, string key, String val, string filePath);

Reading the data in the Ini file
[DllImport ("kernel32")]
private static extern int getprivateprofilestring (string section, String key, String Def, StringBuilder retVal, int size, String filePath);

//<summary>
//Create INI file and write data
//</SUMMARY>
//<param name= "section" > Root node </ Param>
//<param name= "key" > key </param>
//<param name= "val" > Value </param>
//< param name= "FilePath" > Path </param>
public static void Writeinidata (string section, string key, String val, str ing FilePath)
{
if (! File.exists (FilePath))
{
var fs = File.create (FilePath);
FS. Dispose ();
FS. Close ();
}
WritePrivateProfileString (section, Key, Val, FilePath);
}

<summary>
Read Ini file
</summary>
<param name= "section" > Root node </param>
<param name= "key" > Keys </param>
<param name= "def" > Default data </param>
<param name= "RetVal" > Return Data </param>
<param name= "Size" > Size </param>
<param name= "FilePath" > Paths </param>
public static void Readinidata (string section, String key, String Def, StringBuilder retVal, int size, string filePath)
{
GetPrivateProfileString (section, Key, Def, RetVal, size, filePath);
}

C # Read and write INI file

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.