Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1538
  • Last Modified:

delete file using fso

I want to delete a file using fso object.
the file was uploaded with SAfileUp object.
I'm writing this command:

Set fso = CreateObject("Scripting.FileSystemObject")
delfile = Request("fileRef")
fso.DeleteFile(delfile)

delfile contains the whole path to the file
from some reason I get an error :"invalid procedure call or argument"
on this line : fso.DeleteFile(delfile)
I've tried to write like this : fso.DeleteFile("&delfile&")

but the error was "File not found"

what am I doing wrong??
thank you....
0
yaron9
Asked:
yaron9
1 Solution
 
whammyCommented:
You need to map the local path to the file in order for FSO to be able to delete it.

Try this:

delfile = Server.MapPath(Request("fileRef"))

If fso.FileExists(delfile) Then
   fso.DeleteFile(delfile)
Else
   ' Write the file path we're getting:
   Response.Write(delfile & " not found!" & "<br />" & vbCrLf)
End If
0
 
jwalinCommented:
when you pass the value of fileRef .. That time you used Server.URLEncode(fileRef)

example:

<a href="http://server-name/abc.asp?fileRef=<%=Server.URLEncode(fileRef)%>">delete</a>

and then
Set fso = CreateObject("Scripting.FileSystemObject")
delfile = Request("fileRef")
fso.DeleteFile(delfile)

Jwalin
0
 
yaron9Author Commented:
try this:
Sub DeleteFile(fileName)
  Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  filepath = server.mappath(fileName)
  fso.DeleteFile  filePath
end Sub
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
markhoyCommented:
to use fso you need a full file path ie d:\user\htdocs\file.asp

see ww.aspfaqs.com > File System Object

You also need the correct permissions under IIS for IUSR_machinename to delete the file.
0
 
oceanASPCommented:
Here is what I found from http://www.sloppycode.net/fso/?m=56

DeleteFile
FSO.DeleteFile filename[,forceReadOnlyDelete]
 
Description
Deletes filename, which can contain wildcards (only the filename, not folder names).An error occurs if the filename is not found. [forceReadOnlyDelete] will force the file to be deleted if it's readonly.
 
<%
'***************** DeleteFile
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile "C:\afilename.*",true
' This deletes all files called "afilename", regardless of extension, and even if they are readonly files.
Set fso = Nothing
%>
0
 
CleanupPingCommented:
yaron9:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
GaryCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by whammy

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now