By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,813 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

File Move Overwrite??

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <bd***@hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP10.phx.gbl...
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

Nov 20 '05 #2

P: n/a
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.

"B-Dog" <bd***@hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP10.phx.gbl... 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

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.