动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ ASP实例 ]的信息



本月文章推荐
.用ASP+实现一个简单的计算器(适合.
.DW+ASP 玩转动态二级菜单.
.把HTML表单提交的数据转化成XML文.
.磁盘ID在ASP源码防拷贝中的应用.
.使用VB编写纯ASP程序.
.ASP进阶之文章在线管理更新(4).
.使用 ASP+ 列表绑定控件(上).
.如何用ASP编写网站统计系统(一).
.文件的读出 编辑 管理.
.用asp.net写的论坛程序--浏览贴及.
.全文本检索的应用(3).
.Flash+ASP实现电子互动地图在线标.
.用ASP统计用户在站点的停留时间(.
.在ASP中使用FSO组件生成HTML页面.
.中文虚拟域名实现(2) (环境:中文.
.用密码保护页面 (I).
.构建免受FSO组件威胁虚拟主机 .
.完整的访问统计系统(一:数据库.
.用asp解析图片地址,并将其保存。.
.经典的分页完整程序+注释.

ASP.NET: XML留言版第二版

发表日期:2001-6-8 |


Code:
1) guestpost.aspx :- The Guestbook post page

<%@ Import Namespace="System" %>
<%@ Page Language="C#" EnableSessionState="False" Debug="True" %>
<%@ Import Namespace="System.IO" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%-- These are the imported assemblies and namespaces need to run the guest book --%>
<html>
<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script Language="C#" runat="server">
//This method is called when the submit button is clicked
public void Submit_Click(Object sender, EventArgs e)
{
//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile = "db/guest.xml" ;
//put the posting code within a Try-Catch block
try
{
//proceed only if all the required feilds are filled-in
if(Page.IsValid&&Name.Text!=""&&Country.Text!=""&&Email.Text!=""){
errmess.Text="" ;
//make an instance of the class XmlDocument
XmlDocument xmldocument = new XmlDocument() ;
//load the xml file you will use as your database.
//Since we are working on a server we have to use 'Server.MapPath()'
//to map the path to the database file //Also Open a FileStream to the Database
//Keep "FileShare.ReadWrite" mode to enable sharing
FileStream fin ;
fin = new FileStream(Server.MapPath(datafile), FileMode.Open,
FileAccess.Read, FileShare.ReadWrite) ;
xmldocument.Load(new StreamReader(fin)) ;
fin.Close();
//make an instance of DocumentNavigator class which will help us to
//navigate in the loaded XML data file.
DocumentNavigator navigator = new DocumentNavigator(xmldocument) ;

//below code is very significant as it navigates through the XML document and
//stores the required values (ps: read this code carefully)
//first move to the xml documents elements
//(in my xml file this will be the 'Guests' Node)
navigator.MoveToDocumentElement() ;
//then insert First element (FirstChild) which will contain all the information
// of a single guest posting
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Element, "Guest","","") ;
//Insert the Element of Name as the First node of 'Guest'
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Element, "Name","","") ;
//This is important to specify what kind of Value will the Name element contain
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Name","","") ;
//assign the Name element the Value from the .Text property of the TextBox
navigator.Value=Name.Text ;
//Go back to the Parent Node ie 'Guest'
navigator.MoveToParent() ;
//Insert another Element 'Country' After the FirstChild ie. after the 'Name' node.
navigator.Insert(TreePosition.After, XmlNodeType.Element,"Country","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Country","","") ;
navigator.Value=Country.Text ;
navigator.MoveToParent() ;
navigator.Insert(TreePosition.After,XmlNodeType.Element,"Email","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"Email","","") ;
navigator.Value=Email.Text;

navigator.MoveToParent() ;
navigator.Insert(TreePosition.After,XmlNodeType.Element,"Comments","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"comments","","") ;
navigator.Value=Comments.Value ;
navigator.MoveToParent() ;

navigator.Insert(TreePosition.After, XmlNodeType.Element,"DateTime","","") ;
navigator.Insert(TreePosition.FirstChild, XmlNodeType.Text,"DateTime","","") ;
//set the Date time stamp of the entry
DateTime now = DateTime.Now ;
navigator.Value=now.ToShortDateString()+" "+now.ToShortTimeString() ;

//Create a stream to save the file
FileStream fout ;
fout = new FileStream(Server.MapPath(datafile), FileMode.Open,
FileAccess.Write, FileShare.ReadWrite) ;
//after making the necessary changes we Save the changes to the Xml Document
xmldocument.Save(new StreamWriter(fout)) ;
//free up the XML file from the Document file so that other programs can use it
xmldocument=null ;
fout.Close();
//Build a custom query sending the data posted to another page for display
//since it is a query we have to encode it in UTF8 format
String QueryString="Name="
+System.Web.HttpUtility.UrlEncodeToString(Name.Text,System.Text.Encoding.UTF8);
QueryString+="&&Country="
+System.Web.HttpUtility.UrlEncodeToString(Country.Text,System.Text.Encoding.UTF8);
QueryString+="&&Email="
+System.Web.HttpUtility.UrlEncodeToString(Email.Text,System.Text.Encoding.UTF8);
QueryString+="&&Comments="
+System.Web.HttpUtility.UrlEncodeToString(Comments.Value,System.Text.Encoding.UTF8);

//go to the page viewpost.aspx and append the query string at its end.
Page.Navigate("viewPost.aspx?" + QueryString);

}
else
{
//if any of the Fields are kept empty show an error message
errmess.Text="Fill in all the required fields of the Guestbook." ;
}
}
catch (Exception edd)
{
//catch any other exception that occur
errmess.Text="Cannot write to XML file because "+edd.ToString() ;
}
}
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<%-- Include a header file 'header.inc' --%>
<!-- #Include File="header.inc" -->
<br>
<h3 align="center" class="newsbody">Guestbook Post Page.</h3>
<br>
<asp:label id="errmess" text="" style="color:#FF0000" runat="server" />
<form runat="server">
<table border="0" width="80%" align="Center">
<tr >
<td class="newsheading"><b>Sign-in My GuestBook</b></td>
<td class="newsheading">&nbsp;</td>
</tr>
<tr class="newsbody" >
<td>Name :</td>
<td ><asp:textbox text="" id="Name" runat="server" />&nbsp;&nbsp;&nbsp;
<font color=#FF0000>*</font></td>
</tr>
<tr class="newsbody">
<td>Country :</td>
<td><asp:textbox text="" id="Country" runat="server"/>&nbsp;&nbsp;&nbsp;
<font color=#FF0000>*</font></td>
</tr>
<tr class="newsbody">
<td>E-Mail :</td>
<td><asp:textbox test="" id="Email" runat="server"/>&nbsp;&nbsp;&nbsp;
<font color=#FF0000>*</font></td>
</tr>
<tr class="newsbody">
<td>Comments :</td>
<td><textarea id="Comments" cols="25" rows="4" runat="server" /></td>
</tr>
<tr class="newsbody">
<td colspan="2" >
<asp:Button class="newsheading" Text="Submit" onClick="Submit_Click" runat="server"/>
</td>
</tr>
</table>
</form>
<br>
<h4 class="newsbody"><a href="viewguestbook.aspx">Click here </a> to view GuestBook.</h4>
<br>
<!-- #Include File="footer.inc" -->
</body>
/html>




2) viewpost.aspx : The post conformation page.

<%@ Import Namespace="System" %>
<%@ Page Language="C#" Debug="true" %>
<html>
<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script language="C#" runat="server" >
//execute this script when the page loads
void Page_Load(Object Src, EventArgs E)
{
//if the page is called from another page
if (!Page.IsPostBack) {
//get the different Parameters from the query string and store it
//to respective Labels
NameLabel.Text = Request.Params["Name"];
CountryLabel.Text= Request.Params["Country"] ;
EmailLabel.Text=Request.Params["Email"];
CommentsLabel.Text=Request.Params["Comments"] ;
}
if(Page.IsPostBack)
{
//else display an error
errmess.Text="This Page Cannot be called directly. " ;
}
}
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<!-- #Include File="header.inc" -->
<asp:label id="errmess" text="" style="color:#FF0000" runat="server" />
<center>
<h2 class="newsbody"><b>Thank You , for posting in My GuestBook.</b></h2>
<table align=center width="60%" border="0" cellspacing="2" cellpadding="1" >
<tr class="titheading"><td colspan="2">The information You Posted!</td></tr>
<tr class="newsbody">
<td>Name :</td>
<td><asp:label id="NameLabel" text="" runat="server" /></td>
</tr>
<tr class="newsbody">
<td>Country :</td>
<td><asp:label id="CountryLabel" text="" runat="server" /></td>
</tr>
<tr class="newsbody">
<td>E-mail :</td>
<td><asp:label id="EmailLabel" text="" runat="server"/></td>
</tr>
<tr class="newsbody">
<td>Comments :</td>
<td><asp:label id="CommentsLabel" text="" runat="server" /></td>
</tr>
</table>
<br>
<h4 class="newsbody"><a href="viewguestbook.aspx">Click here </a> to view GuestBook.</h4>
<br>
</center>
<!-- #Include File="footer.inc" -->
</body>
</html>




2) viewguestbook.aspx : The Guestbook viewing page.

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Assembly Name="System.Xml" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" %>
<%-- Needed Assembiles --%>
<html>
<head>
<title>Welcome to Saurabh's GuestBook.</title>
<script language="C#" runat=server>
//run the script when the Page is Loaded
public void Page_Load(Object sender, EventArgs e)
{
//the path to the Xml file which will contain all the data
//modify this if you have any other file or directory mappings.
//modify this if you have been directed here from Step 2 of the ReadMe file.
string datafile = "db/guest.xml" ;
//try-Catch block to read from an XML file
try
{
//make an instance to the XMLDataDocument class
//this class can read from an xml file in and ordered format
XmlDataDocument datadoc = new XmlDataDocument();
//Open a FileStream to the Database
FileStream fin ;
fin = new FileStream(Server.MapPath(datafile),FileMode.Open,
FileAccess.Read,FileShare.ReadWrite) ;
// Infer the DataSet schema from the XML data and load the XML Data
datadoc.DataSet.ReadXml(new StreamReader(fin));
//Databind the first table in the Dataset to the Repeater
MyDataList.DataSource = datadoc.DataSet.Tables[0].DefaultView;
MyDataList.DataBind();

//free up the XML file to be used by other programs
datadoc=null;

}
catch (Exception edd)
{
//catch any other exceptions that occur
errmess.Text="Cannot read from XML file because "+edd.ToString() ;
}
}
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" rightmargin="0">
<!-- #Include File="header.inc" -->
<asp:label id="errmess" text="" style="color:#FF0000" runat="server" />
<br>
<h3 align="center" class="newsbody">My Guestbook.</h3>
<ASP:Repeater id="MyDataList" runat="server">
<template name="headertemplate">
<table class="mainheads" width="100%" style="font: 8pt verdana">
<tr style="background-color:#FF9966">
<th>
Name
</th>
<th>
Country
</th>
<th>
Email
</th>
<th>
Comments
</th>
<th>
Date/Time
</th>
</tr>
</template>
<template name="itemtemplate">

<tr style="background-color:#FFFFCC">
<td>
<%# DataBinder.Eval(Container.DataItem, "Name") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Country") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Email") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Comments") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "DateTime") %>
</td>
</tr>

</template>

<template name="footertemplate">

</table>

</template>

</ASP:Repeater>

<!-- #Include File="footer.inc" -->
</body>
</html>


Saurabh Nandu


上一篇:ASP.NET: XML计数器第二版 人气:10040
下一篇:不用图像组件的ASP图像计数器 人气:10562
浏览全部的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-7-25 WikyBlog v1.7.0.1 多国语言版
2008-7-25 乐彼网上开店系统(56770 Eshop)
2008-7-25 赛特网站管理系统sitecms v3.6.0
2008-7-25 Modoer多功能点评系统 v1.0.1 Bu
2008-7-25 Shangducms Teamsuit! v1.1.0 开
2008-7-25 幻影动漫网视频系统(Ppdong) v1.
2008-7-25 acteecompany企业网站建设系统 v
2008-7-25 恒浪整合管理系统 ims v4.1 ACCE
2008-7-25 艺术图库系统 v1.0 beta
2008-7-19 UltraEdit 简体中文增强版 14.10
2008-7-19 CentOS 5.2 i386 LiveCD
2008-7-19 Snapture多功能相机 v1.4
2008-7-19 iAcces中文输入法 v1.0Build016
2008-7-19 Cookbook烹饪秘籍 v2.5
2008-7-19 苹果专用DVD转换工具 v1.1.59汉化
2008-7-19 Modem修复软件ZiPhone修改版04.0
2008-7-19 AgileMessenger即时通讯工具美化
2008-7-19 Sketches画图软件 v0.7b6破解版


  发表评论
姓 名: 验证码:
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵