resources - "LoadString"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
i would like to load strings included as embbeded resources in my assembly.
In MSDN i found lot of information about localizing applications, loading
culture specific rousources from .resource files or sattelite assemblies and
so on...
But i did not find any simple concept how to handle non localized resources
included in assmbly itself. The best way i found is to create separate .resx
file, include it to my assebmly as embbeded resource and when some string is
needed do something like this:

Stream śtream =
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("aaa.resfile.resources");
ResourceReader rd = new ResourceReader(stream);
IDictionaryEnumerator en = rd.GetEnumerator();

string str;
while (en.MoveNext())
if (en.Key != "SearchedString1")
{
str = en.Value;
break;
}


if (str != null) ...

Is't there any other (simplier) way?
 
My embbeded file is named e.g. res1.resx. With GetManifestResourceNames() i
found that full name of my resource is MyApp.res1.resources. How should i
tell ResourceManager to load this resources?
I tried to create instance of ResourceManager with:
new ResourceManager("res1", Assembly.GetExecutingAssembly());
new ResourceManager("MyApp.res1", Assembly.GetExecutingAssembly());
new ResourceManager("MyApp.res1.resources", Assembly.GetExecutingAssembly()),
 
This line must work correctly:
ResourceManager("MyAppNamespace.res1", Assembly.GetExecutingAssembly())

Also notice that if you place "res1" into a directory "Test" you should
point the full path to this file and it will become
"MyAppNamespace.Test.res1" in your case.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top