How to read values from RESX file in ASP.NET using ResXResourceReader

Posted on Microsoft .NET Support Team See other posts from Microsoft .NET Support Team
Published on Tue, 29 Jun 2010 13:51:00 +0000 Indexed on 2010/12/06 16:58 UTC
Read the original article Hit count: 453

Here is the method which returns the value for a particular key in a given resource file.

Below method assumes resourceFileName is the resource filename and key is the string for which the value has to be retrieved.

public static string ReadValueFromResourceFile(String resourceFileName, String key)
   {
       String _value = String.Empty;
       ResXResourceReader _resxReader = new ResXResourceReader(
           String.Format("{0}{1}\\{2}",System.AppDomain.CurrentDomain.BaseDirectory.ToString(), StringConstants.ResourceFolderName , resourceFileName));
       foreach (DictionaryEntry _item in _resxReader)
       {
           if (_item.Key.Equals(key))
           {
               _value = _item.Value.ToString();
               break;
           }
       }
       return _value;
   }

© Microsoft .NET Support Team or respective owner

Related posts about ASP.NET

Related posts about .NET Tips and Tricks