例如静态化页面的时候

总结:用server.CreateObject("adodb.stream") 来读写比较好,可避免乱码和读取到多余的字符。。。。。不推荐 "scripting.FileSystemObject"

例子:页面接受传入ID参数,在数据库里查找ID的记录 写入内容到HTML文件,先创建一个HTML模板文件如“temp_article.html”的文件,读入好久替换里面的内容标签“[-content-]”

[an error occurred while processing the directive]

<%

dim s,ss,id

id= ""& request.QueryString("id")

if id="" then

response.Write("id para is empty")

response.end

else

WriteFile id

end if

'-----------------------------------------------

Function readFile2(fileName)

dim fso,fileobj,fileContent

Set fso = Server.CreateObject("scripting.FileSystemObject") '创建FSO对象

Set fileObj = fso.opentextfile(fileName,1,true) '创建文件读取对象,用于字符文件

filecontent = fileObj.readall '用文件读取对象读出文件内容

readFile2=filecontent

Set fileObj = nothing

Set fso = nothing

end function

'-------------------------------------------------

'函数名称:ReadTextFile

'作用:利用AdoDb.Stream对象来读取UTF-8格式的文本文件

'----------------------------------------------------

Function ReadFromTextFile (FileUrl)

dim str

set stm=server.CreateObject("adodb.stream")

stm.Type=2 '以本模式读取

stm.mode=3

stm.charset="utf-8"

stm.open

stm.loadfromfile FileUrl

str=stm.readtext

stm.Close

set stm=nothing

ReadFromTextFile=str

End Function

'-------------------------------------------------

'函数名称:WriteToTextFile

'作用:利用AdoDb.Stream对象来写入UTF-8格式的文本文件

'----------------------------------------------------

Sub WriteToTextFile (FileUrl,byval Str,CharSet)

set stm=server.CreateObject("adodb.stream")

stm.Type=2 '以本模式读取

stm.mode=3

stm.charset=CharSet

stm.open

stm.WriteText str

stm.SaveToFile FileUrl,2

stm.flush

stm.Close

set stm=nothing

End Sub

Function ReadFile(fileName )

dim fso,fileobj,filecontent

Set fso = Server.CreateObject("scripting.FileSystemObject") '创建FSO对象

Set fileObj = fso.opentextfile(fileName,1,true) '创建文件读取对象,用于字符文件

filecontent = fileObj.readall '用文件读取对象读出文件内容

ReadFile=filecontent

Set fileObj = nothing

Set fso = nothing

end Function

Function WriteFile(id)

dim fso,fileobj,fileName,content,Sqlpp,tbname

dim str

tbname="yao"

Sqlpp ="select ID,Title,content from "&tbname&"_Article Where ID="& ID

Set Rspp=server.CreateObject("adodb.recordset")

rspp.open sqlpp,conn,1,1

if rspp.recordcount<=0 then

Response.write "no record find "

response.end

rspp.close

set rspp=nothing

end if

Do while not Rspp.Eof

'Response.Write( Rspp("content") & "-
" & VbCrLf)

content=Rspp("content")

Rspp.Movenext

Loop

rspp.close

set rspp=nothing

fileName= server.mappath(".") &"\temp_article.html"
'str= ReadFile(fileName)
'str =readFile2(fileName)
str =ReadFromTextFile(fileName) str= Replace(str,"[-body-]",content)
filename=server.mappath("../html/" ) & id & ".html"
call WriteToTextFile(fileName,str,"utf-8")
response.Write(fileName & "------OK") exit function
'response.Write("fid = "&fid) '调试使用,输出请求参数
'response.Write("content = "&content) ’调试使用,输出表单提交数据
Set fso = Server.CreateObject("scripting.FileSystemObject") '创建FSO对象
Set fileObj = fso.opentextfile(filename,2,true) '使用FSO创建文件写入对象
fileObj.Write ( "000000" & str )'向文件写入数据,覆盖形式写入
fileObj.close '推送内容写入并关闭写入通道
response.Write(fileName & "------OK")
Set fileObj = nothing
Set fso = nothing

end Function

%>

ASP 读写文件FSO,adodb.stream的更多相关文章

  1. asp adodb.stream读取文件和写文件

    读取文件操作: '------------------------------------------------- '函数名称:ReadTextFile '作用:利用AdoDb.Stream对象来读 ...

  2. 解决:ADODB.Stream 错误 '800a0bbc' 写入文件失败

    重装更改目录为e盘后,上传文件出现问题.解决方法: 调用adodb.stream的savetofile方法时发生错误, ADODB.Stream 错误 800a0bbc 写入文件失败.(msxml3. ...

  3. asp上传图片提示 ADODB.Stream 错误 '800a0bbc'的解决方法

    asp上传图片提示 ADODB.Stream 错误 '800a0bbc' 有这个提示有很多问题导致.权限是常见一种.这个不多说,还有一个有点怪的就是 windows2008显示系统时间的格式竟然是:2 ...

  4. ASP.NET -- WebForm -- Cookie的使用 应用程序权限设计 权限设计文章汇总 asp.net后台管理系统-登陆模块-是否自动登陆 C# 读写文件摘要

    ASP.NET -- WebForm -- Cookie的使用 ASP.NET -- WebForm --  Cookie的使用 Cookie是存在浏览器内存或磁盘上. 1. Test3.aspx文件 ...

  5. ADODB.Stream

    读写文本文件时出现了乱码,找到了ADODB.Stream,可以指定字符集读取文本 Function ReadUTF() Filename = "F:\vba\2018 - new\2018- ...

  6. c# 高效读写文件

    一.同步读写文件(在并发情况下不会发生文件被占用异常) static void Main(string[] args) { Parallel.For(0, 10000, e => { strin ...

  7. C#常用IO流与读写文件

    .文件系统 ()文件系统类的介绍 文件操作类大都在System.IO命名空间里.FileSystemInfo类是任何文件系统类的基类:FileInfo与File表示文件系统中的文件:Directory ...

  8. IE下使用ADODB.Stream实现断点续传

    最近研究了一下IE自带的一些Activex控件,可以比较简单的实现断点续传功能 不过这种方式不推荐,因为安全性较低,而且需要修改客户端注册表,调低ie安全配置 还有就是我比较懒,只打算写个思路和几个关 ...

  9. 你好,C++(5)如何输出数据到屏幕、从屏幕输入数据与读写文件?

    2.2  基本输入/输出流 听过HelloWorld.exe的自我介绍之后,大家已经知道了一个C++程序的任务就是描述数据和处理数据.这两大任务的对象都是数据,可现在的问题是,数据不可能无中生有地产生 ...

随机推荐

  1. SQL Server 索引知识-应用,维护

    创建聚集索引 a索引键最好唯一(如果不唯一会隐形建立uniquier列(4字节)确保唯一,也就是这列都会复制到所有非聚集索引中) b聚集索引列所占空间应尽量小(否则也会使非聚集索引的空间变大) c聚集 ...

  2. javascript event visualize

    很多时候拿到一个spa,特别是基于jquery的比较复杂的spa时,如果你好奇他是如何工作的,往往没有头绪. 由于spa基本上都是基于事件触发的,一个可行的办法是通过查看事件处理代码能够对spa有一个 ...

  3. 《SQL Server 2008从入门到精通》--20180629

    约束 主关键字约束(Primary Key Constraint) 用来指定表中的一列或几列组合的值在表中具有唯一性.建立主键的目的是让外键来引用. Primary Key的创建方式 在创建表时创建P ...

  4. MySQL存储引擎之Spider内核深度解析

      作者介绍 朱阅岸,中国人民大学博士,现供职于腾讯云数据库团队.研究方向主要为数据库系统理论与实现.新硬件平台下的数据库系统以及TP+AP型混合系统. Spider是为MySQL/MariaDB开发 ...

  5. [翻译] BAFluidView

    BAFluidView https://github.com/antiguab/BAFluidView This view and it's layer create a 2D fluid anima ...

  6. [UI] 精美UI界面欣赏[3]

    精美UI界面欣赏[3]

  7. October 04th 2017 Week 40th Wednesday

    We teach people how to remember, we never teach them how to grow. 我们教会人们如何记忆,却从来不教他们如何成长. Without pr ...

  8. HBase TableExistsException: hbase:namespace

    这个报错一般存在于独立安装Zookeeper集群中. 报这个错的操作时这样的, 先停掉了了Hbase formatZK后重启Hbase 启动hbase shell 后HMaster挂掉,看log里就有 ...

  9. [转]HBase高可用性的新阶段

    From:http://m.csdn.net/article_pt.html?arcid=2823943 Apache HBase是一个面向线上服务的数据库,其原生支持Hadoop的特性,使其成为那些 ...

  10. 4698. [SDOI2008]Sandy的卡片【后缀数组】

    Description Sandy和Sue的热衷于收集干脆面中的卡片.然而,Sue收集卡片是因为卡片上漂亮的人物形象,而Sandy则是为了积 攒卡片兑换超炫的人物模型.每一张卡片都由一些数字进行标记, ...