Delete File

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am moving a file to a folder as follows:

Dim file As New System.IO.FileInfo(Server.MapPath(path))
file.MoveTo(Server.MapPath(newpath))

This is working but if there is already a file with the same name in
the destination folder I get an error.

I would like to replace the file if one exists.

How can I do this?

Thanks,
Miguel
 
I think you'd have to use file.CopyTo(newpath, true) to overwrite an
existing file, and then use file.Delete() to delete the original.

Jonas
 
Back
Top