INI file operation (asp.net+c#)

Source: Internet
Author: User
Tags ini int size
asp.net (i) INIFile.cs

Using System;
Using System.Runtime.InteropServices;
Using System.Text;


Namespace Createwebdir
{
<summary>
Summary description of the 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 ();

}

}
}

=======================================================

(ii) Use of examples

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

INIFile Myini = new INIFile (INIFile);

For (I=0;i<args. length;i++)
{
Myini.iniwritevalue ("WebDir", "Arg" +i.tostring (), args[i]);
}




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.