I load the resources into a hash table, manipulate the hashtable and then write the resource back out.
These methods are from a utility class, they don't use all the usings, but better too many than none ;)
using System.ComponentModel.Design.Serialization;
using System;
using System.CodeDom;
using System.Collections;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Globalization;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Resources;
private Hashtable ReadResource(CultureInfo cultureInfo)
{
//Utilities.MsgBox("ReadResource " + cultureInfo.Name);
IResourceService resourceService = (IResourceService)Site.GetService(typeof(IResourceService));
IResourceReader reader= resourceService.GetResourceReader(cultureInfo);
Hashtable source = new Hashtable();
foreach(DictionaryEntry item in reader)
{
source.Add(item.Key,item.Value);
}
return source;//(Hashtable)savedHashTable[key];
}
public void SynchUpdateResx2(string memberLocalizationItemName,object newValue)
{
Hashtable source = ReadResource(DesignTimeCulture);
if(memberLocalizationItemName.Length!=0
&&
!source.ContainsKey(memberLocalizationItemName))
{
source.Add(memberLocalizationItemName,newValue);
}
IResourceWriter writer = Util.GetResourceWriter(DesignTimeCulture);
foreach(DictionaryEntry item in source)
{
if(item.Key.ToString() == memberLocalizationItemName)//TypedComponent.TextLocalizationItemName)
{
writer.AddResource(item.Key.ToString(),newValue);
}
else
{
writer.AddResource(item.Key.ToString(),item.Value);
}
}
writer.Close();
}