欢迎光临
我们一直在努力

用asp.net和xml做的新闻更新系统(3)-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

最后,大家来看一下最负责的一个页面,这个页面的作用就是用来建立新的xml数据。
manage.aspx </p><p><%@ import namespace=”system.xml.xsl” %>
<%@ import namespace=”system.xml” %>
<%@ assembly name=”system.xml” %>
<%@ import namespace=”system.io” %>
<%@ page language=”c#” debug=”true” codepage=”936″%>
<%@ import namespace=”system”%> </p><p><html>
<head>
<script language=”c#” runat=”server”> </p><p>public void button1_click(object sender, system.eventargs e)
{
//判断文件是否存在
if(file.exists(server.mappath(textbox1.text +”.xml”)))
{
response.write(“文件名已经存在,请重选文件名。”);
response.end() ; </p><p>}
else
{ </p><p>xmlnode currnode;
xmldocument xmldoc = new xmldocument();
xmldoc.load(server.mappath(“contents.xml”)); </p><p>string insstr=”<topic><title>”+textbox2.text+”</title><href>main.aspx?name=”+textbox1.text+”</href></topic>”;
xmldocumentfragment docfrag = xmldoc.createdocumentfragment();
docfrag.innerxml = insstr; </p><p>currnode = xmldoc.documentelement;
currnode.insertafter(docfrag, currnode.lastchild);
//save the output to a file
xmldoc.save (server.mappath(“contents.xml”)); </p><p>//把textbox5中的文件换成符合xml格式的内容。
string xmlfile =textbox5.text.replace(“&”,”&”);
xmlfile = xmlfile.replace(“<“,”<“);
xmlfile = xmlfile.replace(“>”,”>”);
xmlfile = xmlfile.replace( @””””””,”””);
xmlfile = xmlfile.replace(“”,”&apos;”);
xmlfile = xmlfile.replace (“\n”,”</paragraph><paragraph>”);
//把数据写入新建的xml文件中去。
xmldocument doc = new xmldocument();
doc.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>”);
doc.save (server.mappath(textbox1.text +”.xml”));
response.write(“you hava input the article!”);
textbox1.text=””;
textbox2.text=””;
textbox3.text=””;
textbox4.text=””;
textbox5.text=””; </p><p>} </p><p></p><p>
//向目录文件中写数据 </p><p>}
public void button2_click(object sender, system.eventargs e)
{}
</script>
<meta content=”internet explorer 5.0″ name=vs_targetschema>
<meta content=”microsoft visual studio 7.0″ name=generator>
<meta content=c# name=code_language>
</head>
<body ms_positioning=”gridlayout”>
<form runat=”server”>
<font face=宋体>
<asp:label id=label1 style=”z-index: 100; left: 230px; position: absolute; top: 27px” runat=”server” height=”28px” width=”156px”>
asp酷技术资讯网网站内容发布系统
</asp:label>
<asp:label id=label2 style=”z-index: 101; left: 110px; position: absolute; top: 68px” runat=”server” height=”25px” width=”65px”>
文件名:
</asp:label>
<asp:textbox id=textbox1 style=”z-index: 102; left: 255px; position: absolute; top: 64px” runat=”server” height=”33px” width=”178px” >
</asp:textbox>
<asp:label id=label3 style=”z-index: 103; left: 108px; position: absolute; top: 126px” runat=”server” height=”36px” width=”86px”>
文章名称:
</asp:label>
<asp:textbox id=textbox2 style=”z-index: 104; left: 256px; position: absolute; top: 114px” runat=”server” height=”37px” width=”177px”>
</asp:textbox>
<asp:label id=label4 style=”z-index: 105; left: 114px; position: absolute; top: 183px” runat=”server” height=”31px” width=”89px”>
作者:
</asp:label>
<asp:textbox id=textbox3 style=”z-index: 106; left: 256px; position: absolute; top: 183px” runat=”server” height=”36px” width=”179px”>
</asp:textbox>
<asp:label id=label5 style=”z-index: 107; left: 114px; position: absolute; top: 241px” runat=”server” height=”51px” width=”81px”>
摘要:
</asp:label>
<asp:textbox id=textbox4 style=”z-index: 108; left: 256px; position: absolute; top: 245px” runat=”server” height=”36px” width=”179px”>
</asp:textbox>
<asp:label id=label6 style=”z-index: 109; left: 116px; position: absolute; top: 315px” runat=”server” height=”36px” width=”78px”>
内容:
</asp:label>
<asp:textbox id=textbox5 style=”z-index: 110; left: 259px; position: absolute; top: 303px” runat=”server” height=”95px” width=”252px” textmode=”multiline”>
</asp:textbox>
</font> </p><p><input id=button2 style=”z-index: 113; left: 343px; width: 40px; position: absolute; top: 430px; height: 24px” type=button value=重置 name=button2 runat=”server” onserverclick=”button2_click” designtimedragdrop=”59″>
<br>
<br>
<div id=mess runat=server>
</div>
<br>
<input type=”button” value=”提交” onserverclick=”button1_click” runat=”server” id=”button1″ name=”button1″ style=”z-index: 112; left: 268px; position: absolute; top: 430px”>
</form>
</body>
</html>
此程序在.net beta2 build 9148下测试通过。(完)

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用asp.net和xml做的新闻更新系统(3)-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章