Question:

VB.net save an existing file to another location?

by  |  earlier

0 LIKES UnLike

lets say i have a database file in fixed location (c:\database.mdb) and i want to copy it to another location as a back up using a button. how to code the button command to perform that function? anyone can help me?

 Tags:

   Report

2 ANSWERS


  1. Function copyfile(strfrom, strto) As Boolean

    'Copy a file from one place to another!

    On Error GoTo errhandler

    Dim objfso As Object

    Const OverwriteExisting = True

    Set objfso = CreateObject("Scripting.FileSystemObject...

    objfso.copyfile strfrom, strto, OverwriteExisting

    copyfile = True

    done:

    On Error Resume Next

    Set objfso = Nothing

    Exit Function

    errhandler:

    copyfile = False

    Resume done

    End Function

    Example use to create a backup with current time and date:

    Call copyfile("c:\database.mdb","c:\backups\" & Format(Now, "yyyymmdd_hhmm") & ".mdb"


  2. As you requested  ÃƒÂ¢Ã‚€Â¦Ã¢Â€Â¦.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            MsgBox(copy_File("c:\nph-proxy.cgi", "c:\nph-proxy.bc1"))

    End Sub

        Private Function copy_File(ByVal SRC_FILE As String, ByVal DEST_FILE As String) As Boolean

            copy_File = True

            Dim CUR_FILE As System.IO.File

            Try

                CUR_FILE.Copy(SRC_FILE, DEST_FILE)

            Catch ex As Exception

                copy_File = False

            End Try

       End Function

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.