Wednesday, October 30, 2013

Copy file sample in visual basic

Copy file sample in visual basic

FileCopy is the simplest way to copy a file. Use this sample or part of the example to make a efficient file copy tool.
Here is how it works:

        'calling the FileCopy method, very simple
        FileCopy(Source, Destination)

I made a sample project, you could download it. There is nothing special inside. I added a little function tool to help the user get the files names,

''' <summary>
''' This is a sample
''' This show you how to use FileCopy method to copy a file
''' There are better way to copy a file other than FileCopy
''' This is very basic, there is no checking, no security, no rights.
''' Use copy file for simple task or basic operations.
''' </summary>
''' <remarks></remarks>
Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim Source As String = ""
        Dim Destination As String = ""

        'get a file name
        Using oOpenFileDialog As New OpenFileDialog
            If oOpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Source = oOpenFileDialog.FileName
            End If
        End Using

        'Get the name to save to
        Using oSave As New SaveFileDialog
            If oSave.ShowDialog = Windows.Forms.DialogResult.OK Then
                Destination = oSave.FileName
            End If
        End Using

        'calling the FileCopy method, very simple
        FileCopy(Source, Destination)

        Me.Close() 'close the form because the sample is completed.

    End Sub
End Class

This email is free from viruses and malware because avast! Antivirus protection is active.


  1. A straight line is the shortest distance between two points.
    Here I present to you:
    The shortest and easiest way to program a simple calculator in less time and at the lowest possible number of code
    Waiting for your comments and opinions