Resource Document Introduction
(1) Resx file:
Text-based formats are XML formats specific to the .NET framework, called ResX (.resx file). Regardless of its XML basis, the format is not designed specifically for manual reading (the XML format is rarely the case). However, Visual Studio .NET still provides a basic editor for .resx files.
(2) Resources file:
The .resources extension comes from the tools used by Visual Studio .NET to process a .resx file before embedding it as a resource. The tool name is , which is used to "compile" the .resx XML format into a binary format. You can manually compile the .resx file into a .resources file as follows:
C:\>
After compiling the .resx file into a .resources file, you can enumerate it using the ResourceReader in the namespace:
2. Introduction to the resource file application
(1) Use in Windows Application:
1. First of all, the resx resource file in Windows Application is associated with the Form, and the resx file is displayed as a whole (in the resource manager). This does not involve the concept of local and global resource folders. If you want to import the generated Resources file, just right-click the add new Item on the project. After selecting the relevant Resources file, remember to select the Build Action in the properties of the resource file as Embadded resource. In this way, the resources will be directly embedded into your application after you compile.
2. Specific application code examples:
Assembly assembly = ();
ResourceManager rm = new ResourceManager("TestStrongName123.Form1", assembly);
this. = ("First");
The difference between a file and a resx file can also be judged from the way they save the resource. The former will save all resources to the file, while the latter will only save references to the resource.
Use in Web Application:
1. When applying resource files here, it may be slightly different from the previous usage methods. In addition, a new usage method was introduced in VS2005, namely the concept of resource folders, that is, save global resources and local resources into the App_GlobalResources and App_LocalResources directories respectively. As long as the resource files placed in these two directories, you can continue to divide the file according to your own classification. This does not affect the project's finding the resource file. Here we will also briefly introduce the naming of the resource file. The global resource only needs to ensure that its file is a resx file, and the name can be at will. The naming of the latter must follow certain naming rules, that is, the corresponding page file name + ".resx".
2. Specific application code examples:
<1> Apply local resources (string):
<asp:Literal ID="Literal1" runat="server" Text="<%$Resources:LocalString1%>"></asp:Literal>
= (string)("LocalString2");
<2> Apply global resources (string):
<asp:Literal ID="Literal3" runat="server" Text="<%$Resources:GlobalResource, GlobalString1%>"></asp:Literal>
= (string)("GlobalResource", "GlobalString2");
<3> Get the picture in the global resource:
Bitmap bm = null;
bm = ;
3. Other explanation: When using a web site, it is similar to the application here, so I won’t go into details here.
4. For official document systems, the use of resource files is relatively limited, because our official document system adopts a strategy to use client controls and avoid using server-side controls; furthermore, we are unable to know the situation in advance (that is, the global resource idea). Therefore, in view of this, the use of application resource files in our system can only be limited to the use of strings, etc., but it may not meet our needs in terms of pictures, and using image replacement is still our preferred solution.
(1) Resx file:
Text-based formats are XML formats specific to the .NET framework, called ResX (.resx file). Regardless of its XML basis, the format is not designed specifically for manual reading (the XML format is rarely the case). However, Visual Studio .NET still provides a basic editor for .resx files.
(2) Resources file:
The .resources extension comes from the tools used by Visual Studio .NET to process a .resx file before embedding it as a resource. The tool name is , which is used to "compile" the .resx XML format into a binary format. You can manually compile the .resx file into a .resources file as follows:
C:\>
After compiling the .resx file into a .resources file, you can enumerate it using the ResourceReader in the namespace:
2. Introduction to the resource file application
(1) Use in Windows Application:
1. First of all, the resx resource file in Windows Application is associated with the Form, and the resx file is displayed as a whole (in the resource manager). This does not involve the concept of local and global resource folders. If you want to import the generated Resources file, just right-click the add new Item on the project. After selecting the relevant Resources file, remember to select the Build Action in the properties of the resource file as Embadded resource. In this way, the resources will be directly embedded into your application after you compile.
2. Specific application code examples:
Copy the codeThe code is as follows:
Assembly assembly = ();
ResourceManager rm = new ResourceManager("TestStrongName123.Form1", assembly);
this. = ("First");
The difference between a file and a resx file can also be judged from the way they save the resource. The former will save all resources to the file, while the latter will only save references to the resource.
Use in Web Application:
1. When applying resource files here, it may be slightly different from the previous usage methods. In addition, a new usage method was introduced in VS2005, namely the concept of resource folders, that is, save global resources and local resources into the App_GlobalResources and App_LocalResources directories respectively. As long as the resource files placed in these two directories, you can continue to divide the file according to your own classification. This does not affect the project's finding the resource file. Here we will also briefly introduce the naming of the resource file. The global resource only needs to ensure that its file is a resx file, and the name can be at will. The naming of the latter must follow certain naming rules, that is, the corresponding page file name + ".resx".
2. Specific application code examples:
<1> Apply local resources (string):
<asp:Literal ID="Literal1" runat="server" Text="<%$Resources:LocalString1%>"></asp:Literal>
= (string)("LocalString2");
<2> Apply global resources (string):
<asp:Literal ID="Literal3" runat="server" Text="<%$Resources:GlobalResource, GlobalString1%>"></asp:Literal>
= (string)("GlobalResource", "GlobalString2");
<3> Get the picture in the global resource:
Bitmap bm = null;
bm = ;
3. Other explanation: When using a web site, it is similar to the application here, so I won’t go into details here.
4. For official document systems, the use of resource files is relatively limited, because our official document system adopts a strategy to use client controls and avoid using server-side controls; furthermore, we are unable to know the situation in advance (that is, the global resource idea). Therefore, in view of this, the use of application resource files in our system can only be limited to the use of strings, etc., but it may not meet our needs in terms of pictures, and using image replacement is still our preferred solution.