最后,大家来看一下最负责的一个页面,这个页面的作用就是用来建立新的xml数据。
manage.aspx
1<p>```
2@ Import Namespace="System.Xml.Xsl"
1@ Import Namespace="System.Xml"
1@ Assembly Name="System.Xml"
1@ Import Namespace="System.IO"
1@ Page Language="C#" Debug="true" codepage="936"
1@ Import Namespace="System"
2``` </p>
1<p><html>
2<head>
3<script language="C#" runat="server"> </P><P>public void Button1_Click(object sender, System.EventArgs e)
4{
5//判断文件是否存在
6if(File.Exists(Server.MapPath(TextBox1.Text +".xml")))
7{
8Response.Write("文件名已经存在,请重选文件名。");
9Response.End() ; </P><P>}
10else
11{ </P><P>XmlNode currNode;
12XmlDocument xmldoc = new XmlDocument();
13xmldoc.Load(Server.MapPath("contents.xml")); </P><P>string InsStr="<topic><title>"+TextBox2.Text+"</title><href>main.aspx?name="+TextBox1.Text+"</href></topic>";
14XmlDocumentFragment docFrag = xmldoc.CreateDocumentFragment();
15docFrag.InnerXml = InsStr; </P><P>currNode = xmldoc.DocumentElement;
16currNode.InsertAfter(docFrag, currNode.LastChild);
17//save the output to a file
18xmldoc.Save (Server.MapPath("contents.xml")); </P><P>//把TextBox5中的文件换成符合xml格式的内容。
19string xmlfile =TextBox5.Text.Replace("&","&");
20xmlfile = xmlfile.Replace("<","<");
21xmlfile = xmlfile.Replace(">",">");
22xmlfile = xmlfile.Replace( @"""""",""");
23xmlfile = xmlfile.Replace("'","'");
24xmlfile = xmlfile.Replace ("\n","</paragraph><paragraph>");
25//把数据写入新建的xml文件中去。
26XmlDocument doc = new XmlDocument();
27doc.LoadXml ("<?xml version='1.0' encoding='GB2312'?><document><title>"+TextBox2.Text +"</title><abstract>"+TextBox4.Text +"</abstract><author>"+TextBox3.Text +"</author><content><paragraph>"+xmlfile+"</paragraph></content></document>");
28doc.Save (Server.MapPath(TextBox1.Text +".xml"));
29Response.Write("You hava input the article!");
30TextBox1.Text="";
31TextBox2.Text="";
32TextBox3.Text="";
33TextBox4.Text="";
34TextBox5.Text=""; </P><P>} </P><P></P><P>
35//向目录文件中写数据 </P><P>}
36public void Button2_Click(object sender, System.EventArgs e)
37{}
38</script>
39<meta content="Internet Explorer 5.0" name="vs_targetSchema"/>
40<meta content="Microsoft Visual Studio 7.0" name="GENERATOR"/>
41<meta content="C#" name="CODE_LANGUAGE"/>
42</head>
43<body ms_positioning="GridLayout">
44<form runat="server">
45<font face="宋体">
46<asp:label height="28px" id="Label1" runat="server" style="Z-INDEX: 100; LEFT: 230px; POSITION: absolute; TOP: 27px" width="156px">
47asp酷技术资讯网网站内容发布系统
48</asp:label>
49<asp:label height="25px" id="Label2" runat="server" style="Z-INDEX: 101; LEFT: 110px; POSITION: absolute; TOP: 68px" width="65px">
50文件名:
51</asp:label>
52<asp:textbox height="33px" id="TextBox1" runat="server" style="Z-INDEX: 102; LEFT: 255px; POSITION: absolute; TOP: 64px" width="178px">
53</asp:textbox>
54<asp:label height="36px" id="Label3" runat="server" style="Z-INDEX: 103; LEFT: 108px; POSITION: absolute; TOP: 126px" width="86px">
55文章名称:
56</asp:label>
57<asp:textbox height="37px" id="TextBox2" runat="server" style="Z-INDEX: 104; LEFT: 256px; POSITION: absolute; TOP: 114px" width="177px">
58</asp:textbox>
59<asp:label height="31px" id="Label4" runat="server" style="Z-INDEX: 105; LEFT: 114px; POSITION: absolute; TOP: 183px" width="89px">
60作者:
61</asp:label>
62<asp:textbox height="36px" id="TextBox3" runat="server" style="Z-INDEX: 106; LEFT: 256px; POSITION: absolute; TOP: 183px" width="179px">
63</asp:textbox>
64<asp:label height="51px" id="Label5" runat="server" style="Z-INDEX: 107; LEFT: 114px; POSITION: absolute; TOP: 241px" width="81px">
65摘要:
66</asp:label>
67<asp:textbox height="36px" id="TextBox4" runat="server" style="Z-INDEX: 108; LEFT: 256px; POSITION: absolute; TOP: 245px" width="179px">
68</asp:textbox>
69<asp:label height="36px" id="Label6" runat="server" style="Z-INDEX: 109; LEFT: 116px; POSITION: absolute; TOP: 315px" width="78px">
70内容:
71</asp:label>
72<asp:textbox height="95px" id="TextBox5" runat="server" style="Z-INDEX: 110; LEFT: 259px; POSITION: absolute; TOP: 303px" textmode="MultiLine" width="252px">
73</asp:textbox>
74</font> </form></body></html></p>
1<p><input designtimedragdrop="59" id="Button2" name="Button2" onserverclick="Button2_Click" runat="server" style="Z-INDEX: 113; LEFT: 343px; WIDTH: 40px; POSITION: absolute; TOP: 430px; HEIGHT: 24px" type="button" value="重置"/>
2<br/>
3<br/>
4<div id="mess" runat="server">
5</div>
6<br/>
7<input id="Button1" name="Button1" onserverclick="Button1_Click" runat="server" style="Z-INDEX: 112; LEFT: 268px; POSITION: absolute; TOP: 430px" type="button" value="提交"/>
8
9
10
11此程序在.net beta2 build 9148下测试通过。</p>