Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ASP Delete File from server

Enthusiast ,
May 19, 2007 May 19, 2007
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
TOPICS
Server side applications
364
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 20, 2007 May 20, 2007
After some rest and a closer examination, i realized the error was in the mappath line, it wasnt including the folder that held the files. strPhysicalPath = Server.MapPath(filepath) was wrong so, I added the folder name: strPhysicalPath = Server.MapPath("EMPLOYEE_FILES/" & filepath) then the file is deleted. so complete code is:

<%
Dim filepath, strPhysicalPath
filepath = Session("file_del")
strPhysicalPath = Server.MapPath("EMPLOYEE_FILES/" & filepath)
set filedel = CreateObject("Scripting.Fi...
Translate
Enthusiast ,
May 19, 2007 May 19, 2007
("C:\Inetpub\wwwroot\CallCenter\EMPLOYEE_FILES\"& filepath)
This is the path physical path, i copied the wrong one in the first example
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 20, 2007 May 20, 2007
LATEST
After some rest and a closer examination, i realized the error was in the mappath line, it wasnt including the folder that held the files. strPhysicalPath = Server.MapPath(filepath) was wrong so, I added the folder name: strPhysicalPath = Server.MapPath("EMPLOYEE_FILES/" & filepath) then the file is deleted. so complete code is:

<%
Dim filepath, strPhysicalPath
filepath = Session("file_del")
strPhysicalPath = Server.MapPath("EMPLOYEE_FILES/" & filepath)
set filedel = CreateObject("Scripting.FileSystemObject")
filedel.DeleteFile (strPhysicalPath), True
set filedel = nothing
%>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines