using resource file ...

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. Dirc Khan-Evans
    Replies:
    1
    Views:
    914
    Karl Seguin
    Oct 17, 2005
  2. avishosh
    Replies:
    2
    Views:
    10,622
    avishosh
    Aug 8, 2004
  3. Nesster13

    Using local resource file.

    Nesster13, May 14, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    467
    Nesster13
    May 16, 2007
  4. Heinrich Moser
    Replies:
    1
    Views:
    466
    Heinrich Moser
    Mar 27, 2008
  5. hungrymind
    Replies:
    2
    Views:
    564
    hungrymind
    Mar 15, 2008
Loading...

Share This Page