1

I want to add values to the resources dynamically through codings(C#). My below coding runs without any error but the values are not getting added to the resource file.

protected void Button2_Click(object sender, EventArgs e)
{
    using (ResXResourceWriter resx = new ResXResourceWriter("Resources.resx"))
    {
        resx.AddResource( "joth", "joth");
        resx.Close();
    }
}      
5
  • I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". Commented Apr 14, 2013 at 19:37
  • I think this might be what you are seeking. I hope it helps you ! stackoverflow.com/questions/5686370/… Commented Apr 14, 2013 at 19:45
  • tried everythng but din get anything. what value should be provided within braces ("Resources.resx") is what i used is rite? Commented Apr 14, 2013 at 20:38
  • add save changes because you are added successfully but not saved ,so before close save the changes. Commented Apr 15, 2013 at 5:24
  • how can i code for saving the changes made? Commented Apr 15, 2013 at 18:52

2 Answers 2

1
protected void Button2_Click(object sender, EventArgs e)
{
    using (ResXResourceWriter resx = new ResXResourceWriter("Resources.resx"))
    {   resx.AddResource( "joth", "joth");
        resx.Save();
        resx.Close();
    }
} 
Sign up to request clarification or add additional context in comments.

1 Comment

I got the following error if i use resx.save(); (Error 1 'System.Resources.ResXResourceWriter' does not contain a definition for 'Save' and no extension method 'Save' accepting a first argument of type 'System.Resources.ResXResourceWriter' could be found (are you missing a using directive or an assembly reference?) C:\Users\Jothieshwar\Desktop\jothieshwar\Backup\Project\begin\CS\RDImageGallery_WebRole\login.aspx.cs 113 22 RDImageGallery_WebRole)
0

I tried the above it doesn't seem to work, I looked around and try editing the resx file like a xml file and it worked for me.

<data name="v13" xml:space="preserve">
   <value>Test TEst</value>
</data>

Above is the structure of a single key/value pair in the resx file opened in nodepadd ++

XDocument doc = XDocument.Load(Server.MapPath(@"~\App_GlobalResources\myResource2.resx"));

XElement data = new XElement("data");

XNamespace ns = "xml";
data.Add(new XAttribute("name", "v13"));
data.Add(new XAttribute(XNamespace.Xml + "space", "preserve"));

data.Add(new XElement("value", "Test TEst"));

doc.Element("root").Add(data);
doc.Save(Server.MapPath(@"~\App_GlobalResources\myResource2.resx"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.