日期:2014-05-17  浏览次数:20966 次

删除数据库里的路径,并删除图片。转化绝对路径时server.MapPath 出现800a000d错误
VBScript code
<!--#include file="conn.asp"-->

<%
Function DeleteFile(FileName)
FileName=server.MapPath(FileName) '必须转换成绝对路径的
dim Fso
Set Fso = CreateObject("scripting.filesystemobject")
if Fso.FileExists(Filename) then '判断文件是否存在
Fso.DeleteFile filename 
end if
Set Fso = nothing
End Function
%>

<%
Dim action
action = Request.QueryString("action")
Select Case action
     Case "delete"
          delete
End Select

Sub Delete
    dim news_id,rs
    news_id=Trim(Request("news_id"))
    if isnumeric(news_id) then
        connopen
        set rs=server.createobject("adodb.recordset") 
        sql="select * from table_news where news_id=news_id" 
        rs.open sql,conn,1,3 
        DeleteFile(rs("news_img"))
        rs.delete
        rs.update
        rs.close
        set rs=nothing
        Response.Write("新闻删除成功&nbsp;&nbsp;&nbsp;&nbsp;")
        Response.Write("<a href='BMagNews.asp'>返回新闻管理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='BAddNews.asp'>返回新闻发布</a>")
    else
        Response.Write("新闻删除失败&nbsp;&nbsp;&nbsp;&nbsp;")
        Response.Write("<a href='BMagNews.asp'>返回新闻管理</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='BAddNews.asp'>返回新闻发布</a>")
    end if
End Sub
%>


------解决方案--------------------
VBScript code

        sql="select * from table_news where news_id=news_id" 
        rs.open sql,conn,1,3
        if not rs.eof() then
           DeleteFile(rs("news_img"))
           rs.delete
           rs.update
        end if
        rs.close