The XML reads the information and displays

Source: Internet
Author: User

This kind of life is called Message.cs.

Namespace common{public class Message {//<summary>///Information ID//</summary> private string Messagecode = String. Empty; public string Messagecode {get {return messagecode;} }///<summary>//Information description///</summary> private String messagedata = String. Empty; public string MessageData {get {return messagedata;} The public void Setmessagedata (string value) {messagedata = value; The public Message (string Mc,int x) {this.messagedata = MC; }///<summary>///constructor///</summary>//<param name= "MC" > Information number </param& Gt Public Message (String mc) {This.messagecode = MC; using (System.Data.DataSet ds = Xmlhelp.convertxmlfiletodataset ( system.configuration.configurationmanager.appsettings["MessagepatH "])) {if (ds. TABLES[0]! = null) {for (int i = 0; I < ds. Tables[0]. Rows.Count; i++) {if (ds. Tables[0]. rows[i]["Code"]. ToString () = = mc) {This.messagedata = ds. Tables[0]. rows[i]["Content"]. ToString (); Break } } } } } }}

The following class name is called: XMLHelp.cs

are placed in the Dal file and modify the namespace yourself

Using system;using system.text;using system.xml;using system.data;using system.io;using System.Web;namespace Common{p Ublic class Xmlhelp {//<summary>//Convert XML file to DataSet///</summary>//<param N Ame= "xmlfile" >xml file path </param>/////<returns>DataSet</returns> public static DataSet Conv            Ertxmlfiletodataset (String xmlfile) {StringReader sreader = null;            XmlTextReader reader = null;                try {XmlDocument XDoc = new XmlDocument ();                try {xdoc.load (xmlfile); } catch (directorynotfoundexception) {xmlfile = Path.Combine (HttpContext .                    Current.Server.MapPath ("~"), xmlfile);                Xdoc.load (xmlfile);                } DataSet Dresult = new DataSet ();                Sreader = new StringReader (xdoc.innerxml);reader = new XmlTextReader (Sreader);                Dresult.readxml (reader);            return dresult;            } catch (Exception ex) {throw ex; finally {if (reader! = null) reader.            Close (); }}///<summary>//Convert DataSet to XML file///</summary>//<param name= "D S "></param>//<param name=" xmlfile "></param> public static void Convertdatasettoxmlfi            Le (DataSet ds, String xmlfile) {MemoryStream stream = null;            XmlTextWriter writer = null;                try {stream = new MemoryStream ();                Load from stream to XmlTextReader writer = new XmlTextWriter (stream, Encoding.unicode);                Write the file using the WriteXml method. Ds.                WRITEXML (writer); int count = (int) stream.                Length; byte[] arr = new Byte[couNT]; Stream.                Seek (0, Seekorigin.begin); Stream.                Read (arr, 0, Count);                Returns the Unicode encoded text unicodeencoding UTF = new unicodeencoding ();                StreamWriter SW = new StreamWriter (xmlfile); Sw.                WriteLine ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>"); Sw. WriteLine (UTF. GetString (arr).                Trim ()); Sw.            Close ();            } catch (System.Exception ex) {throw ex; } finally {if (writer! = null) writer.            Close (); }        }    }}

such as: Background pop-up window:

String id = request["id"];
if (! Function.checkstr (ID, 1))
{
Function.showmsgbox (New Message ("M0008").  MessageData, "baoming.aspx", false); Drop the method, and then given the parameters, execute directly on the OK
}

In the project root directory there is an XML folder, there is a message.xml file, the contents are as follows:

The code in this XML file defines itself, and content is what you want to read, and it's good to match the Code field when needed. It's so simple.

The XML reads the information and displays

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.