Partager via


Retrieving Resources in .Resources Files 

If your application does not deploy resources in satellite assemblies, you can access .resources files directly. Use the ResourceManager.CreateFileBasedResourceManager method to specify a directory containing loose .resources files. With this approach, it is not necessary to store all the resource files in separate subdirectories, because you will give the resource files different names based upon the cultures they represent. It is good practice, however, to place all the resources for an application in a single subdirectory of the main application directory. The following illustration shows where resource files should be located in the directory structure.


Application directory containing .resources files

Main directory for your application

After you have created your resources and placed them in the appropriate directory, create a ResourceManager to use the resources. The following example creates a ResourceManager. The first parameter specifies the resource file baseName. The second parameter specifies the location of the resources. The third parameter specifies the ResourceSet implementation to use. If the third parameter is null (C#) or Nothing (Visual Basic), the default runtime ResourceSet is used.

Dim rm As ResourceManager
rm = ResourceManager.CreateFileBasedResourceManager("strings",".",Nothing)
ResourceManager rm =
ResourceManager.CreateFileBasedResourceManager("strings",".",null);
NoteNote

You should not deploy ASP.NET applications using loose .resources files. This can cause locking issues and breaks XCOPY deployment. It is strongly recommended that you deploy ASP.NET resources in satellite assemblies. For more information, see Resources in ASP.NET Applications.

See Also

Reference

ResourceManager Class

Concepts

Resources in Applications
Packaging and Deploying Resources
Retrieving Resources in Satellite Assemblies