Embed an Access db in assembly and how to retrieve

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I know that I can place an access database into an assembly as a resource by
dropping it into the Project Explorer and setting it's "Build Action"
property to Embedded Resource. How do I, then, extract that resource and
write it to disk? I'm using the file as a template. I don't want to use
ADOX to create the file because my boss doesn't like COM references. I
actually have several files that I need to do this way so creating a resource
dll would not be a problem if that's the best solution.

Thanks, in advance!
 
Jeff Beem said:
I know that I can place an access database into an assembly as a resource
by
dropping it into the Project Explorer and setting it's "Build Action"
property to Embedded Resource. How do I, then, extract that resource and
write it to disk?

Written from scratch and thus untested:

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Dim s As Stream = _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
"WindowsApplication17.db1.mdb" _
)
Dim Reader As New BinaryReader(s)
Dim fs As New FileStream("C:\db1.mdb", FileMode.CreateNew)
Const BlockSize As Integer = 1024 ' Read blocks of 1,024 bytes.
Dim BytesRead As Long
Dim Buffer() As Byte
Do While BytesRead < Reader.BaseStream.Length
Buffer = Reader.ReadBytes(BlockSize)
fs.Write(Buffer, 0, Buffer.Length)
Debug.Write(System.Text.Encoding.Default.GetString(Buffer))
BytesRead = BytesRead + Buffer.Length
Loop
Reader.Close()
fs.Close()
///
 
Works perfectly! Thank you, Herfried

Herfried K. Wagner said:
Jeff Beem said:
I know that I can place an access database into an assembly as a resource
by
dropping it into the Project Explorer and setting it's "Build Action"
property to Embedded Resource. How do I, then, extract that resource and
write it to disk?

Written from scratch and thus untested:

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Dim s As Stream = _
[Assembly].GetExecutingAssembly().GetManifestResourceStream( _
"WindowsApplication17.db1.mdb" _
)
Dim Reader As New BinaryReader(s)
Dim fs As New FileStream("C:\db1.mdb", FileMode.CreateNew)
Const BlockSize As Integer = 1024 ' Read blocks of 1,024 bytes.
Dim BytesRead As Long
Dim Buffer() As Byte
Do While BytesRead < Reader.BaseStream.Length
Buffer = Reader.ReadBytes(BlockSize)
fs.Write(Buffer, 0, Buffer.Length)
Debug.Write(System.Text.Encoding.Default.GetString(Buffer))
BytesRead = BytesRead + Buffer.Length
Loop
Reader.Close()
fs.Close()
///
 
Back
Top