Modifying App_GlobalResources

To modify the resources file programmatically using C# there are several techniques one of the technique is using XML.

Basically the XML format of a resource file will be like:

<data name=”Language” xml:space=”preserve”>
<data>name=”Language_Name” xml:space=”preserve”>
data name=”Welcome” xml:space=”preserve”>

Taking this part of the resource file and do editing. To read a resource file we need ResXResourceReader Class. To add this System.Windows.Forms assembly of this class, we add a code part in web.config file.
<assemblies />
     <add assembly=”System.Windows.Forms,
    Version=, Culture=neutral,
    PublicKeyToken=B77A5C561934E089″ />
</assemblies />

To read the resource file keys

  string filename = Request.PhysicalApplicationPath + App_GlobalResources\\resource.resx” + 

            Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            ResXResourceReader RrX = new ResXResourceReader(stream);
            IDictionaryEnumerator RrEn = RrX.GetEnumerator();
            SortedList slist = new SortedList();
            while (RrEn.MoveNext())
                slist.Add(RrEn.Key, RrEn.Value);

Update the resource file

filename = Request.PhysicalApplicationPath + App_GlobalResources\\” + filename;
        XmlDocument xmlDoc = new XmlDocument();
        XmlNodeList nlist = xmlDoc.GetElementsByTagName(“
        XmlNode childnode = nlist.Item(id);
xml:space].Value = “default;              
        XmlNode lastnode = childnode.SelectSingleNode(“
        lastnode.InnerText = txtResourceValue.Text;


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s