' Notes:
' The file that you add to the project has to have the Build Action
' property changed to "Embedded Resource" for this to work. This will
add the file
' to the project as a resource and not a compiled item.
'
Dim ResStream As System.IO.Stream
' This is the name of your applications namespace followed by the name
of the file that's embedded.
' So if your namespace is "MyProject" and the name of the file is
"BlankDatabase.mdb" then
' the value for the sResPath would be "MyProject.BlankDatabase.mdb".
Dim sResPath As String = "AnimalControl.db.mdb"
Dim NewFilePathName As String = sPath
Dim numBytesRead As Integer = 0
' Get the Embedded Resource
ResStream =
System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(sResPath)
Dim numBytesToRead As Integer = CInt(ResStream.Length)
Dim bytes(ResStream.Length) As Byte
While numBytesToRead + 1 > 0
Dim n As Integer = ResStream.Read(bytes, numBytesRead, numBytesToRead)
' The end of the file has been reached.
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
' Save the resource to file
Dim fs As New FileStream(NewFilePathName, FileMode.Create)
fs.Write(bytes, 0, bytes.Length)
fs.Close()