Technically, yes it is possible but there are some pitfalls. First, let me show you an example. Suppose my App_GlobalResources
folder looks like so:
/App_GlobalResources
/Test
TestSubresource.resx
TestResource.resx
Each resource file has a single entry called "TestString". I added each resource file using the Visual Studio menu so it created a class for me. By default, all classes added to the App_GlobalResources
folder will have the same namespace of Resource
. So, 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. Once I do that, I can do the following:
var rootResource = Resources.TestResource.TestString;
var subResource = Resources.Test.TestResource.TestString;
I can also reference them using GetGlobalResourceObject
:
var rootResource = GetGlobalResourceObject( "TestResource", "TestString" );
var subResource1 = GetGlobalResourceObject( "TestSubresource", "TestString" );
Notice that I still use the "TestSubresource" as the means to reference the resources in that file even though it is in a subfolder. Now, one of the catches, is that all the files must be unique across all folders in App_GlobalResources
or your project will throw a runtime error. If I add a resource named "TestResource.resx" to /Test, it will throw the following runtime error:
The resource file '/App_GlobalResources/TestResource.resx' cannot be used, as 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 odds of getting a runtime error because of two identically named resource files in different parts of the App_GlobalResources
folder structure which is allowed by the file system but not by .NET.