上一篇:在ASP.NET中实现会话状态基础 >>
用asp.net和xml做的新闻更新系统(3)
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("@#","'");
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下测试通过。(完)
下一篇:用asp.net和xml做的新闻更新系统(2) >>
相关文章:
- · 在ASP.NET中使用用户控件
- · 五种常见的ASP.NET安全缺陷
- · ASP.NET中的HTTP模块和处理程序
- · ASP.NET中使用Treeview和XML
- · 在Asp.net中如何实现弹出提示对话框
- · ASP.NET的跟踪模式详解
- · ASP.NET创建Web Services之概述
- · 在ASP.NET中从SQL Server检索图片
- · ASP.NET系统用户权限设计与实现
- · ASP.NET中TreeView控件使用小结
- · ASP.net的ACCESS数据分页方案
- · ASP.NET中对表单输入行有选择验证
- · 在ASP.NET 2.0中使用页面导航控件
- · ASP.NET四种页面导航方式的比较与选择
- · 利用ASP.NET 2.0创建自定义Web控件
- · ASP.NET 2.0中的DataSource系列控件
- · 使用ASP.NET程序来管理文件或目录的一种方案
- · ASP.NET Web Page应用深入探讨
- · ASP.net中用axWebBrowser中提交表单
- · 在ASP.NET中跟踪和恢复大文件下载
- · 利用ASP.NET的三种缓存提高站点性能
- · 认识ASP.NET会话状态
- · 用ASP/ASP.NET实现网络空间管理
- · ASP.NET 管理实用工具使用方法
- · asp.net开发wap程序必备:识别来访手机品牌型号
- · ASP.NET实现下载功能的中文文件名乱码处理
- · 手工创建datagrid数据列/模板列/按钮事件+简单的数据操作类(asp.net)
- · 在Asp.net中为图像加入版权信息
- · 亲密接触ASP.Net(14)
- · 亲密接触ASP.Net(13)
- · 亲密接触ASP.Net(12)
- · 亲密接触ASP.Net(11)
- · 亲密接触ASP.Net(10)
- · 亲密接触ASP.Net(9)
- · 亲密接触ASP.Net(8)
- · 亲密接触ASP.Net(7)
- · 亲密接触ASP.Net(6)
- · ASP.NET中Web DataGrid的使用指南
