ASP 读写文件FSO,adodb.stream
例如静态化页面的时候
总结:用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的更多相关文章
- asp adodb.stream读取文件和写文件
读取文件操作: '------------------------------------------------- '函数名称:ReadTextFile '作用:利用AdoDb.Stream对象来读 ...
- 解决:ADODB.Stream 错误 '800a0bbc' 写入文件失败
重装更改目录为e盘后,上传文件出现问题.解决方法: 调用adodb.stream的savetofile方法时发生错误, ADODB.Stream 错误 800a0bbc 写入文件失败.(msxml3. ...
- asp上传图片提示 ADODB.Stream 错误 '800a0bbc'的解决方法
asp上传图片提示 ADODB.Stream 错误 '800a0bbc' 有这个提示有很多问题导致.权限是常见一种.这个不多说,还有一个有点怪的就是 windows2008显示系统时间的格式竟然是:2 ...
- ASP.NET -- WebForm -- Cookie的使用 应用程序权限设计 权限设计文章汇总 asp.net后台管理系统-登陆模块-是否自动登陆 C# 读写文件摘要
ASP.NET -- WebForm -- Cookie的使用 ASP.NET -- WebForm -- Cookie的使用 Cookie是存在浏览器内存或磁盘上. 1. Test3.aspx文件 ...
- ADODB.Stream
读写文本文件时出现了乱码,找到了ADODB.Stream,可以指定字符集读取文本 Function ReadUTF() Filename = "F:\vba\2018 - new\2018- ...
- c# 高效读写文件
一.同步读写文件(在并发情况下不会发生文件被占用异常) static void Main(string[] args) { Parallel.For(0, 10000, e => { strin ...
- C#常用IO流与读写文件
.文件系统 ()文件系统类的介绍 文件操作类大都在System.IO命名空间里.FileSystemInfo类是任何文件系统类的基类:FileInfo与File表示文件系统中的文件:Directory ...
- IE下使用ADODB.Stream实现断点续传
最近研究了一下IE自带的一些Activex控件,可以比较简单的实现断点续传功能 不过这种方式不推荐,因为安全性较低,而且需要修改客户端注册表,调低ie安全配置 还有就是我比较懒,只打算写个思路和几个关 ...
- 你好,C++(5)如何输出数据到屏幕、从屏幕输入数据与读写文件?
2.2 基本输入/输出流 听过HelloWorld.exe的自我介绍之后,大家已经知道了一个C++程序的任务就是描述数据和处理数据.这两大任务的对象都是数据,可现在的问题是,数据不可能无中生有地产生 ...
随机推荐
- wkhtmltopdf中文参数
wkhtmltopdf [OPTIONS]... [More input files] 常规选项 --allow <path> 允许加载从指定的文件夹中的文件或文件(可重复) --book ...
- [转载]Cool, Tomcat is able to handle more than 13,000 concurrent connections
Last time I have promised you to take a look at more real life scenario regarding threads. In the la ...
- 提示"Zend Optimizer not installed"卸载安装也不行,什么原因如何解决?
如题:Zend Optimizer not installed可能原因及解决方法 Optimizer, Zend 在配置php服务器的时候,所有的东西都安装好了,就是浏览一个要求zend的程序的时候, ...
- node-sass 解决 no such file or directory
在使用node-sass编译的时候出现以下情况 Error: ENOENT: no such file or directory, scandir 'D:\xxxx\node_modules\.npm ...
- js拼接字符串,字符串转数组
想要把字符串按一定的规则拼起来如 1,2,3 var a = []; a.push(1); a.push(2); a.push(3); a.join(','); =>> 1,2,3 想要把 ...
- JavaScript大位数相加减
function arrayAdd(number, addNumber) { var numberArr = number.toString().split(''); var addNumberArr ...
- .net网站转到出错页是如何实现的
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm"><error s ...
- 初始docker
什么是docker? 很多人都是使用docker但是对docker的理解其实并没有这么透彻,只知道怎么用但是不知道为什么用 什么时候去用. 一.环境配置的难题 软件开发最大的麻烦事之一,就是环境配置. ...
- Elasticsearch安装记录
一 安装部分 1.新建用户 elasticsearch不能使用root身份执行 adduser esuser passwd esuser 2.赋予权限 切换到root chown -R esuser ...
- swift版的CircleView
swift版的CircleView 效果图 源码 // // CircleView.swift // CircleView // // Created by YouXianMing on 15/10/ ...