using resource manager

Discussion in 'ASP .Net' started by =?Utf-8?B?cHJhc2hhbnQga3VtYXIgc3JpdmFzdGF2YQ==?=, Jun 12, 2007.

  1. Hi all,

    I m using asp.net 2.0 version and want to retrieve the particular string
    from resource file dynamically... Following is the my code ... but in this
    every time I get exception that resource key not found... ... might be
    possible as i think that resource file which is being loaded is not fund ...
    plz suggest me how to find the base name of project so that the resource file
    will be loaded .....

    using System;
    using System.Resources;
    using System.Reflection;

    namespace ResourcesDemo
    {
    /// <summary>
    /// Class for resource retrival
    /// </summary>
    public class ResourceText
    {
    private ResourceText()
    {}

    private static ResourceManager _resourceManager;

    //Following method will be called from Global.asax Application_Start

    public static void InitializeResources() //
    {
    string gg = Assembly.GetExecutingAssembly().FullName;
    Assembly assembly = Assembly.GetExecutingAssembly();
    _resourceManager = new ResourceManager("ResourcesDemo.TextRes",
    assembly);
    _resourceManager.IgnoreCase = true;
    }

    public static string GetString(string key)
    {
    string gg = Assembly.GetExecutingAssembly().ToString();
    try
    {
    string s = _resourceManager.GetString( key );
    if( null == s ) throw(new Exception());
    return s;
    }
    catch
    {
    //for resource key not found
    return String.Format("[?:{0}]", key);
    }
    }
    }
    }

    // resource schema...
    ...
    <data name="EMPLOYEE">
    <value>Employee</value>
    </data>
    <data name="DELETE_EMPLOYEE_CONFIRMATION">
    <value>Are you sure you want to delete this employee?
    Doesn't matter it will be deleted any way...</value>
    </data>
    ...
    Reply soon …
    Thanks for giving me your time
     
    =?Utf-8?B?cHJhc2hhbnQga3VtYXIgc3JpdmFzdGF2YQ==?=, Jun 12, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JezB

    Resource Manager Question

    JezB, May 21, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    328
  2. Dirc Khan-Evans
    Replies:
    1
    Views:
    936
    Karl Seguin
    Oct 17, 2005
  3. Replies:
    0
    Views:
    534
  4. padma
    Replies:
    0
    Views:
    377
    padma
    Oct 3, 2007
  5. Metalone
    Replies:
    0
    Views:
    366
    Metalone
    Jan 6, 2010
Loading...

Share This Page