Setup Project - How do you install a file like a .mdb file onto the user's C drive?

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Hi Everyone,

I did my first setup project and it installs nicely.

I have a .mdb file I would like to include into the setup project and have it install it to the user's C drive only if it does not exist there yet?

Can you tell me how to do it?

Thanks.

Truly,
Emad
 

Attachments

  • setup project.jpg
    setup project.jpg
    297.3 KB · Views: 33
Emad,

Here is a solution you could try.

Have the installer include the .MDB file along with your other files in the same program folder.
Example, the user states in the installer that they want to install the software to C:\Program Files\Company\Software\; so with that, the installer copies the software files, but also a backup copy of the .MDB file - maybe in the path C:\P...\Software\data\orginialdatabase.mdb

The reason for this, is that it will work with the following code - which you can incorporate in to your project in the Form_Load procedure on the MAIN form:
VB.NET:
Private Sub Form_Load()
    Dim Directory As String = "C:"

    'Check to see if the database exists.
    If Not My.Computer.FileSystem.FileExists(Directory & "\database.mdb") Then
        MsgBox("The database could not be found. The application will now replace a backup of the database.")
        FileCopy(Application.StartupPath & "\data\database.mdb", Directory & "\database.mdb")
    Else
        MsgBox("The database was found: " & Directory & "\database.mdb")
    End If

    'INCLUDE HERE, OTHER FORM_LOAD CODE.

So here, you are using both a backup copy and an actual copy. Another addition to your software is that you could have the application, on exit, save a backup copy of the database just in case something goes wrong:
VB.NET:
Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Dim outFileName As String = "db_backup_" & Format(Date.Now, "ddMMyy_HHmm") & ".mdb"
    FileCopy(Directory & "\database.mdb", Application.StartUpPath & "\data\backups\" & outFileName)
End Sub

I hope this has helped you with your problem. :)
 
Last edited:
Back
Top