Resource file Overview
(1) resx file:
The text-based format is the XML format specific to the. NET Framework. It is called the ResX (. resx file ). Without considering its XML basics, this format is not specifically designed for manual reading (the XML format is rarely like this ). However, Visual Studio. NET still provides a basic editor for the. resx file.
(2) Resources file:
The. resources extension comes from the tool used to process the. resx file before embedding it 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 shown below:
C: \> resgen.exe Resource1.resx
After compiling the. resx file into the. resources file, you can use the ResourceReader in the System. Resources namespace to enumerate it:
II. Introduction to resource file applications
(1) Use in Windows Application:
1. note that the resx resource file in Windows Application is associated with the Form and Form. cs and Form. designer. cs and Form. the resx file is displayed as a whole (in Resource Manager). The concept of local and global resource folders is not involved here, and if you want to import the generated Resources file, right-click the project and add new Item. After selecting the relevant Resources file, remember to select the Build Action in the resource file attribute as Embadded resource (embedded resource). In this way, resources will be directly embedded into your application after compilation.
2. Specific application code example:
Copy codeThe Code is as follows:
Assembly assembly = Assembly. GetExecutingAssembly ();
ResourceManager rm = new ResourceManager ("TestStrongName123.Form1", assembly );
This. textBox1.Text = rm. GetString ("First ");
3. the difference between the resources file and the resx file can also be determined by their storage form of resources, the former will save all resources to the file, the latter only saves the reference to the resource.
Use in ASP. NET Web Application:
1. the application of the resource file here may be slightly different from the previous method, and a new usage method, that is, the concept of resource folder, is introduced in VS2005, that is, save the global resources and local resources to the App_GlobalResources and App_LocalResources directories respectively. As long as they are placed in the resource files in these two directories, you can continue file division based on your own categories, this does not affect the project to find the resource file. Here, we also need to briefly introduce the name of the resource file. For Global Resources, you only need to ensure that the file is a resx file, and the name can be customized by yourself, the latter must follow certain naming rules, that is, the corresponding page file name + ". resx ".
2. Specific application code example:
<1> application local resource (string ):
<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 = "liter_3" runat = "server" Text = "<% $ Resources: GlobalResource, GlobalString1 %>"> </asp: Literal>
Literal4.Text = (string) base. GetGlobalResourceObject ("GlobalResource", "GlobalString2 ");
<3> retrieve images from global resources:
Bitmap bm = null;
Bm = Resources. GlobalResource. GlobalSmallFail;
3. Another note: when using a web site, it is similar to the application here. I will not go into details here.
4. for the document system, the use of resource files is quite limited, because our document system adopts the policy of using client controls to avoid using server-side controls. Furthermore, we are all hungry applications that do not know the situation in advance (that is, the idea of global resources). Therefore, in view of this, the use of resource files in our system can only be limited to the use of strings, etc, however, images and other aspects may not meet our needs. Replacing images with images is still our preferred solution.