How To Read Data From RESX file C#

Introduction :

In this blog, we will discuss how to access the data from the RESX file.

What is RESX File?

Resource file hold the values in XML formate

This value is pair of objects and strings for a program.

Implementation :

Step 1: Add New Item

Step 2:Now You Can See Your Resouce File In Solution Explorer.

Step 3: Now We Are Going To Add Values In Resource File As Shown In Below Image.

Step 4:Now We Are Going To Access The Values Of the Resource File from the Code Behind the File.

First We Have To Import NameSpace.

using System.Reflection;
using System.Resources;
using System.Globalization;

Once It Is Done We Can Access Using ResourceManager Class.

We Have To Provide the Current Assembly Name. We can Use Assembly.GetExecutingAssembly().

Method :

GetString(“KEY”,CultureInfo.CurrentCulture)

This Method Get Value-Based On Key Which Is Provided In Resouce File.

For Example :

ResourceManager rm = new ResourceManager("RESXExample.Resource1",
Assembly.GetExecutingAssembly());
String strWebsite = rm.GetString("Message1",CultureInfo.CurrentCulture);
String strName = rm.GetString("Name");
Console.WriteLine(strName);

So As per The Resouce File OutPut Will Display.

Submit a Comment

Your email address will not be published.

Subscribe

Select Categories