从资源文件读取数据 [英] Reading data from a resource file

查看:93
本文介绍了从资源文件读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从资源文件中读取特定密钥的数据

How to read data for a perticular key, from a resource file

推荐答案

我建​​议购买一本ASP.NET书籍并阅读,或使用google.如果您要上课,那么肯定有一本教科书.您可能无法上班,因此,如果您正在自学,请购买一些书籍,以便学习或只是学习使用Google.在遇到特定问题时问问题,而不是在没有基础研究能力时问问题.
I recommend buying an ASP.NET book and reading it, or using google. If you''re taking a class, surely it has a textbook. You can''t POSSIBLY be at work, so if you''re teaching yourself, buy some books so you can learn, or just learn to use google. Ask questions when you have specific issues, not when you''re incapable of basic research.


以下是iam在我的Web应用程序中使用的代码.但它表明

<< i> b> ex.Message =在磁盘上找不到适合于指定区域性(或中性区域性)的任何资源.\ r \ nbaseName:资源locationInfo:& lt; null& gt; fileName:Resource.resources</b></i></u>

请帮我....


字符串resourceValue = string.Empty;
试试
{
//指定您的资源文件名
字符串resourceFile = file;
//获取文件的路径
字符串filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
//创建一个资源管理器以供读取
//resx文件
ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile,filePath,null);
//检索指定键的值
resourceValue = resourceManager.GetString(key.ToString());
}
catch(ex ex例外)
{
Console.WriteLine(ex.Message);
resourceValue = string.Empty;
}
return resourceValue;</pre>
Here is the code that iam using in my web application. But it showing that

<<u>i><b>ex.Message = "Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.\r\nbaseName: Resource locationInfo: &lt;null&gt; fileName: Resource.resources"</b></i></u>

plz do help me....


string resourceValue = string.Empty;
try
{
// specify your resource file name
string resourceFile = file;
// get the path of your file
string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
// create a resource manager for reading from
//the resx file
ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
// retrieve the value of the specified key
resourceValue = resourceManager.GetString(key.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
resourceValue = string.Empty;
}
return resourceValue;</pre>


这篇关于从资源文件读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆