Search This Blog

Sunday, July 17, 2011

How to show XML Data in the Grid View

  • Create a Page with the Name XMLSample.aspx
  • Write the Below controls in the .aspx source Page.
  • Create an xml file on the desktop with Name Students ( See example xml at the End)
<asp:GridView ID="gvList" runat="server">
        </asp:GridView>
        Path:
        <asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" />
  • Write the Below code in the Code behind file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;


public partial class XMLSample : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        HttpPostedFile hpf=FileUpload1.PostedFile;
        string fName=FileUpload1.PostedFile.FileName;
        System.Data.DataSet ds = new System.Data.DataSet();
        ds.ReadXml(fName);
        gvList.DataSource = ds.Tables[0];
        gvList.DataBind();
        
        
    }
}

Note : Example Xml file.


<Students>
  <Student>
    <id>1312</id>
    <name>123</name>
    <age>123123</age>
  </Student>
  <Student>
    <id>6</id>
    <name>Ashoke</name>
    <age>23</age>
  </Student>
</Students>

Friday, July 15, 2011

Encrpt and Decrypt Connection String

For Security reasons we need to encrypt the connection strings.

How to Encrypt a connection string:
  • Open visual studio command prompt.
  • Change your command prompt location and should point to your application physical drive
  • Assume your application Name is DataSet and  is present in c:\Documents and Settings\Administrator\My Documents
  • type the below statements and then press enter to encrypt the connection
  • aspnet_regiis -pe "connectionStrings" -app "/DataSet"
How to Decrypt Connection:
  • Type the below command and press enter
  • aspnet_regiis -pd "connectionStrings" -app "/DataSet"
Note : See the below attached screen shot.

Saturday, July 9, 2011

Sealed class

Sealed class

  1. It is complete class
  2. It is allow creating an object
  3. It is also called instance class
  4. Inheritance is not possible for Sealed Class. Means No one can be able to inherit from a Sealed Class but sealed class can inherit from any other class (The Parent Class should not be Sealed Class).
  5. Sealed class can never acts as a Parent Class
  6. Static class is by default sealed class only.

Example for Sealed Class:

----------------------------------------------------

­­­­public sealed class ToyCalc

{

}

public class AdvancedToyCalc : ToyCalc

{

}

Note 1: The above Code is wrong since a sealed class can never act as a Base or Parent Class.

Note 2: But ToyCalc class can inherit from other classes ex.

Ex: ­­­­public sealed class ToyCalc: Toy

The Toy Class should not be a Static Class or SealedClass.

Abstract Class

Abstract Class:
  • When a class is not providing full functionality it recommended to declare that class as an Abstract class.
  • Method with out body is called an abstract method.
  • Ex: public abstract void GetArea ();
  • When class contain at least one abstract method then that class must be declared as abstract class.
  • All the abstract method must be overridden in the derived class.
  • We cant create object for Abstract class.
Ex :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class AbstractClassSammple : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

Circle c = new Circle ();

c.print();

Response.Write(c.findarea()+" ");

Response.Write("
"
+c.print());

}

}

public abstract class Shape

{

private int x = 10;

private int y = 20;

public int print()

{

return (x + y);

}

public abstract double findarea();

}

public class Circle : Shape

{

private int r = 10;

public override double findarea()

{

double a = 3.14 * r * r;

return (a);

}

}