Click here to Skip to main content
15,917,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
One question was bothering me, why do we need to use resources.
I mean it is clear to use files in your project but I want to know what are the cons of using them.
Why not use an installer to install your files in a directory in another computer?

P.S Im am making a large project and I was thinking of optimizing it.
Posted

For one thing, it means that your users can't mess you up by accidentally or deliberately deleting important parts of your application. Resources embedded as part of your app do not appear as separate files, so they can't be removed.

A major reason for using them though, is the ease of access. Which would you rather have:
VB
Dim myImage As Image = Properties.Resources.MyPicture
Or
VB
Dim myImage As Image = Image.FromFile(Application.StartupPath + "\myPicture.jpg")
 
Share this answer
 
The use of resources has nothing to do with installation, essentially. We use them, basically, to isolate a mass of immutable parametric data from the application, and — very essential thing — to globalize the application. This is some feature which you might be not familiar with, otherwise you would not have this question.

The .NET ways of application globalization is based on putting UI strings and strings formats (not only graphical UI but anything which could appear on screen in any mode, in console of windowed, or in output files, including exception messages) in the resources. A well globalized application is something fully ready for localization without passing the kernel source code to the translators and without recompilation of the source code.

The localizing team only gets the resource part of the project, along with original documentation and appropriate number of copies of the working product. Those people translate all resources into a new resource-only project and put it in the working directory under a sub-directory named by a target culture. This part of project does not depend on original project and is simply added to it, without any recompilation of existing code. Such deployed additional localizing parts of the projects are called satellite assemblies. When a resource is needed, the .NET resource managers inquire the current UI culture of a UI thread and loads corresponding satellite assemblies to replace original set of resources fully or partially, depending on available satellite assemblies. If some satellite assembly is not found for certain resource set, a closest possible culture is used. This search falls backs all the way down to the culture used in original product, which is called the fallback process.

This way, the localized resources are added in non-intrusive way, without using the source code of original project and without recompilation of anything.

As to the deployment, installation is only one of the mechanism. You can use just the copy of the output directory with all satellite assemblies and let the user to select the UI culture dynamically at any moment, effectively switching the UI culture using any of the localizations available.

As to the installation, one can use different scenarios. It can be deployment of all satellite assemblies at once, configuring the application culture before execution or dynamically; or one can provide a mechanism for downloading of required satellite assemblies on request (please see the last link below).

There are a number of delicate aspect of globalization and localization, such as text direction and layout, but I explained the main idea. For further reading, please see:
http://msdn.microsoft.com/en-us/library/aa292205%28v=vs.71%29.aspx[^],
http://msdn.microsoft.com/en-us/library/aa291552%28v=vs.71%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms753931.aspx[^],
http://msdn.microsoft.com/en-us/library/ms788718.aspx[^],
http://msdn.microsoft.com/en-us/goglobal/bb688142.aspx[^],
http://msdn.microsoft.com/en-us/library/21a15yht%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/70s77c20.aspx[^],
http://msdn.microsoft.com/en-us/library/70s77c20.aspx[^].

—SA
 
Share this answer
 
v2
Just to add to OriginalGriff's message, it also means you have consistency in your application in terms of messaging. E.g. you can define a number of error messages that would be used throughout your application.

"Sorry, there was a problem with the data - please correct the issues and try again" etc

You just add that to your Resource file and you now have

VB
Dim errorMessage As String = Properties.Resources.InvalidDataMessage


Also, this allows you to make your application multi-language by providing culture specific translations for you resource files.
 
Share this answer
 
Comments
ShinigamiXoY 18-Jun-12 12:22pm    
Thanks I liked you solution more, what OriginalGriff said I already knew.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900