• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Delete a file before uploading files

My ISP has provided me with some code to upload files. Which works the first time. The second time I try to upload files it get the following error..

ABCUpload4.XField.4 error '80040050'

A Windows error - The file exists. - (0x00000050) occurred.

/partnersite/regions/EMEA/upload_success.asp, line 24


I talked to my ISP and they say the permissions are set properly. The only thing I've been able to deduce is that the myupload.dat file doesn't like to be overwritten.  How do I delete the file automatically before uploading my other files? Here is the code of the processing asp.

<%
Set theForm = Server.CreateObject("ABCUpload4.XForm")
theForm("filefield")(1).Save "myupload.dat"
%>


Thanks
0
kevinbenedict
Asked:
kevinbenedict
  • 3
1 Solution
 
dwaldnerCommented:
<%
set fso = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(FILEPATH) then
          Set file = fso.GetFile(FILEPATH)
          if fso.FileExists(BACKUP_FILEPATH) then
            Set file2 = fso.GetFile(BACKUP_FILEPATH)
            file2.Delete True
            Set file2 = nothing
          End if
          file.Move BACKUP_FILEPATH
          set file = nothing
end if
set fso = Nothing
...
%>

This should shed a little bit of light on how to do what you want...this moves your file to a backup location....

This will delete the file

<%
set fso = Server.CreateObject("Scripting.FileSystemObject")
if fso.FileExists(FILEPATH) then
          Set file = fso.GetFile(FILEPATH)
          file.Delete True
          set file = nothing
end if
%>

but basically, what you want is that fso.FileExists(FilePath) method

Dan
0
 
kevinbenedictAuthor Commented:
This is what I tried...

<%
Set theForm = Server.CreateObject("ABCUpload4.XForm")
theForm.overwrite=True
theForm("filefield")(1).Save "myupload.dat"
%>

I got the same error.

I'll go look at your link.
0
 
joeposter649Commented:
Maybe you need to use server.MapPath("/myupload.dat")
0
 
joeposter649Commented:
Or a capital O in Overwrite.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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