-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddExpression.aspx.cs
50 lines (43 loc) · 1.68 KB
/
AddExpression.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using AjaxPro;
using System.Xml;
using System.IO;
public partial class AddExpression : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Utility.RegisterTypeForAjax(typeof(AddExpression));
if (!IsPostBack)
{
}
}
[AjaxMethod]
public string Post(string title, string description, string exp, string match, string unmatch, string author)
{
XmlDocument doc = new XmlDocument(); ;
string xmlfile = Server.MapPath("/Data/useful.xml");
if (!File.Exists(xmlfile))
{
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", "yes"));
doc.AppendChild(doc.CreateElement("regs"));
}
else
{
doc.Load(xmlfile);
}
XmlElement e = doc.CreateElement("reg");
e.Attributes.Append(doc.CreateAttribute("title")).Value = title;
e.Attributes.Append(doc.CreateAttribute("description")).Value = description;
e.Attributes.Append(doc.CreateAttribute("match")).Value = match;
e.Attributes.Append(doc.CreateAttribute("unmatch")).Value = unmatch;
e.Attributes.Append(doc.CreateAttribute("author")).Value = author;
e.Attributes.Append(doc.CreateAttribute("date")).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
e.Attributes.Append(doc.CreateAttribute("exp")).Value = exp;
if (doc.DocumentElement.ChildNodes.Count > 0)
doc.DocumentElement.InsertBefore(e, doc.DocumentElement.ChildNodes[0]);
else
doc.DocumentElement.AppendChild(e);
doc.Save(xmlfile);
return "0";
}
}