?
Solved

Visual Basic - Copy File - Overwrite destination - Suppress Windows 7 Dialog box - Auto Exit and Open Program

Posted on 2011-10-26
9
Medium Priority
?
951 Views
Last Modified: 2012-05-12
Hello all.

I 'm in need of some help in some coding.  What i'm looking at doing is copying a file from one location to another and OVERWRITING it, then open a Program and auto exit out of the VB form/project.

The first issue I ran into is that when the project/form tries to copy and replace the file in Windows 7, Windows 7 prompts asking if you want to merge, replace.  

Here is the code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
My.Computer.FileSystem.CopyFile( _
   "C:\folder1\ini\name.ini", _
   "C:\folder2\name.ini", _
   FileIO.UIOption.AllDialogs, _
   FileIO.UICancelOption.DoNothing)
    End Sub

Open in new window


For the rest of the code (auto exit and open a specific program) i'm really lost.
0
Comment
Question by:jwhiteuwc
  • 5
  • 4
9 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37034049
One of the overrides of the CopyFile takes a boolean parameter to specify whether or not to overwrite the file

Public Sub CopyFile( _
   ByVal sourceFileName As String, _
   ByVal destinationFileName As String, _
   ByVal overwrite As Boolean _
)
0
 

Author Comment

by:jwhiteuwc
ID: 37037314
Added the above code and it's till prompting.  See image below.  copyreplace copyreplace
0
 

Author Comment

by:jwhiteuwc
ID: 37044935
I've requested that this question be deleted for the following reason:

Found solution.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37040372
What's the solution?
0
 

Author Comment

by:jwhiteuwc
ID: 37040382
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        System.Diagnostics.Process.Start("C:\Dolphin\Dolphin.exe")

Allows for opening the program.  I still haven't found a solution to the Windows 7 COPY AND replace prompt.  
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37040401
>System.Diagnostics.Process.Start("C:\Dolphin\Dolphin.exe")

So you closed the wrong question?
0
 

Author Comment

by:jwhiteuwc
ID: 37040420
Here is the entire code, what i'm a missing to suppress the COPY and REPLACe prompt?

THis was a 3 part question.

1) suupress teh copy and replace
2) open a program
3) auto exit.

I found the answer to the auto exit and open program, but still no answer for the supressing of the COPY and REPLACE.  
Public Class Form1
    Public Sub CopyFile( _
   ByVal sourceFileName As String, _
   ByVal destinationFileName As String, _
   ByVal overwrite As Boolean _
)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Computer.FileSystem.CopyFile( _
   "C:\dolphininis\shbini\dolphin.ini", _
   "C:\dolphin\dolphin.ini", _
   FileIO.UIOption.AllDialogs, _
   FileIO.UICancelOption.DoNothing)
        System.Diagnostics.Process.Start("C:\Dolphin\Dolphin.exe")
        End
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        My.Computer.FileSystem.CopyFile( _
   "C:\dolphininis\manini\dolphin.ini", _
   "C:\dolphin\dolphin.ini", _
   FileIO.UIOption.AllDialogs, _
   FileIO.UICancelOption.DoNothing)
        System.Diagnostics.Process.Start("C:\Dolphin\Dolphin.exe")
        End
    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub
End Class

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 37040624
Do a

If IO.File.Exists("path") Then
   IO.File.Delete("path")
End If


before the copy.
0
 

Author Comment

by:jwhiteuwc
ID: 37044936
Solution Provided by CodeCruiser
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question