views:

66

answers:

3

I`m using C# and WPF ... I`m asking this question as I have never found a solution to my previous questions!! so I want to add an empty access database file to the application resources and to copy it to a specific location, I want to know how to add/retrieve the file from the resources ... also, is there a way to update the file during the runtime of the application (like a backup, so that if I move the app to another location or pc the latest updates are used)??

A: 

You can do that in Visual Studio, when you click on the file you want as a resource, go to Properties window and change "Build action" to Resource. I this window, there is also the option to copy the resource to the target directory.

Jan Kratochvil
+1  A: 
using (var resourceStream = Assembly
    .GetExecutingAssembly()
    .GetManifestResourceStream(resourceName))
{
    if (resourceStream != null)
    {
        //read the stream

The tricky bit is getting the resourceName correct. You need to convert the file location into the namespace it belongs to.

So for instance, with a default namespace of DefaultNS, and the file living in a project folder called resources with a filename of myfile.ext, you would have a resource name of:

DefaultNS.resources.myfile.ext
spender