Using resource files in Visual Basic 2008

Can anyone direct me to some tutorials on how to use resource files in Visual Basic 2008? I want to store a Word document, an empty Access database mdb and an HTML file in a resource file. I then want to either open these in a webbrowser control or save them to the hard disk. I am familiar with earlier vb programming, but this new paradigm has me struggling to keep up.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Luis PérezSoftware Architect in .NetCommented:
Mmm... if you want to store as different files as MS Word, MS Access and so on, I think that would be better to use compressed files than resource files. Resource files (and .NET managed resource associated classes) are specially designed to manage resource-oriented types as strings, images (like icons, cursors, gifs), etc; but for complex types or "raw" file types, as you want, is better to use compressed files (for example, zip files, in which you may store any file type).

Compression of .zip files in .NET can be easily accomplished by using SharpZipLib free open source library. You can find the library and documentation in:

Hope that helps.


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
Having said that...  You can add each of these files to your project as resource, and then "extract" them and use them when needed.

Here's an example of adding an Access database:
Click on the Project menu | Add Existing Item...
  Navigate to and select the Access file.
    If the DataSource Configuration Wizard opens, just click Cancel.

In Solution Explorer, Right-Click on the Access file, select Properties
  Set the Build Action to "Embedded Resource"

Here's the code that you can use to "extract" the Access file:

        'Create a temporary path for our file (or change to a specific path)   'or .accdb
        Dim tempPath As String = IO.Path.ChangeExtension(IO.Path.GetTempFileName(), ".mdb")

        'Get the Current Assembly information
        Dim currentAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()

        'Resource will store the full name of our embeded Access resource file
        Dim resource As String = String.Empty

        'Get all resource names and find the full embeded dpe.exe resource file name
        Dim arrResources As String() = currentAssembly.GetManifestResourceNames()
        For Each resource In arrResources

            'or .accdb
            If resource.IndexOf(".mdb") > -1 Then _
                Exit For


        'Open the Embeded Access resource
        Dim resourceStream As IO.Stream = currentAssembly.GetManifestResourceStream(resource)

        'Open FileStream to write out
        Dim writer As New IO.FileStream(tempPath, IO.FileMode.Create, IO.FileAccess.Write)

        'Write out all bytes of the stream
        Const size As Int16 = 4096
        Dim bytes(size) As Byte
        Dim numBytes As Int32 = 0

            numBytes = resourceStream.Read(bytes, 0, size)

            writer.Write(bytes, 0, numBytes)

        Loop While (numBytes > 0)

        'Close both streams and clean up


Luis PérezSoftware Architect in .NetCommented:
Well, in fact I never said that this couln't be done, but I said that probably would be better to use zip files... and I forget to mention one more advantage: zip files are by definition encoded (more over if they are password-protected), but resource files store in exe file as-is, byte-sequential, if I'm not wrong.
glenn_grubbAuthor Commented:
The code works in that it it writes a file to the disk, but it is unreadable by Access. I tried the same thing with a word document (I changed the appropriate extensions) and the same thing happened in that the Word document opened but it was just gibberish.
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
.NET Programming

From novice to tech pro — start learning today.