当前位置: 首页 > 图文教程 > 网络编程 > ASP > 写入文本文件的过程函数(ASP)

ASP
ASP编程中15个非常有用的例子 (二)
ASP与JSP的比较(一)
ASP与JSP的比较(二)
ASP中五种连接数据库的方法
从ASP调用SQL中的图像
用排序串字段实现树状结构(例程:连接字串)
用排序串字段实现树状结构(例程:删除贴子)
用排序串字段实现树状结构(例程:回复表单)
用排序串字段实现树状结构(例程:显示贴子内容)
用排序串字段实现树状结构(例程:显示树)
用排序串字段实现树状结构(存储过程)
用排序串字段实现树状结构(库结构)
用排序串字段实现树状结构(原理)
remote script文档(转载自微软)(一)
remote script文档(转载自微软)(二)
remote script文档(转载自微软)(三)
remote script文档(转载自微软)(四)
remote script文档(转载自微软)(五)
remote script文档(转载自微软)(六)
remote script文档(转载自微软)(七)

写入文本文件的过程函数(ASP)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 138 ::
收藏到网摘: n/a


今天写程序的时候要反复用到写入文本文件,于是就写了一个过程函数,希望对大家有用.
代码:
Sub Write2File(strFile, strContent, blnAppend)
' 写入文件
' strFile 文件名(路径) , strContent 写入的内容, blnAppend 是否追加
On Error Resume Next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If blnAppend Then
Set objWriteText = objFSO.OpenTextFile(strFile,8,True)
Else
Set objWriteText = objFSO.OpenTextFile(strFile,2,True)
End If
objWriteText.WriteLine (strContent)
Set objWriteText = Nothing
Set objFSO = Nothing
' 容错处理
Select Case Err
Case 424 Response.Write "路径未找到或者该目录没有写入权限."
' Case Else Response.Write Err.Description
Case Else Response.Write Err
End Select
End Sub
调用方法:
Write2File "c:\dd.ini", "dd", True
或者
Call Write2File ("c:\dd.ini", "dd", True)
说明:
1.自动建立文件;
2.不能自动建立目录