C # store values in ini format (for example, the user name and logon number on the login interface)

Source: Internet
Author: User

This is the first blog post. In the future, I will summarize and share all the things I have found through my own materials during development, so that I can take a look at them later ~~~

PS: Of course, I feel like I am still a small dish ~ For the great gods, the content may be relatively simple ~ A lot of things are also sorted out on the Internet. It would be a great honor for me to help you a little bit.

First, if you have created a login interface, you must enter the "user name" [username] and password to log on. To avoid entering the user name every time you open the system, now we need to implement a file storage function,

The file will be stored in ". ini" format:

Write File:

1 [DllImport("kernel32")]2 private static extern long WritePrivateProfilesString(string section,string key,string val,string filepath);3 private static void WriteToIni(string name,string key,string value)4 {5     WritePrivateProfilesString(name,key,value,Directory.GetCurrentDirectory()+@"\User.ini");6 }
Write

Read data from a file:

1 [DllImport("kernel32")]2 private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder returnval,int size,string iniPath);3 private string GetStringIni(string section,string key)4 {5      StringBuilder strbuider=new StringBuilder(1024);6      string def=null;7        GetPrivateProfileString(section,key,def,strbuilder,1024,Directory.GetCurrentDirectory()+@"\User.ini");8      return strbuilder.ToString();9 }
Read

 

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.