Read Config.ini file contents

Source: Internet
Author: User
Config.ini file contents: [Database]
ServerName =localhost
Database = Shenxun
UID = sa
PWD = using System; Using System.Text; Using System.Runtime.InteropServices;   namespace TEst2 {    ///<summary>     ///readconfig Summary description.     ///</summary>      public class Readconfig       {         public static string FileName = "Config.ini";   & nbsp;      public Readconfig ()          {              //              //TODO: Add constructor logic here               //        }              [DllImport ("kernel32.dll")]           Private static&nBsp;extern int getprivateprofilestring (String section,                String key,string def,stringbuilder retval,int size, String filepath);          Public Static string readinivalue (string section , string key,string Thispath)            {                  stringbuilder temp =  New stringbuilder (255);               int i =  GetPrivateProfileString (Section,key, "", Temp,255, thispath + "//" + filename);                 return temp. ToString ();         }          Public void ReadFile (ref string Servername,ref string Database,ref string Uid,ref string pwd,string thispath)   &nbsp ;      {              try               {                              servername=readinivalue ("Database", "ServerName", Thispath);                    DataBase = Readinivalue ("Database", "Database", Thispath);                    UID  = readinivalue ("Database", "UID", Thispath);                    PWD = Readinivalue ("Database", "pwd", Thispath);              }                catch (Exception err)                {                   throw new Exception (err. message);              }                finally                {             }          }            public bool Checkfile ()          {               if (! System.io.fIle. Exists (filename ))                            {                    return false;              }                Else                     return true;                        }       }}  

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.