Ayohaych
Ayohaych

Reputation: 5189

C# writing to a .resx file

I need to write to my resx file, using user submitted values.

Basically the user inputs a value, and the program has to check the resx file to see if the number exists. If the number doesn't exist, it adds it to the file.

Here is the code I have so far but it doesn't seem to work:

if (!DictOfSyndicates.Contains(syndicateNumberTextBox.Text))
{
    try
    {
        var resxWriter = new ResXResourceWriter(@".\Syndicates.resx");
        resxWriter.AddResource("test", syndicateNumberTextBox.Text);
        resxWriter.Close();
        MessageBox.Show(@"Sydicate "+syndicateNumberTextBox.Text +@" Added Successfully.");

    }
    catch (FileNotFoundException caught)
    {
        MessageBox.Show(@"Source: " + caught.Source + @" Message: " + caught.Message);
    }   
}
else
{
    MessageBox.Show(@"Syndicate already exists");
}

Anybody have any idea what is going wrong?

Upvotes: 0

Views: 685

Answers (1)

user2525965
user2525965

Reputation: 11

You need to call the Generate method before calling Close to write out your resources.

Upvotes: 1

Related Questions