Usage of resource files in. net

Source: Internet
Author: User

 

I,Resource file Overview

 

(1)ResxFile:

text-based format is specific to . net framework XML Format, called resx ( . resx file ). Ignore XML XML This is rarely the case ). However, Visual Studio. net still . resx provides a basic editor.

 

(2)ResourcesFile:

. ResourcesThe extension comes from. ResxBefore the file is embedded as a resourceVisual Studio. NETThe tool used to process the file. The Tool Name isResgen.exe, Which is used. Resx XMLThe format is "compiled" in binary format. You can manually. ResxCompile the file. ResourcesFile:

C: \> resgen.exe resource1.resx

In. ResxCompile the file. ResourcesFile, you can useSystem. ResourcesIn the namespaceResourcereaderTo enumerate it:

 

II,Introduction to resource file applications

 

(1)InWindows ApplicationIn:

 

1. Note that Windows Application In Resx Resource files are Form Associated, and Form. CS And Form. Designer. CS And Form. resx The 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 Right-click the project Add new item Select the relevant Resources File, remember Build action Select Embadded Resource (Embedded resources). In this way, resources will be directly embedded into your application after compilation.Program.

 

2.Specific ApplicationCodeExample:

AssemblyAssembly =Assembly. Getexecutingassembly ();

ResourceManagerRm =New ResourceManager("Teststrongname123.form1", Assembly );

This. Textbox1.text = RM. getstring ("First");

 

3.ResourcesFile andResxThe difference between files can also be determined by their storage form of resources. The former will save all resources to the file, while the latter will only save the reference to the resource.

 

(2)InASP. NET web applicationIn:

 

1. The Application of resource files here may be slightly different from the previous method, and Vs2005 Introduces a new usage method, that is, the concept of resource folders, that is, to save global resources and local resources App_globalresources And App_localresources Directory, as long as you put the resource files in these two directories, you can continue to divide the files according to your own classification, this does not affect the project to find the resource files, here, we also want to give a brief introduction to the naming of resource files. Resx File, and the name can be customized. The latter must follow certain naming rules, that is, the corresponding page file name. + " . Resx ".

 

2.Sample Code:

<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 (string ):

< ASP : Literal ID= "Liter_3" Runat= "Server" Text="<% $ resources: globalresource, globalstring1 %> " > Asp : literal >

Literal4.text = (String)Base. Getglobalresourceobject ("Globalresource","Globalstring2");

<3>Obtain images from global resources:

BitmapBm =Null;

Bm = resources.Globalresource. Globalsmallfail;

 

3.Other notes: UseWeb SiteThe site is similar to the application here, so I won't 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.

 

 

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.