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

How to Read Windows Registry

24. August 2010

Below is the simple line code in which i have told you how to read window registry.

RegistryKey key = Registry.LocalMachine
.OpenSubKey(ConfigurationManager
.AppSettings["LocalRootRegKey"]
.ToString(), true);

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

ALL

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

PayPal payment system in ASP.NET

14. August 2010

you can download asp.net paypay payment module from below given reference link

http://www.codeproject.com/KB/aspnet/UsePayPalPaymentInASPNET.aspx


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

ALL, asp.net

JSON string DeserializeObject and binf to dropdown control

14. August 2010

First create a class with name ListItem. ListItem class have two members named name and value, which send and receive  string arrary

 

public class ListItem
    {
        private string[] name;
        public string[] Name
        {
            get { return name; }
            set { name = value; }
        }
 
        private string[] _value;
        public string[] _Value
        {
            get { return _value; }
            set { _value = value; }
        }
    }

On Page Load

 

 

protected void Page_Load(object sender, EventArgs e)
        {             

            string JSONString = "{\"Name\":[\"Aamir\",\"Hasan\",\"Awais\",\"Ahmed\",\"Saba",\"Sobia\""],"
                          + "\"_Value\":[\"0x1\",\"0x2\",\"0x3\",\"0x4\",\"0x5\",\"0x6\"]}";            

            ListItem _Items = JsonConvert.DeserializeObject(JSONString);
            for (int i = 0; i < dropdownlistJsonItem.NAAM.Length; i++)
            {
                this.DropDownList1.Items.Add(new ListItem(_Items.Name[i], Items._Value[i]));
            }
        }

 

On aspx Page drag and drop Downdown List control as shown below

 <asp:DropDownList ID="DropDownList1" runat="server" /> 
     

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

ALL, asp.net , , ,



User Name: Guest

Your Ip: 38.107.191.93
Time: