Wednesday, August 26, 2009

Read,Write,Edit Resource File Asp.Net C#

//READ RESOURCE

ResXResourceReader reader = new ResXResourceReader(Server.MapPath("~/App_GlobalResources/test.resx"));

IDictionaryEnumerator ide = reader.GetEnumerator();

int i = 0;

//COUNTING FOR THE RESOURCE KEYS

while (ide.MoveNext())

{

i++;

}

//ASSIGN THE DICTIONARY ENTRY ARRAY FOR STORING KEYS

DictionaryEntry[] de = new DictionaryEntry[i];

i = 0;

//RESET DICTIONARY TO INITIAL POSITION

ide.Reset();

while (ide.MoveNext())

{

de[i] = ide.Entry;

Response.Write(ide.Key + " - " + ide.Value);

}

reader.Close();

//WRITE RESOURCE

ResXResourceWriter writer = new ResXResourceWriter(Server.MapPath("~/App_GlobalResources/test.resx"));

foreach (DictionaryEntry del in de)

{

//YOUR CODE HERE IF YOU WANT TO CHANGE VALUES

writer.AddResource(del.Key.ToString(), del.Value.ToString() + "*");

}

//SAVE CHANGES

writer.Generate();

//CLOSE RESOURCE FILE

writer.Close();

//DESPOSE RESOURCE

writer.Dispose();

No comments:

Post a Comment