. NET resource files resx, resources details _ Practical Tips

Source: Internet
Author: User
Introduction to Resource Files

(1) ResX file:
text-based formats are XML formats that are specific to the. NET framework, known as ResX (. resx files). Regardless of its XML base, the format is not specifically designed for manual reading (this is rarely the case with XML format). However, Visual Studio. NET still provides a basic editor for. resx files.

(2) Resources document:
The. resources extension is derived from the tool used by Visual Studio. NET to work with a. resx file before it is embedded as a resource. The tool name is Resgen.exe, which is used to "compile" the. resx XML format into binary format. You can manually compile the. resx file into a. resources file, as follows:
C:\> Resgen.exe Resource1.resx
After you compile a. resx file into a. resources file, you can enumerate it using the ResourceReader in the System.Resources namespace:

Ii. Introduction to the application of resource files

(1) Use in Windows application:

1. The first note is that the RESX resource file in Windows application is associated with the form in which it is linked. and Form.cs and Form.Designer.cs and Form.resx files are presented as a whole (in the explorer), where the concept of a local and global resource folder is not involved, and if you want to import the resources already generated, right-click on the project directly to add New item, select the relevant resources file, and remember to select the build action in the property of the resource file as embadded resource (embedded Resource), so that the resource will be embedded in your application directly after you compile it.

2. Specific application code examples:
Copy Code code as follows:

Assembly Assembly = assembly.getexecutingassembly ();
ResourceManager rm = new ResourceManager ("Teststrongname123.form1", assembly);
This.textBox1.Text = rm. GetString ("a");

3.resources files are different from ResX files, or they can be judged by the way they save the resource, which saves all resources to the file, which simply saves references to the resource
Use in the ASP.net Web application:

1. Applying a resource file here may be slightly different from the previous approach, and a new way of using it in VS2005, the concept of a resource folder, is to save the global resource and local resources to App_GlobalResources and APP_ respectively LocalResources directory, as long as the resource files in these two directories, you can continue to classify the files according to their classification, this does not affect the project to find resource files, here also to the name of the resource file a brief introduction, global resources as long as the file as a ResX file can be, The name itself can be arbitrary, and the latter name must follow a certain naming rules can be, namely: the corresponding page file name + ". resx".

2. Specific application code examples:
<1> Apply local Resources (strings):
<asp:literal id= "Literal1" runat= "Server" text= "<% $Resources:localstring1%>" ></asp:Literal>
Literal2.text = (string) this. GetLocalResourceObject ("LocalString2");
<2> Apply global Resources (strings):
<asp:literal id= "Literal3" runat= "Server" text= "<% $Resources: Globalresource, globalstring1%>" ></asp :literal>
Literal4.text = (string) base. GetGlobalResourceObject ("Globalresource", "GlobalString2");
<3> get pictures from global resources:
Bitmap BM = NULL;
BM = Resources.GlobalResource.GlobalSmallFail;

3. Another point: the use of web site sites, and the application here is similar, here is not to repeat.

4. For the official Document System, the use of resource documents is limited, because our official Document system adopts the strategy of using the client control to avoid using the server-side controls; Moreover, we are all hungry applications cannot advance to know the situation (that is, the resource mentality of globalization), so, in view of this, The use of resource files in our system can only be limited to the use of strings, etc., but in the picture and so on may not be able to meet our needs, the use of picture replacement is still our preferred solution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.