Hej!
Jeg kan ikke slette en specifik fil!!!
Jeg indsætter mine to sider for måske bedre at kunne illustrerer
hvad det egentlige problem er:
rediger.asp
*****************
<HTML>
<HEAD>
</HEAD>
<BODY>
<%
' Databaseforbindelse - husk at angive sti til din database
Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DSN = DSN & "DBQ=" & Server.MapPath("test.mdb")
Conn.Open DSN
' SQL vælger post
strSQL = "select * from person order by username"
Conn.Execute(strSQL)
Set rs = Conn.Execute(strSQL)
Do
%>
<form action="slet.asp" method="post">
<input type="text" value="<% response.write rs("username")%>"
name="username">
<input type="text" value="<% response.write rs("FILENAME")%>"
name="FILENAME">
<input type="hidden" name="ID" value="<%= rs("ID") %>">
<input type="submit" value="SLET">
</form>
<%
rs.MoveNext
Loop While Not rs.EOF
' Luk databaseforbindelse
Conn.Close
Set Conn = Nothing
%>
</BODY>
</HTML>
****************************'
slet.asp
*************
<head>
</head>
<BODY BGCOLOR="white">
<%
' Variables
' *********
Dim oConn
Dim fso
Dim folder
Dim files
Dim strSQL
Dim oRs
' Object creation
' ***************
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.getFolder(Server.MapPath("Upload"))
Set files = folder.files
' Connect to the DB
' *****************
Set oConn = Server.CreateObject("ADODB.Connection")
curDir = Server.MapPath("test.mdb")
oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver
(*.mdb)};DriverId=25;FIL=MS Access;"
' Open a recordset
' ****************
strSQL = "select * from person"
Set oRs = Server.CreateObject("ADODB.recordset")
Set oRs.ActiveConnection = oConn
oRs.Source = strSQL
oRs.LockType = 3
oRs.Open
' Select each file
' ****************
For each file In files
' Only if the file exist
' **********************
if not Request.Form("FILENAME") <> file.name Then
fso.deletefile(Server.MapPath("Upload\(" &
Request.Form("FILENAME") & ")"))
' delete the current file from a DB field
' **********************************
oRs.delete
ors("username") = request.Form("username")
oRs("FILENAME") = request.Form("FILENAME")
oRs.Update
end if
next
' Destruction
' ***********
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
%>
</BODY>
</HTML>
****************
Når jeg kører scriptet får jeg følgende fejl:
Microsoft VBScript runtime error '800a0035'
File not found
/slet.asp, line 45
(YDERST hjælpsom :) )
Jeg tror problemet bl.a. er at jeg i min db har to forskellige
filer, hvilket forstyrer scriptet.
Min plan er at kunne slette hver enkelt fil og muligvis
tilhørende tekst, hver for sig.
Venlig hilsen Lasse Vestergaard
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials