473,226 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 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 1229
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tony Sutton | last post by:
I have this following code in my html file: <object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#...
2
by: Eric Barr | last post by:
I've found myself using XSD files for my datasets. I'm loading them up from disk right now. I was hoping there was a way to embed the file in the assembly, so I could have access to it without...
7
by: axis | last post by:
What I want to do is pretty simple: I have a bunch of icons in my application project (visual studio .net 2003), and I want to embed those in the executable, and access them through code. I've...
1
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
1
by: Guoqi Zheng | last post by:
I have an ASP.NET application, I need to distribute it to clients. I used some text file to stroed database scripts, .sql files. Those .sql files are very very important part of the application,...
1
by: Andreas Zita | last post by:
Hi I have a 2.0-app which contains some xsl-files. I would like to embed these files in the deployed sites assembly. Previously I would mark the files as embedded resource and then retrieve them...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
8
by: CodeLeon | last post by:
Hi, All. I am creating a setup program. The way it works is that the user creates their setup info, my program generates the C# code for a setup executable, embeds the xml file containing the info...
0
by: VigneshS | last post by:
Hi, I am a newbie to Globalization and Localisation Concepts. I tried almost all the methods of the Globalization concepts. But i cannot be able to embed a text file within a Resource. ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.