Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   using resource manager (http://www.velocityreviews.com/forums/t513936-using-resource-manager.html)

=?Utf-8?B?cHJhc2hhbnQga3VtYXIgc3JpdmFzdGF2YQ==?= 06-12-2007 07:03 AM

using resource manager
 
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



All times are GMT. The time now is 12:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.