There are two types of resource files: Embedded resource files and external resource files. The first type of resource file is relatively simple to use. You can simply select and add a project to select a resource file, which is also very simple to call.
Because the first type of resource file has already been embedded with DLL, it may be troublesome to modify it, so I personally prefer the second type. This method creates a resx, for example, AAA. resx, and create a Chinese version AAA. zh-cn.resx, then put these resx into the app_globalresources folder, use httpcontext for specific use. getglobalresourceobject ("AAA", key, culture) to get the value. You can directly use the text editor to modify the resx file, or drag vs to edit the file. Note that any file changes in this folder will cause the session to be cleared, which is the same as modifying web. config.
Httpcontext also has a getlocalresourceobject method, which is mainly for page-level resource files.
In the moss site, the app_globalresources folder is created when the application is created, and the files in the app_globalresources folder are: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ config \ resources "is copied, and all files are copied only when an application is created,
Therefore, during deployment, you should not only copy our files to the MOSS system folder, but also paste them into the corresponding folder of our site.
App_globalresources folderThe resource file in is the global resource of the application, so it can be referenced from any page.
<Asp: labelrunat = "server" text = "<$ Resources: Resxfile, myresname> "/>
App_localresources folderA subdirectory located in a folder that contains some ASP. NET pages. This folder can be filled with the. resx file named in the top-level directory in the directory structure. Assume that the parent folder contains test. aspx, you can find some available resource files in the app_localresources folder as follows: test. aspx. resx, test. aspx. it. resx and test. aspx. fr. resx. Obviously, the resources stored in the above files only have an impact on the test. ASPX page, so they can only be seen on the linked page (they can be used ).
How can I access a page's unique resources? For programming access, you can use the following code:
Httpcontext. getlocalresourceobject ("/proaspnet20/respage. aspx ",
"Pageresource1.title ")
The third parameter indicates the virtual path of the page, and the third parameter indicates the Resource Name. For declarative access, useMeta: resourcekeyAttribute. For example,
<Asp: buttonrunat = "server" meta: resourcekey = "buttonresource1"/>
This statement associates a unique resource key with a specific button instance. Partial file. resx contains entries in the prefix. Name format, where prefix is the resource key, and name is the property name on the bound control. To assign the button a localized title (Text attribute), you only need to create a buttonresource1.text entry in the resource file.
The resource files in local and global resource folders are compiled to create classes for the affiliated Assembly. The final result is that the developer creates the. resx file and tests the page. The ASP. NET compilation mechanism will complete other work.
There are two types of source files (resources) in the as.p.net program: Global Resource and localresource)
Let's test a test1.aspx page with only one label lblhello.
1. Use globalresource
Add globalresource. Add the globalresource folder and add the resource file below, such as AAA. resx, and add the string "strhello", "hello ". Add an AAA. en-us.resx, and add the string "strhello", "hello ".
Read globalresource. You can use httpcontext. getglobalresourceobject ("AAA", "strhello ");
System. Globalization. cultureinfo culture = new system. Globalization. cultureinfo ("ZH-CN"); // replace it with "En-us" in English"
Thread. currentthread. currentuiculture = culture; // set the current language Region
Object OBJ = httpcontext. getglobalresourceobject ("AAA", "strhello ");
If (OBJ! = NULL)
{
Lblhello. Text = obj. tostring ();
}
// Lblhello. Text = resources. AAA. strhello; // You can also read
. Use localresource
Add localresource. First add an app_localresources folder, and then add a folder with the same name as the page. resx file. For example, if the page is "test1.aspx", create a test1.aspx file under the app_localresources folder. resx, which adds a record "strhello", "hello ". Test1.aspx. en-us.resx add record "strhello", "hello ".
Read localresource:
System. Globalization. cultureinfo culture = new system. Globalization. cultureinfo ("ZH-CN"); // replace it with "En-us" in English"
Thread. currentthread. currentuiculture = culture; // set the current language Region
Object OBJ = httpcontext. getlocalresourceobject ("~ /Test1.aspx "," strhello ");
// Object OBJ = getlocalresourceobject ("strhello"); // You can also directly read
If (OBJ! = NULL)
{
Lblhello. Text = obj. tostring ();
}