using resource file ...

G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top