如何建立自己的新闻发布系统?

2008-02-22 09:28:02来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

下面是一个建立新闻发布系统的程序,不用和数据库打交道哦
步骤:
(1).在vs2005中新建网站,新建三个aspx网页,分别命名:title.aspx,news.aspx,main.aspx其中title.aspx用来设置标题,可以自己设计,写几个字也行,news.aspx用来显示新闻标题,main.aspx用来显示新闻内容。
(2).新建htm页,用来设计框架。代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>无标题页</title>
</head>
<frameset border="0" bordercolor="#6699cc" framespacing="3" id="fsTop" rows="85,*">
<frame frameborder="no" marginheight="0" marginwidth="0" name="title" noresize scrolling="no" src="title.aspx" >
<frameset border="0" frameborder="1" framespacing="3" cols="110,*">
<frame frameborder="0" marginheight="0" marginwidth="0" name="dir" src="news.aspx" style="BORDER-RIGHT: #99ccff 1px solid; BORDER-TOP: #003366 1px solid" scrolling="auto" >
<frame bordercolor="#6699cc" frameborder="0" name="main" scrolling="yes" src="main.aspx?name=hello" style="BORDER-LEFT: #99ccff 2px groove; BORDER-TOP: #003366 1px solid">
</frameset>
</frameset>
</html>(3).现在你的程序还没有内容,新建xml文件,命名contents.xml,用来显示新闻标题,代码如下:
<?xml version="1.0" encoding="GB2312"?>
<topiclist type="Dreamsite News">
<topic>
<title>欢迎进入千里之外的新闻网!</title>
<href>main.aspx?name=hello</href>
</topic>
<topic>
<title>测试新闻</title>
<href>main.aspx?name=test</href>
</topic>
<topic>
<title> 第一条新闻</title>
<href>main.aspx?name=first</href>
</topic>
<topic>
<title> 第二条新闻</title>
<href>main.aspx?name=dddd</href>
</topiclist>注意我们的每条新闻内容都是一个xml文件,现在你知道该做什么了吧,新建hello.xml;test.xml;first.xml;dddd.xml文件,在这里给出一个例子,代码如下:
<?xml version="1.0" encoding="GB2312"?>
<document>
<title>今日新闻</title>
<abstract>头版新闻</abstract>
<author>千里之外</author>
<content>&lt;paragraph&gt;大家好&lt;/paragraph&gt;</content>
</document>现在你就可以看到效果了,下面我们看一下发布新闻的代码,也很简单,新建manage.aspx页面,前台代码:
</head>
<body>
<form id="form1" runat="server">
<div>
<p>千里之外个人新闻发布系统
</p>
文件名:
<asp:textbox id="TextBox1" runat="Server" />
<Asp:RequiredFieldValidator id="valid1" ControlToValidate="Textbox1" runat="Server">(必要栏)
</Asp:RequiredFieldValidator><p>
文章名称:
<asp:textbox id="TextBox2" runat="server" />
<Asp:RequiredFieldValidator id="valid2" ControlToValidate="Textbox2" runat="Server">(必要栏)
</Asp:RequiredFieldValidator>
<p>
作者:
<asp:textbox id="TextBox3" runat="server" />
<Asp:RequiredFieldValidator id="valid3" ControlToValidate="Textbox3" runat="Server">(必要栏)
</Asp:RequiredFieldValidator>
<p>
摘要:<p>
<asp:textbox id="TextBox4" textmode="MultiLine" width="70%" runat="server" />
<p>
内容:<p>
<asp:textbox id="TextBox5" textmode="MultiLine" rows="6" width="70%" runat="server" />
<p>
<asp:Button id="submit" text="提交" runat="server" />
</div>
</form>
</body>后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
public partial class manage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//判断文件是否存在
if (File.Exists(Server.MapPath(TextBox1.Text ".xml")))
Response.Write("文件名已经存在,请重新选文件名!");
else
{
//首先将数据插入新闻列表中
XmlNode CurrNode;
XmlDocument xmldoc = new XmlDocument();
//加载索引文件
xmldoc.Load(Server.MapPath("contents.xml"));
string insstr;
//生成新闻索引
insstr = "<topic><title>" TextBox2.Text "</title><href>main.aspx?name=" TextBox1.Text "</href></topic>";
XmlDocumentFragment docFrag = xmldoc.CreateDocumentFragment();
docFrag.InnerXml = insstr;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:用ASP.NET 2.0设计网络在线投票系统

下一篇:隨心所欲產生圖案