What's Here?
- Members: 118,477
- Replies: 434,464
- Topics: 67,154
- Snippets: 2,407
- Tutorials: 638
- Total Online: 926
- Members: 51
- Guests: 875
Who's Online?
|
Welcome to Dream.In.Code |
|
Getting C# Help is Easy!
Join 118,477 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 926 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
|
This is a snippet you can use to read a certain value from a resource file you have in your application (.resx extension)
|
Submitted By: PsychoCoder
|
|
Rating:

|
|
Views: 11,057 |
Language: C#
|
|
Last Modified: January 22, 2008 |
|
Instructions: Pass the method the name of the file you want to read from, and the key you want the value for and it returns the value |
Snippet
//Namespace reference
using System;
using System.Resources;
#region ReadResourceFile
/// <summary>
/// method for reading a value from a resource file
/// (.resx file)
/// </summary>
/// <param name="file">file to read from</param>
/// <param name="key">key to get the value for</param>
/// <returns>a string value</returns>
public string ReadResourceValue(string file, string key)
{
//value for our return value
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);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
resourceValue = string.Empty;
}
return resourceValue;
}
#endregion
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|