Delete File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shapper

    Delete File

    Hello,

    I am moving a file to a folder as follows:

    Dim file As New System.IO.FileI nfo(Server.MapP ath(path))
    file.MoveTo(Ser ver.MapPath(new path))

    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
  • Jonas Bush

    #2
    Re: Delete File

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

    Jonas


    "shapper" <mdmoura@gmail. comwrote in message
    news:1bcf8f37-a859-408b-b9c6-7b1aa6352460@o7 7g2000hsf.googl egroups.com...
    Hello,
    >
    I am moving a file to a folder as follows:
    >
    Dim file As New System.IO.FileI nfo(Server.MapP ath(path))
    file.MoveTo(Ser ver.MapPath(new path))
    >
    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

    Comment

    Working...