---
title: "Resources in .NET"  
description: "In this article, I’m explaining about resources in .NET"  
author: "priyanka kushwaha"  
published: 2015-02-26  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1616/resources-in-dot-net  
category: ".net"  
tags: ["c#", "asp.net"]  
reading_time: 2 minutes  

---

# Resources in .NET

\

In this [article](https://yourviews.mindstick.com/view/81489/kashmir-now-after-an-year-of-abrogation-of-article-370), I’m explaining about [resources](https://www.mindstick.com/interview/1265/what-are-the-different-types-of-resources-through-which-cold-fusion-can-communicate) in .NET

## What is Resources file?

A resources file is a [XML file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) that contains the string that we want to:

a. [Translate](https://www.mindstick.com/interview/22940/how-to-translate-in-android) into different [language](https://yourviews.mindstick.com/view/81607/hindi-language-in-pakistan-is-getting-killed).

b. Can be updated dynamically so that user themselves can modify values in resources files one the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) is deployed on the server without re-compiling the entire application itself.

c. The [resource file](https://www.mindstick.com/articles/327263/what-is-the-use-of-resource-file-how-to-use-it-on-your-project) contains key/value pairs.

d. Each pair is an individual resources.

e. Key name are not case sensitive.

## Types of resources:

## 1. Local resources

**2. Global resources**

## \
Local resources:

## 1. Local resources:

1. Local resources is specific to a single [web page](https://answers.mindstick.com/qa/92898/how-to-create-a-web-page-using-bootstrap-4) and used for providing version of a web page in different language.

2. Local resources must be stored in App_LocalResources sub folder.

3. Local resources must be named in format <WebPageName>[.language/language and culture etc]

4. Example: Default.aspx.resx- Base resource file.

## 2. Global resources:

1. Global resource can be read from any page or code that is in the application.

2. Global resource must be stored in App_GlobalResources at the root of the application.

**Example:**

1. Create a Default.aspx file. \

```
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DetailForm.aspx.cs" Inherits="ResourceSam.DetailForm"  Culture="auto" UICulture="auto"%> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <link href="css/bootstrap.css" rel="stylesheet" />    <title></title></head><body>    <form id="form1" runat="server">                <table>            <tr><td>Select language</td><td> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">            <asp:ListItem Value="en-us">English</asp:ListItem>            <asp:ListItem Value="hi-in">हिंदी</asp:ListItem>  <asp:ListItem Value="Ur">اردو</asp:ListItem>        </asp:DropDownList><br /></td></tr>            <tr>                <td> <asp:Label ID="lblinformation" runat="server" Text="Personal informatiom" meta:resourceKey="lblinformation"></asp:Label></td>                <td>                          </td>            </tr>            <tr>                <td> <asp:Label ID="lblFirstName" runat="server" Text="First Name"  meta:resourceKey="lblFirstName"></asp:Label></td>                <td>                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></td>            </tr>            <tr>                <td><asp:Label ID="lblLastName" runat="server" Text="Last Name" meta:resourceKey="lblLastName"></asp:Label></td>                <td>                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>            </tr>            <tr>                <td><asp:Label ID="lblAge" runat="server" Text="Age" meta:resourceKey="lblAge"></asp:Label></td>                <td>                    <asp:TextBox ID="txtAge" runat="server"></asp:TextBox></td>            </tr>            <tr>                <td colspan="2">                    <asp:Button ID="btnReg" runat="server" Text="Register" meta:resourceKey="btnReg" /></td>            </tr>        </table>    </form></body></html> 
```

2. Write in Default.cs

```
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Reflection;using System.Resources;using System.Globalization;using System.Threading;namespace ResourceSam{    public partial class DetailForm : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {         }        protected override void InitializeCulture()        {            if (Request.Form["DropDownList1"] != null)            {                UICulture = Request.Form["DropDownList1"];                Culture = Request.Form["DropDownList1"];            }            base.InitializeCulture();        }            }}
```

**3.** Right click on application>> select Add Option>>select Add [ASP.NET](https://www.mindstick.com/articles/155/concept-of-asp-dot-net) Folder>>select>>App_LocalResources>>Right click on App_localResouces>> Select Resource file>>

## 1. DetailForm.aspx.resx for English

## 2. DetailForm.aspx.hi-in.resx for Hindi

**![Resources in .NET](https://www.mindstick.com/mindstickarticle/ee66ffdf-1da3-4c5c-8bce-f36c7d1e23d9/images/0e1930a9-0428-4842-af85-b013149dba4b.png)**

**![Resources in .NET](https://www.mindstick.com/mindstickarticle/ee66ffdf-1da3-4c5c-8bce-f36c7d1e23d9/images/838f56e0-774b-4797-9d5f-ffbe48e796c5.png)**

**Output**

**![Resources in .NET](https://www.mindstick.com/mindstickarticle/ee66ffdf-1da3-4c5c-8bce-f36c7d1e23d9/images/5ba9c7f5-c34b-40b2-be32-68eb8e3abad6.png)**

**![Resources in .NET](https://www.mindstick.com/mindstickarticle/ee66ffdf-1da3-4c5c-8bce-f36c7d1e23d9/images/626a5ed1-a475-4022-9bc4-b7048bbe53b3.png)**

---

Original Source: https://www.mindstick.com/articles/1616/resources-in-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
