How to retrieve a value from Resource File using C#
Author: Mahesh ChandraMouli
Rating:
Rate this Resource
Visits: 27451
Discuss in Newsgroups
This sample describes how to retrieve the values which are stored in Resource file and also explains how can you can convert a text file into an resource file.
1. The below example describes how to retrieve a value from a resource file.
Code Snippet
using System;
using System.Resources;
// specify your resource file name
string m_sResourceFileName = "filename";
// it returns your path where the resource file is stored
string v_sPath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
// creates a resource manager
ResourceManager v_ResMan =
ResourceManager.CreateFileBasedResourceManager(m_sResourceFileName,v_sPath,null);
// it retrieves the connection string value
string m_connectionstring = v_ResMan.GetString("connectionstring");
2. The below shows how can we convert a text file into an resource file.
Resource File Generator (Resgen.exe)
The Resource File Generator converts .txt files and .resx (XML-based resource format) files to common language runtime
binary .resources files that can be embedded in a runtime binary executable or compiled into satellite assemblies. Resgen.exe
performs the following conversions:
Converts .txt files to .resources or .resx files.
In the command prompt>>>resgen filename.txt
when you execute this statement in the command prompt the textfile will be converted to resourcefile.
Visit my guru profile
Visitor Comments
Be the first to rate this code sample!