Read and count books from XML in asp.net 4 using cSharp

29. August 2010

 

CS page code

using System;
using System.IO;
using System.Xml;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int bookcount = 0;
        XmlReaderSettings settings = new XmlReaderSettings();

        settings.IgnoreWhitespace = true;
        settings.IgnoreComments = true;

        string booksFile = Server.MapPath("books.xml");
        using (XmlReader reader = XmlReader.Create(booksFile, settings))
        {
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element &&
                        "book" == reader.LocalName)
                {
                    bookcount++;
                }
            }
        }
        Response.Write(String.Format("Found {0} books!", bookcount));
    }
}

 

books.xml

<?xml version='1.0'?>

<!-- This file is a part of a book store inventory database -->

<bookstore xmlns="http://example.books.com">

    <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">

        <title>The Autobiography of Benjamin Franklin</title>

        <author>

            <first-name>Benjamin</first-name>

            <last-name>Franklin</last-name>

        </author>

        <price>8.19</price>

    </book>

    <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">

        <title>The Confidence Man</title>

        <author>

            <first-name>Herman</first-name>

            <last-name>Melville</last-name>

        </author>

        <price>12.99</price>

    </book>

    <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">

        <title>The Gorgias</title>

        <author>

            <first-name>Sidas</first-name>

            <last-name>Plato</last-name>

        </author>

        <price>9.91</price>

    </book>

</bookstore>



Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0, XML , ,

free download 90-day trial editions of Visual Studio 2010.

14. August 2010

Your Ad Here

you can download free 90 days trial editions of Visual Studio 2010 from microsoft site.Link is given below.

http://www.microsoft.com/visualstudio/en-us/download


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net , ,

Reset Form using Jquery

11. August 2010

If you have one or more then one form in HTML page. You can reset  the form by calling jquery reset function.

Example

$(document).ready(function() {
// you can reset more then one form by using this function
   $("#reset").click(function() {
     $("form").each(function() {
       this.reset();
     });
   });
 });


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, JQuery , , , , ,

Printing Support in avaible in Silverlight 4 now

9. August 2010

good news for developer's. Print can be done in Silverlight 4 through  PrintDocument class.

Example

 

PrintDocument doct = new PrintDocument();

    doct.PrintPage += (s, args)
    {   
        args.PageVisual = LayoutRoot;
    };

    doct.Print(docName);// print dialog box

By using this PrintDocument Class you can print entrie page or to print a specfic part of page.

 


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, SilverLight , ,

Linq to SQL Connection in asp.net Csharp

29. June 2010

In this Example, I have Create a connecton string and establish a connection between object to database. and Select title from employees table.

string connectionString = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True";
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            using (NorthwindDataContext context = new NorthwindDataContext(connection))
            {
                var query = from c in context.employees
                            select c.Title;

                foreach (var title in query)
                {
                    Response.Write(title);
                }
            }


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0 ,



User Name: Guest

Your Ip: 38.107.191.94
Time: