Resource files (files ending in resx) are unavoidable in C # projects
Methods to read and add:
To refer to namespaces first in the project
Using System.Resources;
string [email protected] ". \resources1.resx";
Writes a string to the resource file
using (ResXResourceWriter resx=new resxresourcewriter (Respath))
{
ResX. AddResource ("String1", "the string you want to store");
}
Read the value of a resource file
using (Resxresourceset rest=new resxresourceset (Respath))
{
String str=rest. GetString ("String1");
}
Here is the value of the edit resource file, the resource file is stored in an XML file format, and we edit it as an XML file
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (Respath);
XmlNodeList xnlist = xmldoc.getelementsbytagname ("data");//This data is fixed
foreach (XmlNode node in xnlist)
{
if (node. Attributes = null)
{
if (node. attributes["Xml:space"]. Value = = "preserve")//This preserve is also fixed
{
if (node. attributes["Name"]. value== "String1")//string1 is the one you want to edit
{
Node. InnerText = "I succeeded";//assign it to him OK.
}
}
}
}
Xmldoc.save (Respath);//Don't Forget to save
The merit of doing it! Lol this is not really difficult as long as you know the format of his storage can go to edit it
How C # uses programs to add queries and edit resx files (resource files)