File Move Overwrite??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • B-Dog

    File Move Overwrite??

    Is there a way to make vb.net to overwrite the file when moving? Here is
    what I'm trying to do:

    If System.IO.File. Exists(dest) Then

    'handle overwrite here

    If MessageBox.Show ("Do you want to overwrite", "Overwrite File?",
    MessageBoxButto ns.YesNo, MessageBoxIcon. Question) = DialogResult.Ye s Then

    System.IO.File. Move(lstfilenam e, dest) 'I want to force overwrite file here

    Else


  • Brian

    #2
    Re: File Move Overwrite??

    File.Copy has a boolean parameter that allows you to specify if you want to
    overwrite an existing file or not. You could then File.Delete the old file.

    "B-Dog" <bdog4@hotmail. com> wrote in message
    news:uv2xEhleEH A.1652@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Is there a way to make vb.net to overwrite the file when moving? Here is
    > what I'm trying to do:
    >
    > If System.IO.File. Exists(dest) Then
    >
    > 'handle overwrite here
    >
    > If MessageBox.Show ("Do you want to overwrite", "Overwrite File?",
    > MessageBoxButto ns.YesNo, MessageBoxIcon. Question) = DialogResult.Ye s Then
    >
    > System.IO.File. Move(lstfilenam e, dest) 'I want to force overwrite file[/color]
    here[color=blue]
    >
    > Else
    >
    >[/color]


    Comment

    • Imran Koradia

      #3
      Re: File Move Overwrite??

      you could delete the existing file once you've determined that the file
      exists and the user has decided to overwrite the file. then move the file
      from the source to the destination.
      [color=blue]
      > If System.IO.File. Exists(dest) Then
      >
      > 'handle overwrite here
      >
      > If MessageBox.Show ("Do you want to overwrite", "Overwrite File?",
      > MessageBoxButto ns.YesNo, MessageBoxIcon. Question) = DialogResult.Ye s Then[/color]

      ----> System.IO.File. Delete(dest)
      [color=blue]
      > System.IO.File. Move(lstfilenam e, dest) 'I want to force overwrite file[/color]
      here[color=blue]
      >
      > Else[/color]

      hope this helps..
      Imran.

      "B-Dog" <bdog4@hotmail. com> wrote in message
      news:uv2xEhleEH A.1652@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Is there a way to make vb.net to overwrite the file when moving? Here is
      > what I'm trying to do:
      >
      > If System.IO.File. Exists(dest) Then
      >
      > 'handle overwrite here
      >
      > If MessageBox.Show ("Do you want to overwrite", "Overwrite File?",
      > MessageBoxButto ns.YesNo, MessageBoxIcon. Question) = DialogResult.Ye s Then
      >
      > System.IO.File. Move(lstfilenam e, dest) 'I want to force overwrite file[/color]
      here[color=blue]
      >
      > Else
      >
      >[/color]


      Comment

      Working...