fso 文件操作

stillwaterflow 2005-03-16 11:23:11
我用FSO 把查询到的数据以EXCEL 文件形式保存在服务器上 再自动(中间不需要用户执行任何操作)下载到客户端机器上 再自动删除服务器上该保存的文件,在执行完下载的程序段后 删除文件的程序段不执行了,我该怎么解决这个问题了??
...全文
162 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
stillwaterflow 2005-03-17
  • 打赏
  • 举报
回复
多谢各位了 问题解决了 是response.end 做的怪 该结贴了
TSD 2005-03-16
  • 打赏
  • 举报
回复
可能是楼上所说的情况,也有可能是删除代码那段程序有错,或者是路径有错!
yiran700 2005-03-16
  • 打赏
  • 举报
回复
楼上分析不错
mymyal123 2005-03-16
  • 打赏
  • 举报
回复
对,可能处于打开状态
myvicy 2005-03-16
  • 打赏
  • 举报
回复
你没有关闭该文件,文件的状态可能仍为打开,系统以为正在使用,就无法删除。
hcz0663 2005-03-16
  • 打赏
  • 举报
回复
不是这个问题啊,我那个文件是可以读写的。
mymyal123 2005-03-16
  • 打赏
  • 举报
回复
今天下午我处理了一个问题是删除文件夹时提示没有权限,多方检查后发现是文件属性是只读,你也看看是不是这个问题
Hotlion 2005-03-16
  • 打赏
  • 举报
回复
删除文件的语句不是:fso.DeleteFile(filepath)的吗?没有括号也可以成功执行?
hcz0663 2005-03-16
  • 打赏
  • 举报
回复
我也问个问题,我删除文件时提示没权限,但删除同一文件夹下的另一个文件却可以,这是什么回事啊?
hcz0663 2005-03-16
  • 打赏
  • 举报
回复
Response.end

把这句去掉应该可以吧
scoutlin 2005-03-16
  • 打赏
  • 举报
回复
set objStream=nothing
Response.Flush
Response.end

Response.end
????不是吧...
wfwclyms 2005-03-16
  • 打赏
  • 举报
回复
多谢楼主,以前没作过,学习了~~~~~~~~~~~~~~
stillwaterflow 2005-03-16
  • 打赏
  • 举报
回复
有人做过类似的吗 ??指点以下啊
没作过的也一起来学习学习啊 以后也许会用到的
stillwaterflow 2005-03-16
  • 打赏
  • 举报
回复
这是我的代码

dim ranNum
'strFileName="表2.xls"
strFileName=trim(request.querystring("eName"))&".xls"
strPath = Server.MapPath(".\Excel") & "\" & strFileName
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(strPath, True)

Dim RstRpt,strsql
Set RstRpt = Server.CreateObject("ADODB.Recordset")

strsql=trim(request.querystring("sql"))
response.write strFileName
response.write strsql

'strsql="select Code as 列1,ModuleCode as 列2 from SYS_Limit"
cmd.commandtext=strsql
RstRpt.CursorLocation = 3
set RstRpt=cmd.execute
If RstRpt.EOF Then
MyFile.WriteLine "没有得到可打印的数据。"
Else
Dim strContent
strContent = ""
'写表头
For Each x In RstRpt.Fields
strContent = strContent & x.Name & chr(9)
Next
MyFile.WriteLine strContent
While Not RstRpt.EOF
strContent = ""
For Each x In RstRpt.Fields
If IsNull(x.Value) Or IsEmpty(x.Value) Or x.Value = "" Then
strContent = strContent & " " & chr(9)
Else
strContent = strContent & x.Value & chr(9)
End If
Next
MyFile.WriteLine strContent
RstRpt.MoveNext
Wend
End If
MyFile.Close

'response.redirect Server.MapPath(".\Excel") & "\" & strFileName 在浏览器中打开该Excel表

'文件下在到客户端 2005-3-15
Server.ScriptTimeOut=15000
Response.Buffer=true
dim url,trueurl
trueurl=Server.MapPath(".\Excel") & "\" & strFileName
'response.Write trueurl
set objFso=server.CreateObject("scripting.filesystemobject")
set fn=objFso.GetFile(trueurl)
flsize=fn.size
flname=fn.name
set fn=nothing
set objFso=nothing

set objStream=server.CreateObject("adodb.stream")
objStream.Type=1
objStream.Open
objStream.LoadFromFile trueurl

response.clear() '清掉即可防止下载的文件出现乱码
select case lcase(right(flname,4))
case ".asf"
ContentType="video/x-ms-asf"
case ".avi"
ContentType="video/avi"
case ".doc"
ContentType="application/msword"
case ".zip"
ContentType="application/zip"
case ".xls"
ContentType="application/vnd.ms-excel"
case ".gif"
ContentType="image/gif"
case ".jpg","jpeg"
ContentType="image/jpeg"
case ".wav"
ContentType="audio/wav"
case ".mp3"
ContentType="audio/mpeg3"
case ".mpg", "mpeg"
ContentType="video/mpeg"
case ".rtf"
ContentType="application/rtf"
case ".htm","html"
ContentType="text/html"
case ".txt"
ContentType="text/plain"
Case ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"
Response.Write "受保护文件,不能下载."
Response.End
case else
Response.ContentType="appliation/octet-stream"
end select

Response.AddHeader "Content-Disposition", "attachment; filename="&flname
Response.AddHeader "Content-Length", flsize
response.Expires = -1
Response.CharSet="UTF-8" '文件以什么格式存放
Response.ContentType=ContentType
while not objStream.EOS
Response.BinaryWrite objStream.Read(1024*64)
wend
objStream.Close
set objStream=nothing
Response.Flush
Response.end


'删除文件
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(Server.MapPath(".\Excel") & "\" & strFileName)=true then '判断要删除的文件是否存在
fso.DeleteFile Server.MapPath(".\Excel") & "\" & strFileName,true '删除该文件
end if
set fso=nothing

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧