?
Solved

Deployment / Resources

Posted on 2005-04-05
19
Medium Priority
?
325 Views
Last Modified: 2008-03-17
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!

0
Comment
Question by:i-Thomas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 2
  • +1
19 Comments
 
LVL 8

Expert Comment

by:rajaloysious
ID: 13706009
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:
  http://www.remotesoft.com/linker/

cheers
0
 

Author Comment

by:i-Thomas
ID: 13706200
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!
0
 
LVL 13

Expert Comment

by:dungla
ID: 13713130
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;
TreeView.Nodes.Add(node);
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:dungla
ID: 13713139
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
0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13714170
Build a resouce only assembly and load your images and files from it at runtime.
Here is the article hoe to do it..
http://www.funducode.com/csharpart/csarticle19.htm


jatinder
0
 

Author Comment

by:i-Thomas
ID: 13714550
Thanks so far for the additional hints.

I will work through them today and give you feedback!
0
 

Author Comment

by:i-Thomas
ID: 13740135
Now I come back to you, unfortunately only now and time is running out.

@jatinderalagh

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:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20769673.html

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

public Form1()
{
      InitializeComponent();

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

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:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21088244.html


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!





0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13744273
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.


Cheers
jatinder
0
 

Author Comment

by:i-Thomas
ID: 13751702
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?

0
 
LVL 11

Accepted Solution

by:
jatinderalagh earned 2000 total points
ID: 13752080
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
//http://www.funducode.com/csharpart/csarticle19.htm

And build the assembly.

0
 

Author Comment

by:i-Thomas
ID: 13752303
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:

MyAppFolder
-- 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.



0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13752414
If charts is the subfolder in application directory. Then you need to use @"\charts\desti_ch.tif"
0
 

Author Comment

by:i-Thomas
ID: 13752637
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!

0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13780908
That's nice we can go for another thread.
0
 

Author Comment

by:i-Thomas
ID: 13806566
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!





0
 
LVL 11

Expert Comment

by:jatinderalagh
ID: 13813165
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.
0
 

Author Comment

by:i-Thomas
ID: 13814308
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?

0
 

Author Comment

by:i-Thomas
ID: 13866068
Thank you very very much for your extensive answers and the very quick responses!

Best regards,

i-Thomas
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question