Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to replace a file thats on a remote machine without deleting it. I just need to overwrite the file. I have this code that copies just fine but i dont know what i need to add so it will replace what was there and continue.

VB
Dim FileToCopy As String = "\\" & strComputer & "\C$\Progra~2\Hewlett-Packard\HPCA\Agent\Lib\SYSTEM\RADIA\SOFTSRVC\ASERVICE.EDM"
File.Copy("C:\Temp\ASERVICE.EDM", FileToCopy)
Posted

1 solution

You need to add , true to the parameter list, the other version of that method taking a third param to say if you want to overwrite the file.
 
Share this answer
 
Comments
Zachary.shupp 10-Feb-12 13:31pm    
so it would look like this ?

Dim FileToCopy As String = "\\" & strComputer & "\C$\Progra~2\Hewlett-Packard\HPCA\Agent\Lib\SYSTEM\RADIA\SOFTSRVC\ASERVICE.EDM"
File.Copy("C:\Temp\ASERVICE.EDM", FileToCopy, True)
Christian Graus 10-Feb-12 13:33pm    
Correct. As a rule I would test that code before asking the question, not vice versa :-)
Zachary.shupp 10-Feb-12 13:35pm    
is still get:




The file '\\ADNRFZ900016\C$\Progra~2\Hewlett-Packard\HPCA\Agent\Lib\SYSTEM\RADIA\SOFTSRVC\ASERVICE.EDM' already exists.
Christian Graus 10-Feb-12 13:42pm    
http://msdn.microsoft.com/en-us/library/aa328774(v=vs.71).aspx

That is impossible. True tells it to overwrite the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900