当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  用Asp.net实现基于XML的留言簿之二

 用Asp.net实现基于XML的留言簿之二

点击次数:13 次 发布日期:2008-11-26 16:16:45 作者:源代码网
源代码网推荐      四.代码:
源代码网推荐  
源代码网推荐  (1) guestpost.aspx:
源代码网推荐  
源代码网推荐  < %@ Page Language="C#" EnableSessionState="False" % >
源代码网推荐  < %@ Import Namespace="System" % >
源代码网推荐  < %@ Import Namespace="System.IO" % >
源代码网推荐  < %@ Import Namespace="System.Data" % >
源代码网推荐  < %-- 这些是本程序正常运用所必须的名字空间 --% >
源代码网推荐  
源代码网推荐  < html >
源代码网推荐  < head >
源代码网推荐  < title >欢迎来到我的留言簿< /title >
源代码网推荐  < script Language="C#" runat="server" >
源代码网推荐  ///< summary >
源代码网推荐  /// 当提交(submit)按钮按下后,调要这个函数
源代码网推荐  ///< /summary >
源代码网推荐  public void Submit_Click(Object sender, EventArgs e)
源代码网推荐  {
源代码网推荐  //保存数据的XML文件的路径
源代码网推荐  //如果你的路径和下面的不同,则请修改之
源代码网推荐  string dataFile = "db/guest.xml" ;
源代码网推荐  
源代码网推荐  //运用一个Try-Catch块完成信息添加功能
源代码网推荐  try{
源代码网推荐  //仅当页面是有效的时候才处理它
源代码网推荐  if(Page.IsValid){
源代码网推荐  
源代码网推荐  errmess.Text="" ;
源代码网推荐  //以读的模式打开一个FileStream来访问数据库
源代码网推荐  FileStream fin;
源代码网推荐  fin= new FileStream(Server.MapPath(dataFile),FileMode.Open,
源代码网推荐  FileAccess.Read,FileShare.ReadWrite);
源代码网推荐  //建立一个数据库对象
源代码网推荐  DataSet guestData = new DataSet();
源代码网推荐  //仅从数据库读取XML Schema
源代码网推荐  guestData.ReadXmlSchema(fin);
源代码网推荐  fin.Close();
源代码网推荐  //从数据集的Schema新建一个数据行
源代码网推荐  DataRow newRow = guestData.Tables[0].NewRow();
源代码网推荐  //用相应值填写数据行
源代码网推荐  newRow["Name"]=Name.Text;
源代码网推荐  newRow["Country"]=Country.Text;
源代码网推荐  newRow["Email"]=Email.Text;
源代码网推荐  newRow["Comments"]=Comments.Text;
源代码网推荐  newRow["DateTime"]=DateTime.Now.ToString();
源代码网推荐  //填写完毕,将数据行添加到数据集
源代码网推荐  guestData.Tables[0].Rows.Add(newRow);
源代码网推荐  //为数据库文件新建另一个写模式的FileStream,并保存文件
源代码网推荐  FileStream fout ;
源代码网推荐  fout = new FileStream(Server.MapPath(dataFile),FileMode.Open,
源代码网推荐  FileAccess.Write,FileShare.ReadWrite);
源代码网推荐  
源代码网推荐  guestData.WriteXml(fout, XmlWriteMode.WriteSchema);
源代码网推荐  fout.Close();
源代码网推荐  //隐藏当前的面板
源代码网推荐  formPanel.Visible=false;
源代码网推荐  //显示带有感谢信息的面板
源代码网推荐  thankPanel.Visible=true;
源代码网推荐  }
源代码网推荐  }
源代码网推荐  catch (Exception edd)
源代码网推荐  {
源代码网推荐  //捕捉异常
源代码网推荐  errmess.Text="写入XML文件出错,原因:"+edd.ToString() ;
源代码网推荐  }
源代码网推荐  }
源代码网推荐  < /script >
源代码网推荐  < LINK href="mystyle.css" type=text/css rel=stylesheet >
源代码网推荐  < /head >
源代码网推荐  < body >
源代码网推荐  < %-- 包含一个头文件:header.inc --% >
源代码网推荐  < !-- #Include File="header.inc" -- >
源代码网推荐  < br >
源代码网推荐  < h3 align="center" class="newsbody" >留言者信息< /h3 >
源代码网推荐  < br >
源代码网推荐  < asp:label id="errmess" text="" style="color:#FF0000" runat="server" / >
源代码网推荐  < asp:Panel id=formPanel runat=server >
源代码网推荐  < form runat="server" >
源代码网推荐  < table border="0" width="80%" align="Center" >
源代码网推荐  < tr >
源代码网推荐  < td class="newsheading" >< b >请在我留言簿留下您宝贵的信息!!< /b >< /td >
源代码网推荐  < td class="newsheading" > < /td >
源代码网推荐  < /tr >
源代码网推荐  < tr class="newsbody" >
源代码网推荐  < td >姓名:< /td >
源代码网推荐  < td >< asp:textbox text="" id="Name" runat="server" / >
源代码网推荐  < asp:RequiredFieldValidator ControlToValidate=Name display=static
源代码网推荐  runat=server >
源代码网推荐  *< /asp:RequiredFieldValidator >< /td >< /tr >
源代码网推荐  < tr class="newsbody" >< td >国家:< /td >
源代码网推荐  < td >< asp:textbox text="" id="Country" runat="server"/ >
源代码网推荐  < asp:RequiredFieldValidator ControlToValidate=Country display=static
源代码网推荐  runat=server >
源代码网推荐  *< /asp:RequiredFieldValidator >< /td > < /tr >
源代码网推荐  < tr class="newsbody" >< td >E-Mail:< /td >
源代码网推荐  < td >< asp:textbox test="" id="Email" runat="server"/ >
源代码网推荐  < asp:RequiredFieldValidator ControlToValidate=Email display=static
源代码网推荐  runat=server >
源代码网推荐  *< /asp:RequiredFieldValidator >< asp:RegularExpressionValidator
源代码网推荐  runat="server"
源代码网推荐  ControlToValidate="Email"
源代码网推荐  ValidationExpression="[w-]+@([w-]+.)+[w-]+"
源代码网推荐  Display="Static"
源代码网推荐  Font-Name="verdana" Font-Size="10pt" >
源代码网推荐  请输入一个格式正确的Email地址!< /asp:RegularExpressionValidator >< /td >
源代码网推荐  < /tr >< tr class="newsbody" >< td >留言:< /td >
源代码网推荐  < td >< asp:Textbox textmode=multiline id="Comments" columns="25"
源代码网推荐  rows="4" runat="server" / >< /td >< /tr >
源代码网推荐  < tr class="newsbody" >
源代码网推荐  < td colspan="2" >
源代码网推荐  < asp:Button class="newsheading" id="write" Text="Submit"
源代码网推荐  onClick="Submit_Click" runat="server"/ >< /td >< /tr >< /table >< /form >< /asp:Panel >
源代码网推荐  
源代码网推荐  < asp:Panel id=thankPanel visible=false runat=server >
源代码网推荐  < p class="newsbody" align=center >< b >谢谢访问我的留言簿!< /b >
源代码网推荐  < br >< a href="viewguestbook.aspx" >请点击这里 < /a > 查看留言簿。
源代码网推荐  < /p >
源代码网推荐  < /asp:Panel >
源代码网推荐  < !-- #Include File="footer.inc" -- >
源代码网推荐  < /body >
源代码网推荐  < /html >
源代码网推荐  
源代码网推荐  
源代码网推荐  转自:动态网制作指南 www.knowsky.com
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华