471,624 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

Embed an Access db in assembly and how to retrieve

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!
Nov 21 '05 #1
2 1168
"Jeff Beem" <Je******@discussions.microsoft.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Works perfectly! Thank you, Herfried

"Herfried K. Wagner [MVP]" wrote:
"Jeff Beem" <Je******@discussions.microsoft.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tony Sutton | last post: by
2 posts views Thread by Eric Barr | last post: by
7 posts views Thread by axis | last post: by
1 post views Thread by Guoqi Zheng | last post: by
1 post views Thread by Andreas Zita | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.