Monday, 26 August 2013

You can get Parent element from child element using LINQ method. Some times there are situations when you traverse XML file and you reach at child node and you want to get details of Parent node at that time you can use "Parent" method which will give you parent node as XElement object.

Here is example for this.
In this example we took one "BooksList.xml" file. Now we traverse to child node "Title" and after that, we get its parent node using "Parent" property.

Monday, 19 August 2013

Click Here to MVC_Regular_Expression_ValidationUsingAnnotations.zip Example.

We can do Regular Expression or REGEX validation using Annotations in MVC. We can use "RegularExpression" attribute for validation. In this attribute we specify Regular Expression string.

We can also specify our custom error messages for that we need to set "ErrorMessage" Property in "RegularExpression" attribute.

Here is example for this.

Monday, 12 August 2013

Download AbstractFactoryDesignPatternExampleWithCSharp.zip C# Example.
Download AbstractFactoryDesignPatternExampleWithVB.Net.zip VB.Net Example.


Abstract factory pattern is expanded version of basic factory pattern. In Abstract factory pattern we unite similar type of factory pattern classes in to one unique interface.

Factory classes helps to centralize the creation of classes and types. Abstract factory help bring equability between related factory patterns classes. Which create more simplified interface for the client.

Now let's understand basic details of how to implement abstract factory patterns. We have the factory pattern classes which integrate to a common abstract factory classes through inheritance. Factory classes lay over concrete classes which are derived from common interface.
For instance in below figure we demonstrate "Implementation of abstract factory".

Abstract  Factory Design Pattern
(To view original image , click on image)


Both the concrete classes "ConcreateClass1" and "ConcreateClass2" inherits from one common interface. The client has to only interact with the abstract factory and the common interface from which the concrete classes inherit.

Monday, 29 July 2013

There are situations where some time we want to get root element of XML file or document. We can get this root element and root element name very easily. We are using "Root" property of "XDocument" class.

Here is example for this.
In this example we take on "BooksList.xml" file and we display its root element name.

C#. Net Example :
        XElement objRootElement = XDocument.Load(Server.MapPath("BooksList.xml")).Root;
        Response.Write("<b>Name of root element is : </b>" + objRootElement.Name);

VB.Net Examples :
        Dim objRootElement As XElement = XDocument.Load(Server.MapPath("BooksList.xml")).Root
        Response.Write("<b>Name of root element is : </b>" & objRootElement.Name.ToString())

Output :


Below are the books that you would like :

Tuesday, 23 July 2013

Click Here to Download MVC_String_Length_ValidationUsingAnnotations.zip Example.

We can do string length validation using Annotations in MVC. We are using "StringLength" attribute for validation in this attribute we can specify how many characters we want to allow for particular field. In this, we can specify Maximum Length and Minimum Length. Minimum Length is an optional.

We can use more than one attribute on field.

Here is example for this.

Monday, 15 July 2013

We can get specific attributes values from XML file or document or object using LINQ. We are using "Elements" and "Attributes" methods of XML document object to get attributes values.

Here is example for this.
In this example we take one "BooksList.xml" file. This file contains books related details and each book has ISBN number which appears as attribute in "<book>" node. We retrieve this attribute using LINQ and display on screen.

Tuesday, 9 July 2013

Click Here to Download MVCValidationUsingAnnotations.zip Example.
 
Data annotations are uses for validation purposes. We can use annotations attribute on a model property. You can find data annotations in System.ComponentModel.DataAnnotations namespace. But there are attributes also available outside this namespace.

These attributes provide server-side validation and client-side validation. Here we are demonstrating "Required" attribute. This is a basic validation in each and every project or application we need required field validation.

Here is example for this.