VisualBuilder
  Home > Csharp > Tutorials > Globalization and Localization -2 - C# Tutorial
Tell a friend
Link to us
Total Members
      Members: 84606
     
Sitemap Forum Chat
Home
C# Tutorial Home
1 . Introduction to C sharp
2 . Control Statement: Selection Statement in C sharp
3 . Control Statements – Loops Statement
4 . Methods
5 . Namespaces
6 . Introduction to Classes:
7 . Inheritance:
8 . Polymorphism
9 . Properties
10 . Indexers
11 . Structs
12 . Interfaces
13 . Delegates:
14 . Exception Handling:
15 . Attributes
16 . Enums
17 . Encapsulation
18 . Parameter Passing in C sharp
19 . Method Overloading
20 . Database Interaction Using C sharp
21 . Operator Overloading in C sharp -1
22 . Operator Overloading in C sharp -2
23 . Operator Overloading in C sharp -2
24 . Sockets
25 . DNS [Domain Name System]
26 . Working with Files
27 . Generating Help File in C sharp
28 . Code Access Security
29 . Multi-Threading
30 . Globalization and Localization -1
31 . Working with Registry in C sharp
32 . Globalization and Localization -2
33 . Windows Service
34 . Web Service
35 . Consuming Web Services
36 . Creating Proxy Object of Web Service
37 . Creating an XML document
38 . Reading XML document in C sharp
39 . Using XMLWriter class to Write XML document in C sharp
40 . Assembly Information : Getting Permission set of the assembly
41 . Creating your own Permission Set
42 . Using C sharp Socket
 
Csharp Group Home
Csharp Discussion (7)
Csharp Members (2250)
Csharp Resources
Csharp Source Code (35)
Csharp Articles (0)
Csharp Blogs
Csharp Jobs
Csharp Components (5)
Csharp Books
Csharp Websites (25)
Csharp News (17)
Csharp Q & A (4)
- Csharp Ask Question
- Csharp Questions
- Csharp Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (432 )
Source Code (3217 )
Articles (11 )
Components (1589 )
News (880 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Csharp Tutorial
 Globalization and Localization -2
  << Prev: Working with Registry in C sharp Next: Windows Service >>

The coming section will discuss about some more classes used for Globalization in C#.


 


Resources and ResourceWriter


 


Resources such as pictures or string tables can be put into resource files or satellite assemblies. Such resources can be very helpful when localizing applications, and .NET has built-in support to search for localized resources. A resource file can be a text file or a .resx file or XML file. This file contains the key/value pairs. Where the keys are used in the program and at run time they are replaced with the values that is corresponding to each key. For example:-


 


Name = Jim Tire


Address = USA


Author = Puppet


Publisher = Jim Toe


 


Note:-ResGen.exe utility is used to create a resource file out of this “test.txt” file. the command Resgen test.txt will create the text.txt resource file and Resgen test.txt test.resx will createtthe XML file from the test.txt file.


 


ResourceWriter


This class under the System.Resources namespace is used to create the resource file through the programming. The below example will create the object of the ResourceWriterAddResource() method. and then we can use the same object to add upto 2GB of resources. We have to just supply the key/value pair to the object's


 


Example: Demonstrate ResourceWriter


 


using System;


using System.Collections.Generic;


using System.Text;


using System.Runtime.Remoting;


using System.Threading;


using System.Globalization;


using System.Resources;


 


namespace ConsoleApplication1


{


  class Program1


    {


    static void Main ( string [] args)


        {


            ResourceWriter rw = new ResourceWriter ( "RWDemo.resources" );


      rw.AddResource( "Name " , "VisualBuilder" );


      rw.AddResource( "Adress" , " UK " );


      rw.AddResource( "Hobby" , "Cricket" );


      rw.AddResource( "Favourite Country" , " Australia " );


      rw.AddResource( "Player" , "Sunny" );


      rw.Close();


        }


    }


}


 


Output:


 


This will create RWDemo.resources file, which contains the key/value pairs. The Close() method of the ResourceWriter class automatically calls ResourceWriter.Generate() to finally write the resources to the file RWDemo.resources.


 


Using Resource File in an Application


 


We can add resource files to assemblies using the assembly generation tool al.exe, using the /embed option or using the c# compiler with /resource option or directly using the VS.Net. The following are the steps to use the resource files in C# application.



  1. Open the application

  2. Use the context menu of the solution explorer (Add >> Add Existing Item)

  3. Locate the path where the resource file is situated.

  4. If you check the Resource after adding it to the projects, its BuildAction is “Embedded Resource”, this means the resource is embedded to the output assembly.

  5. You can view the resource file using the ILDasm.exe utility by checking it in the assembly manifest.

  6. To access the embedded resources, use the Resource Manager class from the System.Resources namespace.

  7. You can pass the assembly that has the resources as an argument to the constructor of the Resource Manager class

  8. Once you include the resource file in the application use the Resource Manager and load the resource file into this.


 


Example: Demonstrate Usage of Resource File


 


using System;


using System.Collections.Generic;


using System.ComponentModel;


using System.Data;


using System.Drawing;


using System.Text;


using System.Windows.Forms;


using System.Reflection;


using System.Resources;


 


namespace cSHARPEXAMPLES


{


  public partial class Form22 : Form


    {


    public Form22()


        {


        InitializeComponent();


        }


 


    private void button1_Click( object sender, EventArgs e)


        { //Using Resource File


        System.Resources. ResourceManager rm;


                Assembly assembly = Assembly .GetExecutingAssembly();


        rm = new ResourceManager ( "cSHARPEXAMPLES.RWDemo" , assembly);


                txtName.Text = rm.GetString( "Name " );


                txtAddress.Text=rm.GetString( "Adress" );


                txtHobby.Text = rm.GetString( "Hobby" );


                txtFCountry.Text = rm.GetString( "Favourite Country" );


                txtPlayer.Text = rm.GetString( "Player" );


        }


    }


}


 


 


  << Prev: Working with Registry in C sharp Next: Windows Service >>
Csharp Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
VoIP Internettelefonie AT
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising