asp.net operation INI File example _ Practical Tips

Source: Internet
Author: User
Tags int size

Copy Code 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>
Summary description of INIFile
</summary>
public class INIFile
{

public string path;

Public INIFile (String INIPath)
{
Path = INIPath;
}

[DllImport ("kernel32")]
private static extern long WritePrivateProfileString (string section,
String key, String val, string filePath);

[DllImport ("kernel32")]

private static extern int getprivateprofilestring (string section,
String key, String Def, StringBuilder retVal, int size, string filePath);

public void Iniwritevalue (string section, String Key, String Value)
{
WritePrivateProfileString (section, Key, Value, This.path);
}


public string Inireadvalue (string section, String Key)
{
StringBuilder temp = new StringBuilder (255);

int i = getprivateprofilestring (section, Key, "", temp, 255, this.path);

Return temp. ToString ();

}
}
}

Copy Code code 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, EventArgs e)
{
Createwebdir.inifile ab = new Createwebdir.inifile (@ "F:\test");

String iniFile = @ "F:\test\test.ini";
if (! File.exists (IniFile))
{
using (FileStream fs = File.create (IniFile))
{
Fs. Close ();
}
}

string[] args = new STRING[10];

Createwebdir.inifile Myini = new Createwebdir.inifile (INIFile);

for (int i = 0; i < args. Length; i++)
{
Args[i] = convert.tostring (i + i * i * i);
Myini.iniwritevalue ("WebDir", "Arg" + i.tostring (), args[i]);
}
}
}

Copy Code code 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, EventArgs e)
{
Createwebdir.inifile ab = new Createwebdir.inifile (@ "F:\test\test.ini");

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.