用asp.net和xml做的新聞更新系統(tǒng)(3)
2024-07-10 12:55:32
供稿:網(wǎng)友
最后,大家來看一下最負(fù)責(zé)的一個頁面,這個頁面的作用就是用來建立新的xml數(shù)據(jù)。
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("文件名已經(jīng)存在,請重選文件名。");
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格式的內(nèi)容。
string xmlfile =textbox5.text.replace("&","&");
xmlfile = xmlfile.replace("<","<");
xmlfile = xmlfile.replace(">",">");
xmlfile = xmlfile.replace( @"""""",""");
xmlfile = xmlfile.replace("'","'");
xmlfile = xmlfile.replace ("/n","</paragraph><paragraph>");
//把數(shù)據(jù)寫入新建的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>
//向目錄文件中寫數(shù)據(jù) </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 runat="server" height="28px" width="156px">
asp酷技術(shù)資訊網(wǎng)網(wǎng)站內(nèi)容發(fā)布系統(tǒng)
</asp:label>
<asp:label id=label2 runat="server" height="25px" width="65px">
文件名:
</asp:label>
<asp:textbox id=textbox1 runat="server" height="33px" width="178px" >
</asp:textbox>
<asp:label id=label3 runat="server" height="36px" width="86px">
文章名稱:
</asp:label>
<asp:textbox id=textbox2 runat="server" height="37px" width="177px">
</asp:textbox>
<asp:label id=label4 runat="server" height="31px" width="89px">
作者:
</asp:label>
<asp:textbox id=textbox3 runat="server" height="36px" width="179px">
</asp:textbox>
<asp:label id=label5 runat="server" height="51px" width="81px">
摘要:
</asp:label>
<asp:textbox id=textbox4 runat="server" height="36px" width="179px">
</asp:textbox>
<asp:label id=label6 runat="server" height="36px" width="78px">
內(nèi)容:
</asp:label>
<asp:textbox id=textbox5 runat="server" height="95px" width="252px" textmode="multiline">
</asp:textbox>
</font> </p><p><input id=button2 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" >
</form>
</body>
</html>
此程序在.net beta2 build 9148下測試通過。(完)
網(wǎng)站運(yùn)營seo文章大全提供全面的站長運(yùn)營經(jīng)驗(yàn)及seo技術(shù)!