Read in C #, write INI file

Source: Internet
Author: User

       [DllImport ("Kernel32.dll")] private static extern bool WritePrivateProfileString (string section, string key,        String val, string filePath); [DllImport ("Kernel32.dll")] private static extern int getprivateprofilestring (string section, string key, String de        F, StringBuilder retVal, int size, string filePath);        private string spath_ = ""; <summary>//absolute path///</summary> public string Spath {get {retur n Spath_;        } set {spath_ = value;} }///<summary>///write to INI file///</summary>//<param name= "section" > File Domain & lt;/param>//<param name= "key" >key value </param>///<param Name= "value" >value value </param&        Gt            <returns></returns> public bool Writetoini (string section, string key, String value) {            BOOL result = FALSE; if (System.IO.File.Exists (spath){result = WritePrivateProfileString (section, key, value, spath);        } return result; }///<summary>///read from INI file///</summary>//<param name= "section" > File Domain & lt;/param>//<param name= "key" >key value </param>///<param Name= "defaultvalue" > Default </pa ram>//<returns></returns> public string Readfromini (string section, String key, String def            Aultvalue = "") {string result = DefaultValue;                if (System.IO.File.Exists (spath)) {StringBuilder stemp = new StringBuilder (1024);                int i = getprivateprofilestring (section, key, DefaultValue, Stemp, 1024x768, spath);            result = Stemp.tostring ();        } return result; }

Strongly NOTE:

INI file must be in ANSI, Unicode format, or an exception will occur, for reasons that are not found yet. Please help the hero to explain.

Read in C #, 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.