Search code examples
c#asp.netlocalizationresxculture

How to pass a string value to resx file?


How to pass a string value as name in order to get its value from resx file. Currently I'm using the above method (see image) to place bilingual data to a Text Box control. Is it possible to pass a string value as Name for resx file and get a value. Please share some code If you have one this before. Thanks in advance


Solution

  • You can create new .resx file and add new value using ResXResourceWriter like

     using (ResXResourceWriter resx = new ResXResourceWriter(@".\Resources.resx"))
     {
         resx.AddResource("StringKey1", "s1");
         resx.AddResource("StringKey2", "s2");
    
     }
    

    Here you find more about working with .resx Files Programmatically

    If you want get some key from exist resource file you can get it using ResourceManager

     ResourceManager myManager = new ResourceManager(typeof(Resource));
     string myString = myManager.GetString("TextBox.Text");
     string myString2 =  Resource.TextBox_Text;