ASP.NET
  Home arrow ASP.NET arrow Page 2 - Completing an ASP.NET AJAX Client-Centric ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Completing an ASP.NET AJAX Client-Centric Wiki Application
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-10-16

    Table of Contents:
  • Completing an ASP.NET AJAX Client-Centric Wiki Application
  • The Server Side
  • Write a Post Related to the Special Article
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Completing an ASP.NET AJAX Client-Centric Wiki Application - The Server Side


    (Page 2 of 4 )

    As is mentioned above, the SendMsgServer.aspx page serves as a CGI's functionality. Now let's look into the source code:

      protected void Page_Load(object sender, EventArgs e){

    //get the name of current user

      string username = HttpContext.Current.User.Identity.Name;

      string title = Request.QueryString["title"];

      string content = Request.QueryString["content"];

      int categoryid = int.Parse(Request.QueryString["categoryid"]);

       ArticleManager myarticle = new ArticleManager();

        myarticle.AddArticle(title, username, categoryid);

    //add the details into a XML file

    myarticle.AddXML(Server.MapPath(".") + @"content.xml", title,
    content, username);

    Response.Write("Congratulation! You've succeeded in sending the
    post.");

    }

    There are four tasks here in total.

    1. Accept the passed parameters. 
    2. Add the general article information into the database table. 
    3. Put the detailed article content into the corresponding '.xml' file using an XML file template (i.e. file content.xml located at the root folder, which specifies the format of a newly-generated XML file). 
    4. Send back to the client side the message about the asynchronous invocation.

    Obviously, steps 2 and 3 are of major interest to us. Let's continue to study them.

    First, let's check out the code for the AddArticle method:

    public void AddArticle(string title, string user, int
    categoryid)

    {

      StringBuilder strSQL = new StringBuilder();

        SqlParameter[] newsParms = GetParameters();

         newsParms[0].Value = title;

         newsParms[1].Value = getFilename().ToString();

         xmlfilename = getFilename().ToString();

         newsParms[2].Value = DateTime.Now;

         newsParms[3].Value = 0;

         newsParms[4].Value = DateTime.Now;

         newsParms[5].Value = user;

         newsParms[6].Value = categoryid;

    using (SqlConnection conn = new SqlConnection(ConnectionString))

    {

      strSQL.Append("INSERT INTO ArticleInfo VALUES " +

    "(@title,@filename,@posttime,@replycount,@lastreplytime,
    @postuser,@categoryid)");

    SqlHelper.ExecuteNonQuery(conn, CommandType.Text,
    strSQL.ToString(), newsParms);

     }

    }

    Here, we first get the buffered parameters using the helper method GetParameters; if there are no buffered parameters this method will automatically create a list of parameters and buffer them. Next, we assign values to each parameter. At last, within the 'using' code block we accomplish the task of inserting the current article information into the ArticleInfo table with the help of a helper class named SqlHelper (you can study it in the downloaded source code).

    Additionally, it's worth doing some more research into the above private method named getFilename:

    private int getFilename(){

      int cardrule = 0;

    string strsql = "select top 1 InfoID from ArticleInfo order by
    InfoID desc ";

     try {

      cardrule = (int)SqlHelper.ExecuteScalar(ConnectionString,
    CommandType.Text, strsql, null);

    }

     catch { cardrule = 0; }

      return cardrule + 1;

    }

    As you can see above, using the SqlHelper helper class gives us the maximum value for the InfoID field in the current ArticleInfo table, and then adds 1 to it. Finally, we return the integer value as the file name.

    Next, let's take a look at the code of the AddXML method:

    public void AddXML(string filename/*include path*/, string
    title, string content, string user){

     XmlDocument mydoc = new XmlDocument();

       mydoc.Load(filename);

     XmlElement ele = mydoc.CreateElement("title");

     XmlText text = mydoc.CreateTextNode(title);

     XmlElement ele1 = mydoc.CreateElement("posttime");

     XmlText text1 = mydoc.CreateTextNode(DateTime.Now.ToString());

     XmlElement ele2 = mydoc.CreateElement("content");

     XmlText text2 = mydoc.CreateTextNode(content);

     XmlElement ele3 = mydoc.CreateElement("postuser");

     XmlText text3 = mydoc.CreateTextNode(user);

     XmlNode newElem = mydoc.CreateNode("element", "xmlrecord", "");

      newElem.AppendChild(ele);

      newElem.LastChild.AppendChild(text);

      newElem.AppendChild(ele1);

      newElem.LastChild.AppendChild(text1);

      newElem.AppendChild(ele2);

      newElem.LastChild.AppendChild(text2);

      newElem.AppendChild(ele3);

      newElem.LastChild.AppendChild(text3);

        XmlElement root = mydoc.DocumentElement;

          root.AppendChild(newElem);

          int index = filename.LastIndexOf(@"");

          string path = filename.Substring(0, index);

          path = path + @"" + xmlfilename + "file.xml";

        FileStream mystream = File.Create(path);

     mystream.Close();

    XmlTextWriter mytw = new XmlTextWriter(path, Encoding.Default);

     mydoc.Save(mytw);

      mytw.Close();

    }

    Here, we are performing the typical ASP.NET 2.0 XML data operation-mainly using the XmlDocument class and the XmlTextWriter class together with a ready XML file template to construct an XML file which, due to the reason discussed before, will finally be stored at the root folder of the website. Since there is nothing more peculiar to be emphasized (you can find out much about XML operations in MSDN), we will leave the subject here, but it is highly recommended that you study it together with the ready template file named 'content.xml'-it's a pretty universal module that you can put to use elsewhere.

    So much for the 'sending post' module. Next, let's continue to study the last part of this article-adding comments to the current article.

    More ASP.NET Articles
    More By Xianzhong Zhu


     

    ASP.NET ARTICLES

    - Developing a Mini ASP.NET AJAX Server Centri...
    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT