不知道你的具体用途 也可以考虑服务器端fso<% function ReadFile(filename) on error resume next err.clear 'ASP的一种校错方法 Const ForReading = 2 Const Create = false Dim FSO DIM TS DIM filepath DIM thefile Dim content'---------------操作地址Set FSO=server.createobject("scripting.filesystemobject") filepath=server.MapPath("temp") ./记录本存放的文件夹if err.number<>0 then response.Write "目录不存在" response.End end if'filename="test.txt" ---------test.txt为你从数据库里读出的文件名 thefile=filepath&"/"&filename Set TS = FSO.OpenTextFile(thefile,1)do until Ts.AtEndOfStream Response.Write (""&TS.ReadLine&"") response.write("<br>") loopSet TS = Nothing Set FSO = Nothing end function %><% dim id dim filename id=6 Set rs=Server.CreateObject("ADODB.Recordset") sql="select * from yuan where id="&id rs.open sql,cn,1,1 filename=rs("fileload") %><% readfile(filename) %>
谢谢你的代码,正在读,很感动,但我是想只用html和js脚本,应该如何是好呢
我也遇到你类似的问题,好想不好弄,建议搞个临时目录吧 如: f = fso.CreateTextFile("c:\\temp\\testfile.txt", ForWriting, true);
有的网页能打开网页文件并取原码这里最好用ajax,用xmlhttp组件
而且谁能告诉我,Scripting.FileSystemObject的打开文件函数,功能描述是说可以用相对路径的,可为什么就不行呢?我换了两台机器试也都不行
function ReadFile(filename)
on error resume next
err.clear
'ASP的一种校错方法
Const ForReading = 2
Const Create = false
Dim FSO
DIM TS
DIM filepath
DIM thefile
Dim content'---------------操作地址Set FSO=server.createobject("scripting.filesystemobject")
filepath=server.MapPath("temp") ./记录本存放的文件夹if err.number<>0 then
response.Write "目录不存在"
response.End
end if'filename="test.txt" ---------test.txt为你从数据库里读出的文件名
thefile=filepath&"/"&filename
Set TS = FSO.OpenTextFile(thefile,1)do until Ts.AtEndOfStream
Response.Write (""&TS.ReadLine&"")
response.write("<br>")
loopSet TS = Nothing
Set FSO = Nothing
end function
%><%
dim id
dim filename
id=6
Set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from yuan where id="&id
rs.open sql,cn,1,1
filename=rs("fileload")
%><% readfile(filename) %>
如:
f = fso.CreateTextFile("c:\\temp\\testfile.txt", ForWriting, true);