Delete File

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
 
J

Jonas Bush

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top