Technically, yes, it is possible, but there are some pitfalls. First, let me show you an example. Suppose my App_GlobalResources folder looks like this:
/App_GlobalResources /Test TestSubresource.resx TestResource.resx
Each resource file has one entry called "TestString". I added each resource file using the Visual Studio menu to create a class for me. By default, all classes added to the App_GlobalResources folder will have the same Resource namespace. Therefore, if I want to use the class generator, and I want Test in the namespace, I need to go into the TestSubresource.Designer.cs file and manually change the namespace. As soon as I do this, I can do the following:
var rootResource = Resources.TestResource.TestString; var subResource = Resources.Test.TestSubResource.TestString;
I can also reference them using GetGlobalResourceObject :
var rootResource = GetGlobalResourceObject( "TestResource", "TestString" ); var subResource1 = GetGlobalResourceObject( "TestSubresource", "TestString" );
Note that I still use "TestSubresource" as a means to reference the resources in this file, even if it is in a subfolder. Now one of the catch is that all files must be unique in all folders in App_GlobalResources or your project will cause a runtime error. If I add a resource called "TestResource.resx" to / Test, it will output the following runtime error:
The resource file '/App_GlobalResources/TestResource.resx' cannot be used because it conflicts with another file with the same name.).
This is true even if I change the namespace on the new resource.
So, in conclusion, yes, it is possible, but you increase the likelihood of a runtime error due to two identically named resource files in different parts of the App_GlobalResources folder App_GlobalResources , which are allowed by the file system but not .NET.
Thomas
source share