简体   繁体   中英

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?

您需要先调用Generate方法,然后再调用Close来写出您的资源。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM