File Move Overwrite??

  • Thread starter Thread starter B-Dog
  • Start date Start date
B

B-Dog

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?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then

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

Else
 
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.
 
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.
If System.IO.File.Exists(dest) Then

'handle overwrite here

If MessageBox.Show("Do you want to overwrite", "Overwrite File?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then

----> System.IO.File.Delete(dest)
System.IO.File.Move(lstfilename, dest) 'I want to force overwrite file here

Else

hope this helps..
Imran.
 

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

Back
Top