You can create a resource file in Visual Web Developer 2005 express edition. You can store strings, images, icons, text files, and other content in the file.. net.
The resource file extension is. resx. In the form software, you can use resxresourcereader to directly read The. resx file. However, in ASP. NET, we cannot do this. We need to use resgen.exe to generate a binary. Resources file using. resx (note the extension), and then use resourcereader to read the file. Note: resxresourcereader and resourcereader.
Create. resx
Creating a. resx file in Visual Web Developer 2005 express edition is very simple. You can select this type of file in the "New File" dialog box. You can also create a file by using resourcewriter.
Generate. Resources
We need to install.. NET Framework. Then, you can find the resgen.exe tool at a location similar to c: \ Program Files \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin. the resx file is compiled. resources file.
Resgen E: \ resource1.resx E: \ resource1.resources
Read. Resources
Use resourcereader.
The namespace of resourcereader is:
System. Resources
Example
Resourcereader reader = new resourcereader (server. mappath ("resource1.resources "));
String resourcetype;
Byte [] resourcedata;
Reader. getresourcedata ("string1", out resourcetype, out resourcedata );
Byte [] arr = new byte [resourcedata. Length-1];
For (INT I = 0; I <arr. length; I ++)
{
Arr [I] = resourcedata [I + 1];
}
LB. Text = encoding. utf8.getstring (ARR );
System. Collections. idictionaryenumerator en = reader. getenumerator ();
While (EN. movenext ())
{
LB. Text + = "<br/>" + en. value. tostring ();
}
Reader. Close ();
The sample code contains four sections. The first section is the creation of resourcereader, and the fourth section is the release of resourcereader resources. For details about how to release resources by close, see the differences and usage of finalize (destructor), dispose, and close.
The second and third sections are two read methods.
The first parameter of getresourcedata is resourcename case sensitive. encoding. utf8.getstring converts the byte array into a string. I don't know why the byte read from getresourcedata always has one more byte, so I used array conversion to remove the previous byte.
In the third section, use getenumerator to retrieve all resources and display them separately.