Read and Write INI File Code

Source: Internet
Author: User
Two functions for reading and writing INI files

Writeprivateprofilestring (); // write
Writeprivateprofilestring (string section, string key, string Val, string filepath );
Parameter description
Section summary name
Key keyword
Val Value
Filepath

Getprivateprofilestring (); // read
Getprivateprofilestring (string section, string key, string def, stringbuilder retval, int size, string filepath );
Parameter description
Section summary name
Key keyword
Default Value returned when the def specified entry is not found
Character Buffer specified by retval
Size retval maximum number of characters in the buffer
Filepath
You need to introduce
Using system. runtime. interopservices;

Code Example Code
[Dllimport ( " Kernel32 " )]
Private   Static   Extern   Long Writeprivateprofilestring ( String Section, String Key, String Val, String Filepath );
Private   Void Button3_click ( Object Sender, eventargs E)
{
Writeprivateprofilestring ( " Feng " , " ID " , " 007 " , @" D: \ FSL. ini " );
Writeprivateprofilestring ( " Feng " , " ISS " , " 008 " , @" D: \ FSL. ini " );
Writeprivateprofilestring ( " F " , " ID " , " 008 " , @" D: \ FSL. ini " );
}
[Dllimport ( " Kernel32 " )]
Private   Static   Extern   Int Getprivateprofilestring ( String Section, String Key, String Def, stringbuilder retval, Int Size, String Filepath );

Private   Void Button4_click ( Object Sender, eventargs E)
{
Stringbuilder temp =   New Stringbuilder ();
Getprivateprofilestring ( " Feng " , " ID " , " Dddddxxxd " , Temp, 255 , @" D: \ FSL. ini " );
Label1.text = Temp. tostring ();
}

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.