Wednesday 19 February 2014

read resource file in asp.net

Step:1

Add resource file in your application

step:2

create a page for input text and output result label.

step:3

in code behind add this line

System.Resources.ResourceManager rm = new System.Resources.ResourceManager("Yourresourcefilenamespace.resourcefilename(without extention.resx)", this.GetType().Assembly);
        It cerates reslult set      
                var entry =
                    rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                      .OfType<System.Collections.DictionaryEntry>().Where(e => e.Key.ToString() == "input text").Select(v=>v.Value);
      for single row
 var entry =
                    rm.GetResourceSet(System.Threading.Thread.CurrentThread.CurrentCulture, true, true)
                      .OfType<System.Collections.DictionaryEntry>().FirstOrDefault(e => e.Key.ToString() == "your text");
                     

                var key = entry.Value.ToString();

No comments:

Post a Comment