Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Deployment / Resources

Hi Experts!

I have written my first C# app that includes a number of background images, button images and avi movies.

Right now I read images and movies from a folder structure on disk.

The disadvantage is that everybody can simply exchange or manipulate these images.

Is it possible to included all the resources into a binary resource file and access them from there? What do I have to rearrange in my project to do it?

The next question:

I would like to deploy the app in such a way that .NET framework is included in the installation. How to do this?

I need some practical step-by-step advise how to handle this installer building, so-to-speak some condensed info for beginners. There are endless complicated articles on the web. I need to get started hands-on and all the C# books I have also do not comment on deploying my first application...

Thank you very much in advance for helping!

  • 9
  • 7
  • 2
  • +1
1 Solution
You can use a ImageList control to store your images

RemoteSoft has a product which gives you the ability to distribute a .NET application to a computer that does not have the framework installed:

i-ThomasAuthor Commented:
1) How to use ImageList control for this purpose? Please post some code example

2) Does it work also for the avis? I guess not...

3) I read something on the web that if .NET SDK is installed and .NET Bootstrap... (whatever this is) then you can create installation package with .NET redistributable package included. Do you know how this works? This should be basic problem of 1000s of developers...

Thanks a lot for your quick reaction!
1. You can use ImageList control very simple: drag ImageList control to your form, then open Property bag, select Images property, then add many images as you want. For example, I have a tree view control and want to apply image for node, in design mode, select TreeView control and bring up Property Bag, select ImageList property then select the ImageList control you just created.

TreeView.SelectedImageIndex property: select the image available from the list
TreeView.ImageIndex property: select the image available from the list

TreeNode node = new TreeNode();
node.Text = "Something";
node.ImageIndex = intIndexFromList;
node.SelectedImageIndex = intIndexFromList;
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

2) For avi, I think you right, it is impossible to do that
3) You can get dotnetfx.exe from www.asp.net. Its size about 20Mb. In your installation, force user to install dotnetfx first
Build a resouce only assembly and load your images and files from it at runtime.
Here is the article hoe to do it..

i-ThomasAuthor Commented:
Thanks so far for the additional hints.

I will work through them today and give you feedback!
i-ThomasAuthor Commented:
Now I come back to you, unfortunately only now and time is running out.


This article is interesting, but I would prefer to directly build the images into my code, not in a separate resource file.

I have found another article here at ee about this:


I took the solution of the accepted answer. My code:

public Form1()

        Stream pStream = this.GetType().Assembly.GetManifestResourceStream("Bitmap1.bmp");
        Image pImage = Image.FromStream(pStream, false, true);
        uxImagePbx.Image = pImage;

I tried two ways of adding a bitmap to my project:

1) drag and drop image from Windows Explorer to my project references
2) Use "Add Item" after right mouse click on it and then select the bitmap (allows only .bmp!?)

It resides in the same level hierarchy as the Form1.cs file.

Unfortunately I get the  following error message described in another article at ee:


An unhandled exception of type 'System.ArgumentException' occurred in system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.

The problem is:

I do not know why, because I set the property of the bitmap to "embedded resource" and did not forget it as describes in this article.

Perhaps I have to set some special compiler settings or make other settings in the IDE?

I hope you can help me, I have to finish the project till Sunday evening!

Thank you very much for helping!

You can build a resource file. And add it to the same application this way your resources will be embedded in same assembly. Then you will be able to use the ResourceManger class for reding the resouces.

For creating the resource file : -

The .NET Framework includes a sample application called ResEditor that facilitates creating and editing resource files. The ResEditor application allows you to create binary resource files (.resources) as well as XML resource files (.resX).

Building ResEditor
ResEditor is provided as source code with the .NET Framework SDK. Before you can use ResEditor, you must build it using the supplied batch file.

To build the ResEditor Application

1. Start Windows, and then click the Start button, point to All Programs, then Visual Studio .NET 2003, then Visual Studio .NET Tools, then Visual Studio .NET Command Prompt to open the Visual Studio .NET command prompt.

2. At the command prompt, change the directory to the SDK\v1.1\Samples\Tutorials\resourcesandlocalization\reseditor folder as shown below:
cd \Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Samples\Tutorials\resourcesandlocalization\reseditor

3. At the command prompt, type Build, then press the ENTER key to build the application.
ResEditor is built and the executable is placed in the \Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Tutorials\resourcesandlocalization\reseditor folder.

i-ThomasAuthor Commented:
Hello Jatinder!

Thanks for your reply, I managed to locate and build the resource-file editor.

How to read the image from a resource-file?

Can you please send me a code example?

Let's assume I have example.jpg and I put it into the resource file with the tool. What to do then?

Just include the Resource file in your project. Wherever you want to access the assembly.
Use following piece of code.

Assembly asm = Assembly.GetExecutingAssembly ( ) ;
ResourceManager rm = new ResourceManager ( "Name of resource", asm ) ;
pic.Image = ( Image ) rm.GetObject ("Name of image") ;

//The above code for retriving the images is the same as defined in article

And build the assembly.

i-ThomasAuthor Commented:
Thanks a lot!

I will soon try.

I have another urgend question related to that.

I created a setup up project for my app that works fine in Debug mode and also setup works fine in so far that all files and shortcuts are porperly installed on the target computer.

The only problem is that the relative path to some images does not work. I use this:

public Image DestiChart = Image.FromFile("charts\\desti_ch.tif");

My folder structure after installation looks like this:

-- charts
   -- desti_ch.tif
   -- ...

Time is scarce so I do not know, if I will manage changing all to the embedded resources right now. I have to deliver a test version in the next hour.

If charts is the subfolder in application directory. Then you need to use @"\charts\desti_ch.tif"
i-ThomasAuthor Commented:
Thank you very much again for the instant response.

Unfortunately this did not help.

I always get a System.Reflection.TargetInvocationException in my .exe

We can open a different thread, if you want, you deserve good points for your answers!

That's nice we can go for another thread.
i-ThomasAuthor Commented:
Hello Jatinder!

Unfortunately I can come back only now. I prefered to send out the first version without embedded resources but now I have to master them.

I made a number of tests and in priciple it works, but right now I find it very unhandy to have these three lines everywhere in my code.

In pricinple I would like to declare and initialize each image object once as I do when loading them from disk. I have about 30 images and all are needed frequently in the code so I would like to have each image represented by a short but clear name.

The problem I encounter is that I try to have the following lines only once in Form 1:

Assembly asm = Assembly.GetExecutingAssembly ( ) ;
ResourceManager rm = new ResourceManager ( "Name of resource", asm ) ;

I would like to have a line like

puclic Image AppStart = (Image)rm.GetObject("AppStart");

in the declaration part of my code, but the problem is that rm is unknown when I place the first two lines in Form1.

On the other hand I cannot put "public..." into Form1(), because "public" is not allowed there...

I hope you can understand what I am driving at and I hope you have a quick and simple solution for me!

Many many thanks again for helping me!

How about going for a singleTon design pattern for managing your resource manager instance.
This way you will always have a single calll from any form.
i-ThomasAuthor Commented:
Ok, from your answer I see that obviously it does not seem to be a beginners mistake that I do not get it going in one line instantly.

Can you please explain to me what a singleTon design pattern is?

Maybe you have a link at hand?

i-ThomasAuthor Commented:
Thank you very very much for your extensive answers and the very quick responses!

Best regards,


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 9
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now