读取资源文件的方法
我想做的是在 C# 代码隐藏中编写一个方法来根据键读取文本。 现在我只想对一种语言执行此操作,这就是为什么我不需要使用 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;
}
但它不起作用:( 当我写类似 litWelcome.Text = GetCurrentLanguage("Welcome");
的内容时,它会返回错误。
有人知道我做错了什么吗?
感谢您的提前:)
编辑
好的,我自己得到它,这是我的问题的解决方案:
public string GetCurrentLanguage(string key)
{
string result = Resources.textFile.ResourceManager.GetString(key).ToString();
return result;
}
感谢大家的帮助:)
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:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能正在寻找 使用资源进行本地化?
我知道这不是您问题的直接答案,但也许这是您正在寻找的解决方案。此链接将为您提供有关如何使用 ASP.NET 中的网站本地化内置支持的信息。
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.
这条线正确吗?
您编辑的评论显示:
file is in ~\App_GlobalResources\textFile.resx
您的斜杠不一致。这是您的帖子或代码中的拼写错误吗?
Is this line correct?
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?
尝试:
GetGlobalResourceObject获取全局资源。
GetLocalResourceObject 用于本地资源。
EX:
有关详细信息,请检查 http://msdn.microsoft.com/en-us /library/ms227982.aspx
try :
GetGlobalResourceObject for global resources.
GetLocalResourceObject for local resources.
EX:
for more info check http://msdn.microsoft.com/en-us/library/ms227982.aspx