要求:
能够读取按照 INI文件的Section和Key来读出相应的Value。
比如一个配置文件
mail.ini
---------------------------------
[MailInfo]
user=123
pwd=321
server=smtp.163.com
---------------------------------
主体程序(方法) :
inifile.asp
-----------------------------------------------
<%
set IniFileDictionary = CreateObject("Scripting.Dictionary")
Sub IniFileLoad(ByVal FilSpc)
IniFileDictionary.RemoveAll
FilSpc = lcase(FilSpc)
if left(FilSpc, 1) = "p" then
'Physical path
PhyPth = mid(FilSpc, instr(FilSpc, "=") + 1)
else
'Virtual path
PhyPth = Server.MapPath(mid(FilSpc, instr(FilSpc, "=") + 1))
end if
set FilSys = CreateObject("Scripting.FileSystemObject")
set IniFil = FilSys.OpenTextFile(PhyPth, 1)
do while not IniFil.AtEndOfStream
StrBuf = IniFil.ReadLine
if StrBuf <> "" then
'There is data on this line
if left(StrBuf, 1) <> ";" then
'It's not a comment
if left(StrBuf, 1) = "[" then
'It's a section header
HdrBuf = mid(StrBuf, 2, len(StrBuf) - 2)
else
'It's a value
StrPtr = instr(StrBuf, "=")
AltBuf = lcase(HdrBuf & " |" & left(StrBuf, StrPtr - 1))
do while IniFileDictionary.Exists(AltBuf)
AltBuf = AltBuf & "_"
loop
IniFileDictionary.Add AltBuf, mid(StrBuf, StrPtr + 1)
end if
end if
end if
loop
IniFil.Close
set IniFil = nothing
set FilSys = nothing
End Sub
Function IniFileValue(ByVal ValSpc)
dim ifarray
StrPtr = instr(ValSpc, " |")
ValSpc = lcase(ValSpc)
if StrPtr = 0 then
'They want the whole section
StrBuf = ""
StrPtr = len(ValSpc) + 3
ValSpc = ValSpc + " |"
ifarray = IniFileDictionary.Keys
for i = 0 to IniFileDictionary.Count - 1
if left(ifarray(i), StrPtr) = ValSpc then
'This is from the section
if StrBuf <> "" then
StrBuf = StrBuf & "~"
end if
StrBuf = StrBuf & ifarray(i) & "=" & IniFileDictionary(ifarray(i))
end if
next
else
'They want a specific value
StrBuf = IniFileDictionary(ValSpc)
end if
IniFileValue = StrBuf
End Function
Function Chr(section,key)
char1=IniFileValue(section)
SearchString =char1
SearchChar = key
MyPos=Instr(1,SearchString,SearchChar,1)
'char2=section+key
char1=mid(char1,MyPos+len(key)+1,len(char1)-MyPos+1)
SearchString =char1
SearchChar = "~"
MyPos=Instr(1,SearchString,SearchChar,1)
if MyPos<>0 then
char1=mid(char1,1,MyPos-1)
else
char1=mid(char1,1)
end if
Chr = char1
End Function
%>
如何使用?
-----------------------------------------------
<!--#include file="inifile.asp"-->
<%
'virtual:表示服务器路径 Physical:表示物理路径 mail.ini : 配置文件名称
call IniFileLoad("virtual=mail.ini")
'MailInfo:节点名称 server: 配置文件中的KEY
serverStr = Chr("MailInfo","server")
Response.Write("<br/>serverStr:"&serverStr)
%>
分享到:
相关推荐
vb6生成的DLL结合ASP文件读取INI内容,附源码
asp.net读写ini文件内容
ASP.NET 2.0 读取配置文件[INI]
完整的ASP.NET网上书店系统VB代码,为教学资料.
传统的配置文件ini已有被xml文件逐步代替的趋势,但对于简单的配置,ini文件还是有用武之地的。ini文件其实就是一个文本文件,它有固定的格式,节Section的名字用[]括起来,然后换行说明key的值: [section] key=...
asp.net读写ini文件,里面有个ini.cs类文件,下载后,可以放app_Code里调用声明下,就可以使用了,代码很简单,可以自己看下里面,里面有写了说明文件
ASP.NET+VB.NET 上传文件 以一个用户注册页面为例
ASP读写INI文件的函数,完全封装,加入包含文件即可使用。
vb.net及asp.net代码手册vb.net及asp.net代码手册vb.net及asp.net代码手册
一样跟简单的聊天室代码 运用的是asp(vb)语言编写,很简单很好用
VB代码1000例 1000s of Visual Basic Source Code examples 由于文件较大所以我分 成了很多部分。 VB代码1000例第一部分(可单独使用) http://download.csdn.net/source/2029561 VB代码1000例第二部分(可单独...
HTML板式在线编器源代码 (ASP.net + VB)
聊天室asp(vb)完整源代码,仅供学习参考用
本代码结合vb讲述了如何在asp中上传图片文件,以及如何把文件保存在数据库中
一款asp代码加密工具,vb6编写.注意在运行加密后的asp文件时,需要在服务器端注册aspDecoder.dll控件
用VB生成DLL封装ASP代码_连接数据库,调用站点外部的数据
《ASP.NET专业项目实例开发》 vb源代码 很好的实例啊
[Wrox] ASP.NET 4.5 入门经典 (C# & VB 语言实现) (英文版) [Wrox] Beginning ASP.NET 4.5 in C# and VB (E-Book) ☆ 图书概要:☆ The ultimate programming guide to ASP.NET 4.5, by popular author and ...
利用asp.net+sql server2005 伪邮箱系统 vb代码,可实现邮箱基本功能,关键要正确安装asp.net+sql server2005,同时代码里面的server,uid,password,database等要改成你对应的server名字,uid(用户名),password...