Describes the asp.net operation INI file read and write

Source: Internet
Author: User
Tags ini int size

  This article mainly introduces the asp.net operation INI file reading and writing, read and write operation of the local INI configuration file method, the need for friends can refer to the following

  Code as follows: using System; Using System.Data; Using System.Configuration; Using System.Web; Using System.Web.Security; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Web.UI.WebControls.WebParts; Using System.Web.UI.HtmlControls;   using System.Runtime.InteropServices; Using System.Text;   namespace Createwebdir {   ///<summary>    ///INIFile Summary description    ///</s Ummary>     public class INIFile     {          public string path; &nbsp ;         public INIFile (string INIPath)         {        &NBSP ;   Path = INIPath;        }           [DllImport ("kernel32")]-        Priva Te static extern long WritePrivateProfileString (string section,          string key, String Val, String filePath);         &NBSP [DllImport ("kernel32")]           private static extern int GetPrivateProfileString (string secti On,          string key, String def, StringBuilder retVal, int size, string filePath);           public void Iniwritevalue (string section, String Key, String Value)     &NBSP ;   {            writeprivateprofilestring (section, Key, Value, This.path);   &NBSP ;    }           public string Inireadvalue (string section, String Key)   &N Bsp     {          StringBuilder temp = new StringBuilder (255);     &NBSP ;         int i = getprivateprofilestring (section, Key, "", temp, 255, this.path);               return temp. ToString ();           {   }}   code is as follows: using System; Using SysTem. Data; Using System.Configuration; Using System.Collections; Using System.Web; Using System.Web.Security; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Web.UI.WebControls.WebParts; Using System.Web.UI.HtmlControls;   using System.IO;   public partial class User_Default:System.Web.UI.Page {    protected void Page_Load (object sender, even Targs e)     {        Createwebdir.inifile ab = new Createwebdir.inifile (@ "f:test");           String iniFile = @ "F:testtest.ini";         if (! File.exists (IniFile))                     using (FileStream fs = File. Create (IniFile))             {                FS. Close ();                     {          string[] args = new STRING[10]; &nbSp         Createwebdir.inifile Myini = new Createwebdir.inifile (INIFile);           for (int i = 0; i < args. Length; i++)         {            Args[i] = convert.tostring (i + i * i * i); &n Bsp           Myini.iniwritevalue ("WebDir", "Arg" + i.tostring (), args[i]);        }    /}     code is as follows: using System; Using System.Data; Using System.Configuration; Using System.Collections; Using System.Web; Using System.Web.Security; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Web.UI.WebControls.WebParts; Using System.Web.UI.HtmlControls;   using System.IO;   public partial class User_Default:System.Web.UI.Page {    protected void Page_Load (object sender, even Targs e)     {        Createwebdir.inifile ab = new Createwebdir.inifile (@ "F:testtest.ini") ;   &NBSp       Response.Write (AB. Inireadvalue ("WebDir", "Arg5"));    }}
Related Article

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.