INI文件的操作(ASP.NET+C#)

INI文件的操作(ASP.NET+C#)

(一)INIFile.cs

using System;

using System.Runtime.InteropServices;

using System.Text;

namespace CreateWebDir

{

/// <summary>

/// 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();

}

}

}

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

(二)使用示例

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]);

}

INI文件的操作(ASP.NET+C#),布布扣,bubuko.com

时间: 2024-08-10 18:03:21

INI文件的操作(ASP.NET+C#)的相关文章

wince中对ini文件的操作

下面是代码 class ZT_INI { /************************************************************************/ /*写操作 * strSection 节 * strKey 键 * strValue 需要写入的值 * strFilePath 配置文件的全路径(wince中只能使用绝对全路径) */ /************************************************************

VC关于INI文件的操作

1.查看INI文件是否存在,不存在则创建INI文件 //查看是否有First.ini文件 CFileFind fd; if(fd.FindFile(".First.int")) { MessageBox("找到文件"); } else { MessageBox("没找到文件,创建文件"); CFile file; file.Open(".\First.int",CFile::modeCreate|CFile::modeWrit

Delphi 对ini文件的操作

界面如图: 代码如下: 1 unit Unit1; 2 3 interface 4 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,IniFiles; //添加库 IniFiles 8 9 type 10 TForm1 = cla

关于C#操作INI文件的总结

原文:关于C#操作INI文件的总结 INI文件其实是一种具有特定结构的文本文件,它的构成分为三部分,结构如下: [Section1]key 1 = value2key 1 = value2--[Section2]key 1 = value1key 2 = value2-- 文件由若干个段落(section)组成,每个段落又分成若干个键(key)和值(value).Windows系统自带的Win32的API函数GetPrivateProfileString()和WritePrivateProfil

C#操作INI文件之Vini.cs的使用

VClassLib-CS项目Github地址:https://github.com/velscode/VClassLib-CS VINI文档地址:https://github.com/velscode/VClassLib-CS/blob/master/VINI/VINI_Docs.md INI文件为程序配置存储的常用格式之一,VINI.cs提供了对INI文件读写操作的支持,可以为您快速搭建需要操作INI文件的应用程序.其操作流程简单,源码基于MIT开源协议,你可以在保留原作者版权申明的条件下自由

python3.52 使用configparser模块读写ini文件

使用configparser模块读写ini文件,如果是python 2.7 使用为 import ConfigParser,python 3.2 以后的版本中 ,应当使用import configparser.Python的configparser Module中定义了3个类对INI文件进行操作.分别是RawConfigParser.ConfigParser.SafeConfigParser.模块所解析的ini配置文件是由多个section构成,每个section名用中括号'[]'包含,每个se

delphi 颜色,字体保存到INI文件

颜色转换成整型保存{也可以用ColorToString  / stringTOColor}字体用下面的函数转换成字符串,然后保存 unit xFonts; interface uses Classes, Graphics, SysUtils; procedure StringToFont(sFont: string; Font: TFont; bIncludeColor: Boolean = True);function FontToString(Font: TFont; bIncludeCol

对*.ini文件的增删改查

文件的格式有很多种 *.ini 一般是带一个齿轮的配置文件,这个文件的操作有专门的类库进行处理不行自己硬编码      ini4j.jar 这个jar包专门封装了处理*.ini文件的方法. 1 public interface IParaManager { 2 public int getKey(String section, String key, CInt value); 3 public int getkey(String section, String key, CString valu

Delphi INI 文件读写

delphi中,配置文件的相关操作. (1) INI文件的结构: ;这是关于INI文件的注释部分 [节点] 关键字=值 ... INI文件允许有多个节点,每个节点又允许有多个关键字, “=”后面是该关键字的值(类型有三种:字符串.整型数值和布尔值.其中字符串存贮在INI文件中时没有引号,布尔真值用1表示,布尔假值用0表示).注释以分号“;”开头. (2) INI文件的操作 1. 在Interface的Uses节增加IniFiles: 2. 在Var变量定义部分增加一行:inifile:Tinif