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 , ,

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 ,

Parameter Name asp.net 4.0 New feature

25. June 2010

Another new feature in 4.O FrameWork, Name Parameter,Let see in the Below Sample how to pass the parameter.

 

protected void Page_Load(object sender, EventArgs e)
   {
   	foreach (int i in Add( n1:20,n2:60))
   	{
   		Response.Write(i.ToString() + " ");
   	}
   }
  

 public static IEnumerable Add(int n1, int n2)
 {
 
 return i*i;
 
 }


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

ALL, asp.net, asp.net 4.0, CSharp ,

View State Management in ASP.NET 4.0

28. April 2010

In ASP.NET 4.0 we have more control over maintaining view state for page let’s see how we can manage View State more efficiently in asp.net 4.0. In the earlier version of asp.net we have View State optional that means we can turn View State view EnableViewState property.

ASP.NET 4.0 things are different with respect to above scenario. Now we have one more property called ViewStateMode Property. This property help us greatly in managing View State. It has there values Enabled,Disabled,Inherit. With this property you can enable View State of control even if View State is disabled. So now we will have facility to turn off the View State of parent controls like page and then we can decide which control will have View State enabled.

In ASP.NET 4.0 ViewStateMode property will accept following values.

  • Enabled- This will enable View State for particular control and also for any child control which have ‘Inherit’ value for this property or nothing set for this property.
  • Disabled- This will disable View State for that particular control.
  • Inherit- This will specify that control will use the parent control ViewStateMode property.

Hope this will help you understanding View State Management in ASP.NET 4.0.



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

ALL, asp.net 4.0 ,

What's New in Visual Studio 2010 Languages

15. April 2010

What's New in Visual Basic 2010

Describes new features in the Visual Basic language and Code Editor. The features include implicit line continuation, auto-implemented properties, collection initializers, and more.

What's New in Visual C# 2010


Describes new features in the C# language and Code Editor. The features include the dynamic type, named and optional arguments, enhanced Office programmability, and variance.

What's New in Visual C++ 2010

Describes new and revised features in Visual C++. The features include lambda expressions, the rvalue reference declarator, and the auto, decltype, and static_assert keywords.

What's New in Visual F# 2010

Describes the F# language, which is a language that supports functional programming for the .NET Framework.

Reference:http://msdn.microsoft.com/en-us/library/bb386063%28VS.100%29.aspx


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

ALL, asp.net 4.0



User Name: Guest

Your Ip: 38.107.191.94
Time: