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....
yaron9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.