Answered
ASP Delete File from server
I have made a file sharing app, and the description and file
name are stored in my access db, when i delete the recordset for
the file i also want to delete the actual file. i am able to delete
the file with the full path entered and the file name as a
variable,
with this code:
<%
Dim filepath
filepath = Session("file_del")
set filedel = CreateObject("Scripting.FileSystemObject")
filedel.DeleteFile("C:\localhost\CallCenter\EMPLOYEE_FILES\"& filepath), True
set filedel = nothing
%>
I put the name of the file in the file_del session variable on the page that deletes the recordset.
But i would like to make it work on my hosted site without having to change the path to my sites, so i have made this code:
<%
Dim filepath
filepath = Session("file_del")
strPhysicalPath = Server.MapPath(filepath)
set filedel = CreateObject("Scripting.FileSystemObject")
filedel.DeleteFile strPhysicalPath , True 'Line that causes ERROR
set filedel = nothing
%>
But the error comes File Not found.
if i just display the strPhysicalPath variable on the page without the delete action it displays the proper path.
how can i get the strPhysicalPath to be read, i have tried all of the ways i can think of
filedel.DeleteFile strPhysicalPath , True
filedel.DeleteFile & strPhysicalPath & , True
filedel.DeleteFile (strPhysicalPath) , True
filedel.DeleteFile ("" & strPhysicalPath & "") , True
filedel.DeleteFile ( & strPhysicalPath) , True
But none of them work ?
Any help would be great
with this code:
<%
Dim filepath
filepath = Session("file_del")
set filedel = CreateObject("Scripting.FileSystemObject")
filedel.DeleteFile("C:\localhost\CallCenter\EMPLOYEE_FILES\"& filepath), True
set filedel = nothing
%>
I put the name of the file in the file_del session variable on the page that deletes the recordset.
But i would like to make it work on my hosted site without having to change the path to my sites, so i have made this code:
<%
Dim filepath
filepath = Session("file_del")
strPhysicalPath = Server.MapPath(filepath)
set filedel = CreateObject("Scripting.FileSystemObject")
filedel.DeleteFile strPhysicalPath , True 'Line that causes ERROR
set filedel = nothing
%>
But the error comes File Not found.
if i just display the strPhysicalPath variable on the page without the delete action it displays the proper path.
how can i get the strPhysicalPath to be read, i have tried all of the ways i can think of
filedel.DeleteFile strPhysicalPath , True
filedel.DeleteFile & strPhysicalPath & , True
filedel.DeleteFile (strPhysicalPath) , True
filedel.DeleteFile ("" & strPhysicalPath & "") , True
filedel.DeleteFile ( & strPhysicalPath) , True
But none of them work ?
Any help would be great
