locked
Get resource file value programmatically including culture info RRS feed

  • Question

  • User-1246604461 posted

    I want to get a value from my global resource file, but also passing the correct language parameter.

    Normally I retreive values like so: Resources.Glossary.title, but that doesnt give me the opportunity to pass a specific culture.

    I could also do it like so:
    rm.GetString("title", New System.Globalization.CultureInfo("en"))
    But then I have to compile the resource files in my \bin folder and I want to retrieve them from my \App_GlobalResources\glossary.resx files

    Also the GetGlobalResourceObject doesnt allow for passing a language parameter.

    So is there a way to do this?

    Friday, May 20, 2011 3:25 PM

Answers

  • User-276842610 posted

    Hi Peter,

    thanks for your post.

    please try to use Assembly.GetExecutingAssembly() instead of Assembly.Load().

    more details please refer: http://msdn.microsoft.com/en-us/library/yfsz7ac5.aspx

    hope this helps, thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2011 2:25 AM
  • User1489189787 posted

    //For Getting the Resource File

    System.Resources.ResourceManager rsMgr = new System.Resources.ResourceManager("ClassLibraryName.ResourceFileName", System.Reflection.Assembly.GetExecutingAssembly());

    // in Place of ClassLibraryName put ur ProjectName like  systemframework ... and ResourceFileName like glossary //

    //For getting the title string value

    string value = rsMgr.GetString("title") ;

    Let me know if u have any questions...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2011 2:40 AM

All replies

  • User-1696077569 posted

    Add multiple files in \App_GlobalResources folder like \glossary.resx.en for every culture and use rm.GetString("title", New System.Globalization.CultureInfo("en"))

    Friday, May 20, 2011 3:38 PM
  • User-1246604461 posted

    Ok, so I already have that. But what exactly do I need to load into the resource manager in global.asax?

    I tried this:
    Application("RM") = New ResourceManager("Glossary", Assembly.Load("Glossary"))

    Then in default.aspx.vb I do: Shared rm As ResourceManager = HttpContext.Current.Application("RM")

    But with the above I get:
    Could not load file or assembly 'Glossary' or one of its dependencies. The system cannot find the file specified.

    Friday, May 20, 2011 4:17 PM
  • User-1696077569 posted

    try Assembly.LoadFrom with full path of assembly

    Friday, May 20, 2011 4:38 PM
  • User-1246604461 posted

    Sorry, not sure what you mean there. Does that mean I STILL have to compile the resource files?

    Friday, May 20, 2011 4:46 PM
  • User-276842610 posted

    Hi Peter,

    thanks for your post.

    please try to use Assembly.GetExecutingAssembly() instead of Assembly.Load().

    more details please refer: http://msdn.microsoft.com/en-us/library/yfsz7ac5.aspx

    hope this helps, thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2011 2:25 AM
  • User1489189787 posted

    //For Getting the Resource File

    System.Resources.ResourceManager rsMgr = new System.Resources.ResourceManager("ClassLibraryName.ResourceFileName", System.Reflection.Assembly.GetExecutingAssembly());

    // in Place of ClassLibraryName put ur ProjectName like  systemframework ... and ResourceFileName like glossary //

    //For getting the title string value

    string value = rsMgr.GetString("title") ;

    Let me know if u have any questions...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 26, 2011 2:40 AM