Harry89pl
Harry89pl

Reputation: 2435

method to read resource file

what i'm trying to do is to write a method in c# codebehind to read text based on key. For now i whant to do this for only one language that's why i don't need to use System.Globalization.CultureInfo

private ResourceManager rm;
private ResourceReader rr;
public string GetCurrentLanguage(string key)
{ 
    rm = new ResourceManager("~/App_GlobalResources/textFile", System.Reflection.Assembly.GetExecutingAssembly());
    string result = rm.GetString(key).ToString();
    return result;
}

but it doesn't work :( when i write something like litWelcome.Text = GetCurrentLanguage("Welcome"); it's returns error.

anyone have idea what's i'm doing wrong ?

Thanks for advance:)

Edited

ok i get it on my own this is a solution for my problem:

public string GetCurrentLanguage(string key)
{

    string result = Resources.textFile.ResourceManager.GetString(key).ToString();
    return result;
}

Thanks all for help:)

Upvotes: 0

Views: 2626

Answers (3)

Boomer
Boomer

Reputation: 1478

try :

GetGlobalResourceObject for global resources.

GetLocalResourceObject for local resources.

EX:

Button1.Text = GetLocalResourceObject("Button1.Text").ToString();
Image1.ImageUrl = CType(GetGlobalResourceObject("WebResourcesGlobal","LogoUrl"), String)

for more info check http://msdn.microsoft.com/en-us/library/ms227982.aspx

Upvotes: 0

Matt M
Matt M

Reputation: 3779

Is this line correct?

 rm = new ResourceManager("~/App_GlobalResources\textFile"

Your edited comment shows:

file is in ~\App_GlobalResources\textFile.resx

Your slashes aren't consistent. Is this a typo in your post, or your code?

Upvotes: 0

neeKo
neeKo

Reputation: 4280

Might you be looking for Using Resources for Localization?

I know this isn't a direct answer to your question, but maybe it is the solution you are looking for. This link will give you information on how to use built-in support for localization of your web site in ASP.NET.

Upvotes: 1

Related Questions