Tuesday 1 July 2014

Simple CMS System in Asp.Net

Today, i will show the way to create simple CMS system in asp.net websites.This can be used to generate dynamic content pages or simple blog application in dot net.Though content on page is dynamic but yo must add a aspx page manually in your application. You may tweak this application according to your need to add dynamic pages on the fly in asp.net web applications or websites.

cms in asp.net

Steps to create cms system in asp.net:
1. First create a database in sql server and compile the following script for one of the tables to store dynamic content:
USE [CMS]
GO
/****** Object:  Table [dbo].[cms_page]    Script Date: 06/30/2014 09:57:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[cms_page](
    [page] [nvarchar](50) NULL,
    [html] [ntext] NULL,
    [id] [int] IDENTITY(1,1) NOT NULL,
 CONSTRAINT [PK_cms_page] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

2. Now add a page to manage dynamic content pages.
3. Now add a label and literal control on any page to show dynamic content. Bind data to label and literal using sql query.
4.I am using CKEDITOR as html content editor.
5. Download full attachment here.






Read More

Friday 30 May 2014

Learn C# Programming Tutorial Part 1 : Getting Started

Getting Started in C# - Tutorial



Madan Gehlot

Version 1.1

Copyright 2014

21.02.2014

Introduction to Dot Net Framework and C#


This tutorial describe history of Dot Net Framework , Platform Advantage , How program are executed and Setting up Development Environment.

Table Of Contents

1. Getting started
   1.1. Dot NetFramework
   1.2. Platform Advantage
   1.3. Platform Programming
   1.4. Development Environment Setup

1.1Dot Net Framework:

When Internet started to grown fast after 1995, Microsoft realised that direction of Web Development and Deployment will depends on growth of Internet, so they started to design and development of .NET platform keeping future of technology in mind.
When Microsoft was thinking of developing a new programming platform, at the same time, the Sun microsystem’s JAVA was very popular in the area of web development and Visual Basic was going viral for Desktop Programming. Microsoft didn’t want to leave the battle.
They inspired from JAVA to design such a programming language that have Security and Extendibility.They emphasised on the importance of Rapid and Easy Development.
Thus Microsoft decided to develop a Programming Language which has all essential concepts of programming. C# was the result of such efforts.
C # (C Sharp) is much similar to C/C++, JAVA and Visual Basic. C # is similar to JAVA from the Classes and Platform points of view, similar to Visual Basic from the GUI point of view, similar to C++ for Object Oriented Concepts and similar to C for Coding Structure.
C# also has Hardware level interaction capacity like C language. The architecture like JAVA language makes it more Secure and Powerful. Visual Basic like GUI feature enables it for Rapid Application Development.
Dot Net Framework was developed to make the programming architecture Future Proof, manage portability and manage Web and Windows application from single platform.
In .Net Framework, every .Net application includes Run time and Compile time services. These are Servers, COM, COM+ , DCOM, Internet Information Server , Windows .Net Server and SQL Server etc.
.Net Application Code has CLR( Common Language Runtime) in the root of Run Time Execution.
Purpose of CLR is same as that of JVM in JAVA. IT acts like Virtual Machine. CLR makes .Net code platform independent.
A program developed on a computer system having CLR can also be run on any other computer that has CLR. When we compile Dot Net Application, it generates .DLL or .EXE codes.We call them Portable Executable (PE) codes. These generated codes are not Native or Machine level but a kind of intermediate byte code.
Intermediate Codes are known as Microsoft Intermediate Language(MSIL) or simply IL.
When codes are loaded into CLR for execution, we call such code “ASSEMBLY” .Assembly is one or more file collection. All files are deploying as single unit. There is a Manifest file in Assembly which contain Data Types, Classes and files.
When CLR loads application into memory, only MANIFEST file is compiled in memory. Data Types and Classes are compiled only when there is need.  Because of this, .NET application load faster in memory and uses less resources. This process is called Just In Time compilation. As a result, there is no leakage of memory.
Garbage Collector automatically free up the Memory once there is no use of any Objects.

1.2 NET Platform Advantage:

Before proceeding, we will discuss the features of .NET platform that are helpful in developing Software and Services.

Object Oriented Programming:

Dot Net Framework was completely designed based on Object Oriented Programming Paradigm. We can extend any application using OOPs. Design and Management of software becomes easy using OOPs concepts.

Multiple Language Support:

Dot Net platform not only support C# and Visual Basic but also C++ and F#. More languages are being added at appropriate time.
We can develop even Android Based application using C#.

Simple Application Deployment:

Dot Net application are easy tom deploy because it don’t require registration like COM based application.

Rich Framework Class Library:

.Net has rich collection of Class Library. It is the perhaps only language which has features in rich Class libraries. We need framework class library to full fill specific achievement while developing any application.

Exception Handling:

This technique was designed to manage error in applications. Exception Handling works in the same way as C++ / JAVA Exception Handling mechanism works.

Improved Security:

Security is serious concern of code deployment. So Microsoft created Code Access Security (CAS) as Built In Security Mechanism.

Development Tools and Support:

Microsoft developed Visual Studio tool. It not only makes the development faster but also easy. It saves time of common configuration of our application. We can Create Manage, Design and Handle our project at single place.
We also get Debug, Error Handling, Packaging and Deployment help at single place.

1.3 Platform Programming:

.Net is multi language platform and more than 50 languages which have be designed or modified to support CLS specification of Dot Net framework. Microsoft support mainly four programming languages:

C# (C Sharp):

This programming language is top choice of developed. MS officially backed C# for development in .Net framework. C# is powerful like JAVA and retain powerful concepts from other languages such as C and C++ also.

VB.NET :

Visual Basic .Net is advanced version of VB 6.  OOPs concepts were lacking in VB 6 so MS added OOPs support to VB.NET. At present, marking share of VB.Net is reducing. Many developers and companies are leaning towards C#.

C++ /CLI (Common Language Infrastructure):

This is only Managed Code Extension of C++ programming. It enables us to design Dot Net framework based application by using C++ code syntax.

F# :

F# language is mainly for Financial and Scientific computing. Programmers use this language as Functional Programming.  Though very few people use F# and Microsoft only concentrating C#.
Apart from these languages, COBOL, Small Talk , Pascal, APL and Delhi are also used to develop application on  .Net framework.

Code Execution Process in Dot Net Platform:

There are two Code Execution processes:
 1.  Compile Time Process:
In this stage, the source code of our application is converted into intermediate code called MSIL (Microsoft Intermediate Language) or simply IL(Intermediate Language). Now a days, it is also known as CIL (Common Intermediate Language) .  MSIL code is not machine dependent code. So we can’t execute on any system directly.

Source Code à .Net Compiler à Byte Code (MSIL + META DATA)
2.   Run Time Process:
In the Run Time Stage, MSIL code is converted into machine code which is done by CLR (Common Language Runtime). CLR is heart of .Net framework. CLR includes Garbage Collection (GC), Code Access Security (CAS) , Code Verification (CV) and Just In Time (JIT) . JIT compiler actually does the IL to Native translation.

Byte Code (MSIL + META DATA) à JIT à Native Code
Native code is fully compatible with machine.
Please view below images to understand Code Execution Process.
Since MS support multiple languages for .Net framework, so there may be a situation when one type defined in a language may differs with type of another one. Every language must follow these types to make them compatible with .Net Framework:
1.       Value Type
2.       Reference Type
3.       Pointer Type

1.4 Development Environment Setup:

Every Programming Language is learnt by practicing small and fundamental programs. So we need any text editor or IDE. Text editors can be used for practice of small programme but developing whole project is very hard task. That’s why we use IDE (Integrated Development Environment). IDE makes development faster as they include useful tools. Build in support of such tool makes development, debugging and deployment easy.

For Development in .Net Framework using C#, we will use IDE. There are some commercial and free Tools we can use for this purpose. For example:
1.       Visual C# Express Edition
2.       Visual Studio Ultimate or Similar Commercial Version
3.       SharpDevelop
Using IDE at beginner level is not recommended as we may not be aware what’s happening. If you really want to understand basic code structure and working, I recommend use text editor such as NotePad ++ (NPP).
To use NPP as default C# IDE , you must download and install two plugins , “Explorer” and “NppExec” from plugin manager.
Please search “Using NotePad ++ for C # Development” in Google for more help.
Setting Visual Studio for development in C# is easy. You must set C# as default language. Follow on screen command during installation. If you find any difficulties, please let me know. I will use VS 10 edition’s screenshot in this tutorial.



Read More

Friday 28 March 2014

Bulk SMS Gateway C# Code for HTTP API

Today , I am going to show you how to send BULK SMS from any Website or Software. Every Bulk SMS provides uses SMS Gateway that are of two types :
1. Promotional
2. Transactional
First one is used to broadcast SMS to multiple users at a time which take minimum 5-10 minutes of time to deliver SMS. Messages are sent through low priority gateways. You won't get unique Sender ID.
On the other hands , Transactional type SMS uses high priority network and also allow use of unique Sender ID.
Many Bulk SMS provider companies gives API to intregate with custom web and software application. Though implemention of SMS gateway API is simple but its quite tricky.
Checkout below code which demonstrate send multiple SMS on one click:


protected void Button5_Click(object sender, EventArgs e)
    {
       
        string[] strArray = sms.Split(new char[1]
      {
        ','
      });

        int count = strArray.Count();
        
        try
        {
           WebClient client = new WebClient();
            // Add a user agent header in case the requested URI contains a query.
            for (int i = 0; i < count; i++)
            {
                client.Headers.Add("user-agent", "Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
              baseurl = "http://login.redseo.in/API/SendMessage.ashx?user=test&password=0123&phone="+strArray[i]+"&text="+TextBox5.Text+"&type=t&senderid=TESTIN";
               
                 data = client.OpenRead(baseurl);
                 reader = new StreamReader(data);
                string s = reader.ReadToEnd();
            }
            data.Close();
            reader.Close();
           
            //return (s);
        }
        catch (Exception exc)
        {
            Label128.Text = "Failed.";
            
        }
    }
Read More

Thursday 27 March 2014

[Solved ] DateTime Conversion Problem in Dot Net C Sharp

Today, i am providing a custom Date Time Class that can be used to solve the issues related to Date Time Conversion problem in Dot Net. The code provided here is in C#. You can directly use this class in your project and call the related methods which is required.

Why Date Time Conversion problem occurs?


Different PCs have different Date and Time format based on choice and locale. In sql server, [datetime] type datatype always store Date and Time in yyyy-MM-dd HH:MM:SS.000 format. So if we try to insert Date other then this standard format, then sql server shows the error which says ,"Conversion from nvarchar/varchar data type to datetime data type failed." . So if you already use this standard format then you don't require Date Conversion class. Some we don't know what will be format of inpu date and time. In this case, use of following class code is very helpful:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;

/// <summary>
/// Summary description for DateTimeClass
/// </summary>
public class DateTimeClass
{
    //METHOD 1
    // use only when you want to convert any input time format to system time format
    // Both method parse only date seperator like [ - , / ] etc
    // IT NOT CONVERT MM/dd/yyyy to dd-MM-yyyy . it only convert dd/MM/yyyy to dd-MM-yyyy 
   
    DateTime dateTime;
   
    DateTime dtime;
    //get current date format
    string dateformat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
    //CALL WHEN YOU WANT TO CONVET INPUT DATE STRING INTO SYSTEM DATE STRING
    public string DTC(string input)
    {
     
         

        DateTime.TryParse(input , out dateTime);

        return dateTime.ToShortDateString();
       
    }

    public DateTime DTCC(string input)
    {



        DateTime.TryParse(input, out dateTime);

        return dateTime;

    }
    // CALL WHEN U WANT SYSTEM DATE TIME FORMAT
    public string DTF()
    {
        string input = DateTime.Now.ToString();

        DateTime.TryParse(input, out dateTime);


        return dateTime.ToShortDateString();

    }

    public string DTPE(string input)
    {
        string dtformat = "dd/MM/yyyy";

        CultureInfo cprovider = CultureInfo.InvariantCulture;

        return DateTime.ParseExact(input, dtformat, cprovider).ToString("dd/MM/yyyy");
     
     
    }


    //METHOD 2
    // use this function when you want to convert fixed input time format to system time format
    // this method parse date seperator like [ - , / ] etc
    // IT CAN CONVERT MM/dd/yyyy to SYSTEM DATE WHICH MAY BE IN dd-MM-yyyy TYPE FORMAT.
    // DATE TIME CONVERT FIXED INPUT DATE FORMAT
    public string DTCFF(string input)
    {

        dateTime = DateTime.ParseExact(input, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return dateTime.ToShortDateString();

    }

    // DATE TIME CONVERT FIXED INPUT DATE FORMAT
    public string DTCF()
    {
        string input = DateTime.Now.ToShortDateString();
        dateTime = DateTime.ParseExact(input, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return dateTime.ToShortDateString();

    }


    //DATE TIME  FIXED INPUT FORMAT 

    public string DTFF(DateTime sql)
    {

        sql = DateTime.ParseExact(sql.ToString(), "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return sql.ToShortDateString();
    }


    //BREAK SYSTEM DATE INTO DESIRED FORMAT
    public string DTN()
    {
        DateTime dt = DateTime.Now;
        string d1, m1, y1;
        d1 = dt.Day.ToString();
        m1 = dt.Month.ToString();
        y1 = dt.Year.ToString();


        return d1 + "/" + m1 + "/" + y1;
    }

    public string DTNN(DateTime dt)
    {

        DateTime dt1 = new DateTime();
        dt1 = dt.AddYears(1);
        DateTime dt3 = new DateTime();
        dt3 = dt1.AddDays(-1);
        string d1, m1, y1;
        d1 = dt3.Day.ToString();
        m1 = dt3.Month.ToString();
        y1 = dt3.Year.ToString();
        return d1 + "/" + m1 + "/" + y1;

    }

}

Read More

Tuesday 18 February 2014

Learn C# Programming

Learn basics of C# programming with us. C# is very popular language for development in Dot Net platform. It is simple and easy to learn programming language. I am writing series of posts on "Learn C# Programming". Here is complete syllabus :

1. Getting started
   1.1. Dot Net Framework
   1.2. Platform Advantage
   1.3. Platform Programming
   1.4. Development Environment Setup

2. Data and Data Types
   2.1. Variable and Constant Declaration
   2.2. Integer , Floating Point , Boolean
   2.3. Character , String and Array
   2.4. new operator and var keyword
   2.5. Type conversion

3. Operators
   3.1. Unary
   3.2. Binary
   3.3. Airthmatic
   3.4. Relational
   3.5. Increments and Decrements
 
4. Decision Making and Control Statement
   4.1. Conditional
   4.2. Looping
   4.3. Branching
   4.4. Jumping

5. OOP's Fundamentals
   5.1. Object
   5.2. Class
   5.3. Class Member and Methods
   5.4. Method Overloading
   5.5. Constructor
   5.6. Inheritance
   5.7. Abstract Class and Method
   5.8. Interface
   5.9. Partial Class
   5.10. Access Modifier

6. The Next Step  
   6.1. Delegates
   6.2. Events
   6.3. Generics
   6.4. Collection
   6.5. Exception Handling
   6.6. I/O Handling
   6.7. Threading
   6.8. Properties



Read More

Blogger