`
wangdeshui
  • 浏览: 256830 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

[Tips]:Read value from Resource file in C#

阅读更多
   1: //Namespace reference
   2: using System;
   3: using System.Resources;
   4:  
   5:  
   6: #region ReadResourceFile
   7: /// <summary>
   8: /// method for reading a value from a resource file
   9: /// (.resx file)
  10: /// </summary>
  11: /// <param name="file">file to read from</param>
  12: /// <param name="key">key to get the value for</param>
  13: /// <returns>a string value</returns>
  14: public string ReadResourceValue(string file, string key)
  15: {
  16:     //value for our return value
  17:     string resourceValue = string.Empty;
  18:     try
  19:     {
  20:         // specify your resource file name 
  21:         string resourceFile = file;
  22:         // get the path of your file
  23:         string filePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
  24:         // create a resource manager for reading from
  25:         //the resx file
  26:         ResourceManager resourceManager = ResourceManager.CreateFileBasedResourceManager(resourceFile, filePath, null);
  27:         // retrieve the value of the specified key
  28:         resourceValue = resourceManager.GetString(key);
  29:     }
  30:     catch (Exception ex)
  31:     {
  32:         Console.WriteLine(ex.Message);
  33:         resourceValue = string.Empty;
  34:     }
  35:     return resourceValue;
  36: }
  37: #endregion
分享到:
评论

相关推荐

    Beginning ASP.NET 2.0 in C# 2005:From Novice to Professional

    "Beginning ASP.NET 2.0 in C# 2005: From Novice to Professional steers you through the maze of ASP.NET web programming concepts. You will learn language and theory simultaneously, mastering the core ...

    50 Tips and Tricks for MongoDB Developers

    Application Design Tips: What to keep in mind when designing your schema Implementation Tips: Programming applications against MongoDB Optimization Tips: Speeding up your applications Data Safety Tips...

    WPF Tips: Uncheckable radio buttons

    《WPF Tips: Uncheckable radio buttons》一文的可执行程序示例与源代码。 原文网址:http://blog.csdn.net/xinyaping/article/details/7887663 作者:辛亚平 工程文件为Visual Studio 2008 with .Net Framework 3.5...

    Power Tips: Calculate an R-C Snubber in Seven Steps

    内容概要:本技术文章介绍了如何在七个步骤内选择适当的 RC 阻尼器值来消除转换器电路中的振铃现象。它解释了振铃的原因并提供了一个简易方法计算所需的电容器 (Csnub) 和电阻器 (Rsnub) 大小来减少过高的电压峰以及...

    C# 5.0 Programmer’s Reference

    Beginning through intermediate-level programmers will benefit from the accessible style of C# 5.0 Programmer’s Reference and will have access to its comprehensive range of more advanced topics....

    Professional Refactoring in C# & ASP.NET

    In this first book to provide a hands-on approach to refactoring in C# and ASP.NET, you’ll discover to apply refactoring techniques to manage and modify your code. Plus, you’ll learn how to build a...

    Pro LINQ: Language Integrated Query in C# 2010 (含源码)

    Pro LINQ: Language Integrated Query in C# 2010 is all about code. Literally, this book starts with code and ends with code. Most books show the simplest examples of how to use a method, but they so ...

    TIPS:路径重要性的轨迹推断的简化方法

    尖端通过伪时比较对单细胞RNAseq数据进行功能评估的途径意义的轨迹推断直接从R和GitHub启动TIPS步骤1:安装R和RStudio 在运行TIPS之前,您将需要安装R和RStudio。请检查CRAN( )以安装R。请检查以获取有关R的信息。...

    TMS Pack for FireMonkey2.3.0.1

    Fixed : Issue with scrolling and selecting value in iOS in TTMSFMXSpinner Fixed : Issue with escape key not cancelling edit mode in TTMSFMXGrid v1.6.0.1 Fixed : Issue with double databinding ...

    Effective C# 2ed (Covers C# 4.0)

    Drawing on his unsurpassed C# experience, Wagner addresses everything from types to resource management to dynamic typing to multicore support in the C# language and the .NET framework. Along the way...

    Ubuntu Tips: APE转Flac

    使用方法:下载后删除文件名最后的\".zip\"即可得到deb包文件。 博文链接:https://lgn21st.iteye.com/blog/207177

    [C#] Effective C# 改善C#程序的50种方法 第1版 (英文版)

    Drawing on his unsurpassed C# experience, Wagner addresses everything from value types to assemblies, exceptions to reflection. Along the way, he shows exactly how to avoid dozens of common C# ...

    Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional (1)

    Within these pages, you’ll find tips for “best practices” and comprehensive discussions of key database and XML principles you need to know in order to be effective with ASP.NET. The book also ...

    Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional (3)

    Within these pages, you’ll find tips for “best practices” and comprehensive discussions of key database and XML principles you need to know in order to be effective with ASP.NET. The book also ...

    Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional (2)

    Within these pages, you’ll find tips for “best practices” and comprehensive discussions of key database and XML principles you need to know in order to be effective with ASP.NET. The book also ...

Global site tag (gtag.js) - Google Analytics