eNerGiZer0101
IS-IT--Management
Dear reader,
I am faced with a problem when deleting a file from a file from the hard drive of my web server. I will post the forms that I have programmed:
The first form's is name toDelete_files.asp
<html>
<body>
<h2 align=center>Delete Files</h2>
<%
Dim Conn, Rs, sql
set Conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
Conn.open = "DRIVER={MYSQL Connector/ODBC v5};SERVER=localhost;DATABASE=inse6120project;UID=root;PWD=root; OPTION=3; PORT=1433;"
sql= "SELECT * FROM files;"
Rs.Open sql, Conn
Response.Write "<FORM name='Delete' method='post' action='deleteFiles.asp'>"
Response.Write "<table align=center border=1 cellspacing=0>"
Response.Write "<tr>"&"<th></th>"&"<th align='center'>"&"File Name"&"</th>"&"<th align='center'>"&"Description"&"</th>"&"</tr>"
Do While not Rs.EOF
Response.Write ("<tr>")
Response.Write ("<td>"&"<input type='radio' name='ID' value="&Rs("file_number")&">"&"</td>")
Response.Write ("<td>"&Rs("file_name")&"</td>")
Response.Write ("<td>"&Rs("description")&"</td>")
Response.Write ("</tr>")
Rs.MoveNext
Loop
Response.Write("<tr>"&"<td colspan='3' align='center'>"&"<input type ='submit' name='submit' value='Delete' onClick='return validate();'>"&"</td>"&"</tr>")
Response.Write "</table>"
Response.Write "</form>"
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
</body>
</html>
This next form is where I found the error:
The form's name is deleteFiles.asp
<%
Dim ID
Dim fs
Dim FName
ID = Request.Form("ID")
if ID="" then
Response.Write "You did not select a name to delete!"
Else
Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={MYSQL Connector/ODBC v5};SERVER=localhost;DATABASE=inse6120project;UID=root;PWD=root; OPTION=3; PORT=1433;"
sql= "SELECT file_name, fpath FROM files WHERE file_number='" & ID & "'"
Rs.Open sql, Conn
FName = Rs.Fields.Item("fpath") & Rs.Fields.Item("file_name")
Response.Write (FName)
Rs.Close
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.FileExists(FName) then
Response.write "hello"
fs.DeleteFile(FName)
end if
set fs=nothing
sql= "Delete FROM files WHERE file_number='" & ID & "'"
Rs.Open sql, Conn
Conn.Close
Set Conn = Nothing
Response.Write "Successfully Deleted"
End If
%>
I have put a response.write "hello" before the line that is causing the error. The error when submitting the delete button from the toDelete_files.asp page is :
Object expected
Line 4
URL toDelete_files.asp
I don't think there is an error with the toDelete_files.asp page but it is from the deleteFiles.asp page.
For clarity, the line that is giving the error is :
fs.DeleteFile(FName)
When I comment the line the form deletes the entry in the DB but I need for it to delete the file...
Can someone please help me with this?
Thank you in advance,
Liam
I am faced with a problem when deleting a file from a file from the hard drive of my web server. I will post the forms that I have programmed:
The first form's is name toDelete_files.asp
<html>
<body>
<h2 align=center>Delete Files</h2>
<%
Dim Conn, Rs, sql
set Conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
Conn.open = "DRIVER={MYSQL Connector/ODBC v5};SERVER=localhost;DATABASE=inse6120project;UID=root;PWD=root; OPTION=3; PORT=1433;"
sql= "SELECT * FROM files;"
Rs.Open sql, Conn
Response.Write "<FORM name='Delete' method='post' action='deleteFiles.asp'>"
Response.Write "<table align=center border=1 cellspacing=0>"
Response.Write "<tr>"&"<th></th>"&"<th align='center'>"&"File Name"&"</th>"&"<th align='center'>"&"Description"&"</th>"&"</tr>"
Do While not Rs.EOF
Response.Write ("<tr>")
Response.Write ("<td>"&"<input type='radio' name='ID' value="&Rs("file_number")&">"&"</td>")
Response.Write ("<td>"&Rs("file_name")&"</td>")
Response.Write ("<td>"&Rs("description")&"</td>")
Response.Write ("</tr>")
Rs.MoveNext
Loop
Response.Write("<tr>"&"<td colspan='3' align='center'>"&"<input type ='submit' name='submit' value='Delete' onClick='return validate();'>"&"</td>"&"</tr>")
Response.Write "</table>"
Response.Write "</form>"
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
</body>
</html>
This next form is where I found the error:
The form's name is deleteFiles.asp
<%
Dim ID
Dim fs
Dim FName
ID = Request.Form("ID")
if ID="" then
Response.Write "You did not select a name to delete!"
Else
Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={MYSQL Connector/ODBC v5};SERVER=localhost;DATABASE=inse6120project;UID=root;PWD=root; OPTION=3; PORT=1433;"
sql= "SELECT file_name, fpath FROM files WHERE file_number='" & ID & "'"
Rs.Open sql, Conn
FName = Rs.Fields.Item("fpath") & Rs.Fields.Item("file_name")
Response.Write (FName)
Rs.Close
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.FileExists(FName) then
Response.write "hello"
fs.DeleteFile(FName)
end if
set fs=nothing
sql= "Delete FROM files WHERE file_number='" & ID & "'"
Rs.Open sql, Conn
Conn.Close
Set Conn = Nothing
Response.Write "Successfully Deleted"
End If
%>
I have put a response.write "hello" before the line that is causing the error. The error when submitting the delete button from the toDelete_files.asp page is :
Object expected
Line 4
URL toDelete_files.asp
I don't think there is an error with the toDelete_files.asp page but it is from the deleteFiles.asp page.
For clarity, the line that is giving the error is :
fs.DeleteFile(FName)
When I comment the line the form deletes the entry in the DB but I need for it to delete the file...
Can someone please help me with this?
Thank you in advance,
Liam