How C # uses programs to add queries and edit resx files (resource files)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.