在项目里新建个类,把下面的代码粘贴进去,相信你操作.INI文件就轻松多了。
注:下面有用法实例。
'------class代码
Imports System.Collections 'ArryList命名空间引用
Imports System.IO 'TextWriter
TextReader
Imports System.Diagnostics '使您能够与系统进程、事件日志和性能计数器进行交互
'Imports System.Security.Cryptography'
命名空间提供加密服务,Md5命名空间引,类Encryption中已经导入
'Imports System.Linq '提供支持使用语言集成查询 (LINQ) 进行查询的类和接口
'Imports System.Runtime.InteropServices
'[DllImport("kernel32")]与非托管代码交互
Namespace OperateIniSorted
'''
'''Ini
配置文件类
'''
'''
Public
NotInheritable Class IniFileSorted
Private m_strIniFilePath As String '配置文件路径
Private m_bIsLoad As Boolean '是否已经初始化
Private m_arrSections As ArrayList '属性分节单元
Private m_arrProperties As ArrayList '属性值数组
Private Const msgTile As String = "提示"
Private Const msgNoPro As String = "该属性不存在"
Private Const msgNoInit As String = "尚未初始化"
Private Const msgNoOpenInifile As String = "没有打开配置文件"
Private Const msgIncorrectProperty As String = "属性名称不能为空"
Private Const msgIncorrectSection As String = "指定的属性名称不能为空"
Private Const msgIncorrectValue As String = "指定的属性值不能为空"
Private Const msgExistedProperty As String = "属性已经存在"
'''
''' ini文件加载后,获取全部属性对象
'''
Public ReadOnly Property PropertiesLst() As ArrayList
Get
Return IIf(m_bIsLoad, m_arrProperties, Nothing)
End Get
End Property
'''
''' INI文件加载后,获取全部单元对象
'''
'''
'''
'''
Public ReadOnly Property SectionLst() As ArrayList
Get
Return IIf(m_bIsLoad, m_arrSections, Nothing)
End Get
End Property
'''
''' 配置INI文件路径
'''
'''
'''
'''
Public Property IniFilePath() As String
Get
Return m_strIniFilePath
End Get
Set(ByVal value As String)
m_strIniFilePath = value
End Set
End Property
Public Sub New() '构造
m_strIniFilePath = ""
m_bIsLoad = False
m_arrSections = New ArrayList()
m_arrProperties = New ArrayList()
End Sub
Public Sub New(ByVal a_strIniFilePath As String) '重构
m_strIniFilePath = a_strIniFilePath
m_bIsLoad = False
m_arrSections = New ArrayList()
m_arrProperties = New ArrayList()
End Sub
#Region "属性单元Section类"
Public Class Section
Private m_strSectionNmae As String '单元名称
Public Property SectionName() As String '存取单元名称
Get
Return m_strSectionNmae
End Get
Set(ByVal value As String)
m_strSectionNmae = value
End Set