Embed a file (.mdb) into app then extract and SaveAs... i.e. stores template in app or DLL file


I have decided that creating a Microsoft Access database was much easier in VB6 than in .NET therefore I have created a blank database (table and relationship structure OK but no data) and would like to:
1) Embed this into the distributable code (either within the main .exe or ideally as a DLL file.
2) Within the application copy the embedded file and SaveAs \my_path\myname.mdb
3) Open and manipulate the database

Hope someone can help. Rather than explaining how to in general terms, a good URL or code example would ensure points.
Thanks in advance,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you can do it with embedded resources in .NET, look here for an explanation with images, only think it through in mdb

I think you can use the same technique to get to a stream of an mdb file
mdb_stream = _
           executing_assembly.GetManifestResourceStream(my_namespace _
           + ".my.mdb"
then you can either write that stream to a file \mypath\my.mdb
nvmsAuthor Commented:
THanks for taking the time to provide this example. The example is in VB not C#, ideally a simple 10 line example of read/write resulting in a new file would be excellent. Will see if any further comments come along otherwise it's yours.
In your case since it's an mdb it's more the principle than the code i think, but here is a c# howto
since both use an image and show it instead of saving it, you would have to write the stream to disk
check this article for an extensive explanation

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nvmsAuthor Commented:
Excellent ! I used these starting points and a good example found at:
to create the following test code. Once you choose Project...Add existing item... locate your file (any file, .doc .txt etc) and specify in the properties of the item "Embedded Resource" then the following code works perfectly:
(assumes that there is only one embedded file ending in .mdb, and that the file to create is c:\test.mdb.)
Writes the destination file in 32Kb chunks, my file was 1.6Mb and opened perfectly retaining all table and relationship information. Now all I need to do is keep this code in a DLL file so the overheads in the executable are not too high

Assembly a = Assembly.GetExecutingAssembly();
string [] resNames = a.GetManifestResourceNames();
foreach(string s in resNames)
using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream(s))
using (Stream output = new FileStream("c:\\Test.mdb",
byte[] buffer = new byte[32768];
int read;
while ( (read=input.Read(buffer, 0, buffer.Length)) > 0)
output.Write(buffer, 0, read);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.