.net
.net
.net
Net History
Microsoft started development of the .NET Framework in the late 1990s, originally under the name of Next Generation
Windows Services (NGWS). By late 2000 the first beta versions of .NET 1.0 were released.
The C# programming language was developed with the .NET Framework by Anders Hejlsberg, Scott Wiltamuth, and
Peter Golde and was first available in July 2000.
These are the versions of C# and .Net framework:
C# 1.0; released with .NET 1.0 and VS2002 (January 2002).Contained the first version CLR and base class
libraries
C# 1.2 ; released with .NET 1.1 and VS2003 (April 2003). First version to call Dispose on IEnumerators which
implemented IDisposable.Included updates to ASP.NET and ADO.NET. Introduced side-by-side execution, which
enables apps on a single computer to run against multiple versions of the CLR.
C# 2.0; released with .NET 2.0 and VS2005 (November 2005). Major new features: generics, nullable types
C# 3.0; released with .NET 3.5 and VS2008 (November 2007). Major new features: lambda
expressions(=>),LINQ , implicit typing (var), query expressions
C# 4.0; released with .NET 4 and VS2010 (April 2010). Major new features: Dynamic language run-time,
parallel computing, named arguments and optional parameters
C# 5.0; released with .NET 4.5 and VS2012( August 2012).Major new features: asynchronous file operations
and improved on parallel computing.
4.5.1 Preview with Visual Studio 2013 Preview. Includes performance and debugging improvements, support for
automatic binding redirection, and expanded support for Windows Store apps.
The .NET Framework is a technology that supports building and running the next generation of applications and XML
Web services. The .NET Framework is designed to fulfill the following objectives:
Provide a runtime environment that simplifies software deployment and reduces the chances of version conflicts.
Enable the safe execution of code.
Use industry standards for all communication to enable integration with non-.NET code.
Provide a consistent developer experience across all types of applications in a way that is language- and platform-
independent.
Provide a runtime environment that minimizes or eliminates the performance problems of scripted or interpreted
languages.
Terminoly:.NET enabled Microsoft's marketing people to emphasise the "Network"-ing aspect of its technologies, and
was also a reaction to the marketing blitz by Sun Microsystems in the late 1990s whose theme was "The network is the
computer". The term "Dot-Com" was synonymous with the Internet that time, and "Dot-NET" was a play on that term.
.Net architecture
This library is categorized into different modules and can access to Windows application, Web development, Network
programming ,IO etc.
Common Type System(CTS)
CTS define how types are declared, used and managed in the CLR, and is also an important part of the runtime's support
for cross-language integration. The common type system performs the following functions:
Establishes a framework that helps enable cross-language integration, type safety, and high-performance code
execution.
Provides an object-oriented model that supports the complete implementation of many programming
languages.
Defines rules that languages must follow, which helps ensure that objects written in different languages can
interact with each other.
Provides a library that contains the primitive data types (such as Boolean, Byte, Char, Int32, and UInt64) used in
application development.
This makes it possible for the 2 languages to communicate with each other by passing/receiving parameters to and
from each other. A type is a representation of data(such as int).
All types in the .NET Framework are either value types or reference types.
It is a subset of the CTS. The CLS establishes the minimum set of rules to promote language interoperability.
When there is a situation to communicate Objects written in different .Net Complaint languages , those objects must
expose the features that are common to all the languages . Common Language Specification (CLS) ensures complete
interoperability among applications, regardless of the language used to create the application.
Microsoft has defined CLS, which are nothing but guidelines, that language should follow so that it can communicate
with other .NET languages in a seamless manner.
Advantages
Supports fully managed code.
Fully integrated IDE available.
WPF and WCF are the new way of buildign UI's and Communicating between processes and systems.
Linux and Mac support through 3rd parties (Mono).
Many languages available, both dynamic (IronPython and IronRuby) and static (C#, VB.NET, C++), both object oriented
(C#, VB.NET, C++) and functional (F#).
Interoperability: Now developers of different languages can work easily together on the same project.
Disadvantages
- Multi platform support isn't available from MS and isn't available straight after installing Visual Studio
- Managed code can be slower than native code
Structured programming is a logical programming method that is considered a precursor to object-oriented programming
(OOP). Structured programming facilitates program understanding and modification and has a top-down design approach,
where a system is divided into compositional subsystems(developers map out the overall program structure into separate
subsections.).
Structured programming (sometimes known as modular programming ) is a subset of procedural programming that
enforces a logical structure on the program being written to make it more efficient and easier to understand and modify.
such as Ada and Pascal are designed with features that encourage or enforce a logical program structure.
A defined function or set of similar functions is coded in a separate module or sub-module, which means that code can be
loaded into memory more efficiently and that modules can be reused in other programs.
Program flow follows a simple hierarchical model. These are sequence, selection, and repetition:
Real-world entities of problem represent as an object. Objects are instances of classes. It is a technique to think real world
in terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide
services to application or other objects.
The four primary concepts of object-oriented programming are encapsulation, abstraction, inheritance, and polymorphism.
Class
Classes are special kinds of templates from which we can create objects.A class describes all the attributes of objects, as
well as the methods that implement the behavior of member objects. It is a comprehensive data type, which represents a
blue print of objects. Each object contains data and methods to manipulate and access that data.
Object
An object can be considered a "thing" that can perform a set of related activities.
Encapsulation: the wrapping up of data and function into a single unit(class) is called encapsulation.
Data is not accessible to the outside world and functions which are wrapped in the class can access it. Function provide
interface between the object’s data and the program. This insulation of data from direct access by program is called data
hiding.
Abstraction:refers for representing essential features without including the background details of explanations.
Inheritance: is the process by which objects of one class acquire properties of objects of another class
Polymorphism:means one name ,multiple forms
C#
C# is an object-oriented language and fully supports the object-oriented programming concepts of inheritance,
polymorphism, encapsulation, and abstraction.
It is similar to c++ and Java. C# code is made up of a series of statements, each of which is terminated with a semicolon.
C# is a block-structured language, meaning that all statements are part of a block of code. These blocks which are
delimited with curly brackets({}), may contain any number of statements, or none at all.
C# code is case-sensitive.
C# is a general-purpose, object-oriented, type-safe programming language
`There were two ways of commenting C# code. (//, /*….*/ and special comment ///).
used for writing applications of any type.
#region and #endregion keywords, which defines the start and end of a region of code that can be expanded and collapsed.
# is actually preprocessor directive
Using keyword allow to access the all classes of “System” namespace
Simple Types
Int, long, byte, float, char, bool, string
Variable and Function declaration
<accessibility_level><type><variable_name>;
Example
int a=2;
string myString;
<accessibilityLevel><returnType><functionName>(paramType paramName, . . . . . . )
{
Logic here
}
Example
public int Sum(int a, int b)
{
Return a+b;
}
Naming Conventions
Generally two naming conventions in .Net Framework
PascalCase and camelCase
Private viables(fields of class)name are generally in camelCase
age, firstName
Methods and public varibles name are generally inPascalCase
Above example. We can call function Sum()
Escape sequence(\)
String myString=”\”myInteger\” is “; if you myString=””myInteger” is “ then compiler error
\’ single quotation mark
\n new line
\t horizontal tab
\\ backslash
“C:\\MyDocument\\MyFile.doc”
@“C:\MyDocument\MyFile.doc”
String formatting
MessageBox.Show(string.Format(“{0} {1}.”, myString, myInteger));
String is actually template into which you insert the contents of variables. Each set of curly brackets in the string is a
placeholder. The integers start at 0 and are incremented by 1 and numbers of varibales are separated by comma. Each
placeholder is replaced by the corresponding value for each variable. In above example,{0} is replaced by value of
myString and {1} is replaced by value of myInteger
Namespace
Way of providing containers for application code. We can define sub namespace within parent namespace.
namespace CosMos
{
Code here
}
Assignment operators
var1 +=var2; var1 is assigned value that is the sum of var1 and var2. Similarly for other operators(-,*,/,%)
Flow Control
Controlling program flow(order of execution of lines of C# code)
Branching:execute code conditionally, depending on the outcome of an evaluation.
Looping: repeatedly executing the same statements.
Boolean Logic:bool types are used to store the result of a comparison.
var1=! var2 var1 is assigned value true if var2 is false(Logical NOT).
var1=var2&&var3 var1 is assigned value true if var2 and var3 are both true.
var1=var2||var3 var1 is assigned value true if either var2 or var3 are true.
Branching
The ternary operator
The if statement
The switch statement
Ternary operator
<test> ? <resultIfTrue> : <resultIfFlase>
Eg.string str=(myInteger<10) ? “Less than 10” : “Greater than or equal to 10”;
Interrupting Loops
breake: Causes the loop to end immediately.
continue:Cauesed the current loop cycle to end immediately(execution continues with the next loop cycle)
return: Jumps out of the loop and its containinfuction.
goto: allows jumping out of a loop to a labeled position(generally not used)
Type Conversion
Convert.ToInt32(val) val converted to int
Convert.ToDecimal(val) val converted to decimal
Convert.ToString(val) val converted to string
Declaring Arrays
<baseType>[ ] <name>;
Eg.int[] myIntArray;
string[ ] friendNames={“Ram ”,”Hari”,”Sita”}
Foreach loops
foreach(<baseType><name> in <array>)
{
// can use <name> for each element
}
Eg.
string[ ] friendNames={“Hari”,”Ram”,”Sita”} ;
foreach(stringfriendName in friendNames)
{
MessageBox.Show(friendName);
}
String Manipulation
Reference Parameter
Void ShowDouble(ref intval):unassigned variable is illegal
Void ShowDouble(out intval): unassigned variable is legal
Overloading functions
Same function name with different signature that means same function name but different in paramete type or number of
parameters
//overloaded functions
int sum;
decimal dsum;
public void Add(inta,intb)
{
sum = a+b;
}
public void Add(decimala,decimalb)
{
dsum = a+b;
}
Complex Variable Types
Enumerations:Variable types that have a user-defined discrete set of possible values that can be used in a
human-readable way
An enum is a special "class" that represents a group of constants (unchangeable/read-only variables).
To create an enum, use the enum keyword (instead of class or interface), and separate the enum items with a
comma:
Structures:Composite variable types made up of a user-defined set of other variable types
Arrays: Types that hold multiple variables of one type, allowing index access to the individual values.
Defining Enumerations
enum typeName
{
value1,
value2,
value3
}
typeName varName=typeName.value;
eg.
enum Orientation
{
north=1,
south=2,
east=3,
west=4
}
Orientation myDirection=Orientation.north;
Defining Structs
struct<typeName>
{
<memberDeclarations> this contain <accessibility><type><name>
}
Eg.
struct route
{
public orientation direction;
public double distance;
}
Classes and Objects
Classes and structs have members that represent their data and behavior. Those members include:
Fields
Fields are instances of objects that are considered part of a class, normally holding class data. For example, a calendar
class may have a field that contains the current date.
public class CalendarDate
{
publicintmonth;
}
Properties
A property can provide protection for a class field to keep it from being changed without the object's knowledge.
publicclassPerson
{
//classic way of defining a property
private string _FirstName;
public string FirstName
{
get{return_FirstName;}
set{_FirstName = value;}
}
//simple/compact way of defining a property with get/set operations //internally/implicitly maintains a private variable
publicstringLastName { get; set; }
Methods
Are used to give access to functionality of object .Methods define the actions that a class can perform. Method can take
parameters that provide input data, and can return output data through parameters. Methods can also return a value
directly, without using a parameter.
Events
Events are a way of providing notifications about occurrences, such as button clicks or the successful completion of a
method, to other objects. Events are defined and triggered using delegates.
Constructors
A constructor has the same name as the class .Class have internally default constructor and we can also define constructor.
public class Student
{
//Constructor without parameter:
public Student() { }
public Student(int ID) { }
}
// object instantiation
StudentobjStudent = newStudent();
Methods type
static: accessible through class name. not the object instance.
virtual:Method may be overridden in derived class.
abstract:Method must be overridden in non-abstract derived class(permitted only on abstract class).
override: Method overrides a base class method.
Partial classes
Many developers need access to the same class, then having the class in multiple files can be beneficial. The partial
keywords allow a class to span multiple source files.
There are some rules for defining a partial class as in the following;
A partial type must have the same accessibility.
Each partial type is preceded with the "partial" keyword.
If the partial type is sealed or abstract then the entire class will be sealed and abstract.
Eg.
public partial class partialclassDemo
{
}
Static classes
A static class is declared using the "static" keyword. If the class is declared as static then the compiler never creates an
instance of the class. All the member fields, properties and functions must be declared as static and they are accessed by
the class name directly not by a class instance object.
public static class staticDemo
{
//static fields
public static int a=10,b=15,sum;
//static method
public static void Add()
{
sum =a+b;
}
}
//function calling directly
staticDemo.Add();
Abstract Classes
C# allows both classes and functions to be declared abstract using the abstract keyword. We can't create an instance of an
abstract class. An abstract member has a signature but no function body and they must be overridden in any non-abstract
derived class.//abstract class
public abstract class Employess
{
//abstract method with no implementation
public abstract void displayData();
}
//derived class
public class test :Employess
{
//abstract class method implementation
public override voiddisplayData()
{
Console.WriteLine("Abstract class method");
}
}
Sealed Classes
Sealed classes cannot be inherited. You can create an instance of a sealed class. A sealed class is used to prevent further
refinement through inheritance.
sealed class SealedClass
{
void myfunv();
}
public class test :SealedClass//wrong. will give compilation error
{
}
publicclassEmployee : Person //"Employee" class, now contains all properties of "Person" class
{
publicintEmployeeID { get; set; }
//the "FirstName" and "LastName" properties in "Person" classare automatically carried into this class.
}
Employee objEmployee = newEmployee();
objEmployee.EmployeeID = 100;
objEmployee.FirstName = "Ram";
objEmployee.LastName = "Shreshtha";
Multiple Inheritance
Multiple inheritance in .NET framework cannot be implemented with classes, It can only be implemented with interfaces.
Interface
An interface is a set of related functions that must be implemented in a derived class. Members of an interface are
implicitly public and abstract. Interfaces are similar to abstract classes. First, both types must be inherited; second, you
cannot create an instance of either.
It is used to achieve multiple inheritance which can't be achieved by class. An interface is a completely "abstract class",
which can only contain abstract methods and properties
Using interface-based design concepts provides loose coupling, component-based programming, easier maintainability,
makes your code base more scalable and makes code reuse much more accessible because the implementation is separated
from the interface. Interfaces add a plug and play like architecture into your applications.
Although there are several differences as in the following;
An Abstract class can contain some implementations but an interface can't.
An Interface can only inherit other interfaces but abstract classes can inherit from other classes and interfaces.
An Abstract class can contain constructors and destructors but an interface can't.
An Abstract class contains fields but interfaces don't.
interfaceIControl
{
void Paint();
}
interfaceISurface
{
void Paint();
}
classSampleClass :IControl, ISurface
{
// BothISurface.Paint and IControl.Paint call this method.
publicvoid Paint()
{
}
}
Polymorphism
Polymorphism is the ability to treat the various objects in the same manner. It is one of the significant benefits of
inheritance. We can decide the correct call at runtime based on the derived type of the base reference. This is called late
binding.
public abstract class Employee
{
public virtual void LeaderName()
{
}
}
public class hrDepart :Employee
{
public override void LeaderName()
{
Console.WriteLine("Mr. jone");
}
}
public class itDepart : Employee
{
public override void LeaderName()
{
Console.WriteLine("Mr. Tom");
}
}
hrDepart obj1 = new hrDepart();
itDepart obj2 = new itDepart();
obj1.LeaderName();
obj2.LeaderName();
Windows Form
We can create a userinterface by dragging and dropping controls from a toolbox to your form
Common controls
Controls for displaying information to the user, such as the Label and LinkLabel controls.
Controls for triggering events, such as the Button control.
Controls tha allow you to have the user of you application enter text, such as the TextBox control.
Controls that allow you to inform the user of the current state of the application and allow the user to change that state,
such as RadioButton and CheckButton controls.
Controls that allow you to display lists of information, such as the ListBox and ListView controls.
Controls that allow you to group other controls together, such as the Groupbox.
Menu control.
Properties
All controls have a number of properties that are used to manipulate the behavior of the control.
Name Description
Enabled Set to true usually means that control can receive input form user.
Name The name of the control. This name can be used to reference the control in code
Text This holds the text that is associated with this control.
Visible Specifies whether or not the control is visible at runtime
Events
Events generated by Windwos Form controls.These events are usually associated with the actions of the user. Example
when user clicks or presses a button, that button generates an event.
Click:Occurs when control is clicked. Sometime, this event will also occur when user press the Enter key.
MouseMove: Occurs continually as the mouse travels over the control.This event will also occur when a user presses the
Enter key.
What is an Exception
An exception is an error condition or unexpected behavior encountered by an executing program during runtime.
What is Exception Handling
Exception handling is an in built mechanism in .NET framework to detect and handle run time errors.
Exceptions are handled in C# using the 'try/catch/finally' statements.
Finally block is executed in every time.
Exceptions can be explicitly generated by a program by using the throw keyword.
try
{
// this code may cause an exception. If it does cause an exception, the execution will not continue.
// Instead,it will jump to the 'catch' block.
}
catch (Exception ex)
{
// I get executed when an exception occurs in the try block. Write the error handling code here.
thrownewException("Customise error message");
}
finally
{
//Release resources.For example to close any streams or files that were opened in the try block.
}
Delegate
A delegate is a type that enables you to store references to functions. Delegates are declared much like functions, but with
no function body and using the delegate keyword. The delegate declaration specifies a function signature consisting of a
return type and the parameter list.
Eg.
delegate double MyDelegate(double param1, double param2);
static double Add(double param1, double param2)
{
return param1 + param2;
}
static double Subtract(double param1, double param2)
{
return param1 - param2;
}
MyDelegate md;
if(input==”M”)
md=new MyDelegate(Add);
else
md=new MyDelegate(Subtract);
double d= MyDelegate(3,4)
What is HTML
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
ASP
Active Server Pages (ASP), also known as Classic ASP or ASP Classic, was Microsoft's first server-side script engine for
dynamically generated web pages.The use of ASP pages with Internet Information Services (IIS).
<html>
<head>
<title>The current time</title>
</head>
<body>
The server's current time:<br />
<%
Response.WriteNow()
%>
</body>
</html>
ASP.NET
ASP.NET is a server-side Web application framework designed for Web development to produce dynamic Web pages. It
was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services.
ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web
applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET
applications you have access to classes in the .NET Framework.
ASP.NET Page Life-Cycle Events
PreInit
Raised after the start stage is complete and before the initialization stage begins.
Use this event for the following:
• Check the IsPostBack property to determine whether this is the first time the page is being processed. The
IsCallback and IsCrossPagePostBack properties have also been set at this time.
• Create or re-create dynamic controls.
• Set a master page and Theme dynamically.
• Set initialization.
If the request is a postback, the values of the controls have not yet been restored from view state. If you set a control
property at this stage, its value might be overwritten in the next event.
Init
Raised after all controls have been initialized and any skin settings have been applied. The Init event of individual
controls occurs before the Init event of the page. Use this event to read or initialize control properties.
PreLoad.
Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with
the Request instance.
Load
The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control
until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page.
Use the OnLoad event method to set properties in controls and to establish database connections.
PreRender
Raised after the Page object has created all controls that are required in order to render the page, including child controls
of composite controls. The Page object raises the PreRender event on the Page object, and then recursively does the same
for each child control. The PreRender event of individual controls occurs after the PreRender event of the page.
Use the event to make final changes to the contents of the page or its controls before the rendering stage begins.
Render
It’s now time to send the output to the browser. If you would like to make some changes to the final HTML which is
going out to the browser, you can enter your HTML logic here.
This is not an event; instead, at this stage of processing, the Page object calls this method on each control. All ASP.NET
Web server controls have a Render method that writes out the control's markup to send to the browser.
If you create a custom control, you typically override this method to output the control's markup. However, if your custom
control incorporates only standard ASP.NET Web server controls and no custom markup, you do not need to override the
Render method.
Unload
Raised for each control and then for the page. Page object is unloaded from the memory.
In controls, use this event to do final cleanup for specific controls, such as closing control-specific database connections.
For the page itself, use this event to do final cleanup work, such as closing open files and database connections, or
finishing up logging or other request-specific tasks.
ASP.NET - Server Controls
Types of server controls:
Introduction to ADO.NET
ADO.NET is an object-oriented set of libraries that allows you to interact with data sources. Commonly, the data source is
a database, but it could also be a text file, an Excel spreadsheet, or an XML file
Data Providers
ADO.NET allows us to interact with different types of data sources and different types of databases. Since different data
sources expose different protocols, we need a way to communicate with the right data source using the right protocol .
ADO.NET provides a relatively common way to interact with data sources, but comes in different sets of libraries for each
way you can talk to a data source. These libraries are called Data Providers and are usually named for the protocol or data
source type they allow you to interact with.
Table 1. ADO.NET Data Providers are class libraries that allow a common way to interact with specific data sources or
protocols. The library APIs have prefixes that indicate which provider they support.
Provider Name API prefix Data Source Description
ODBC Data Provider Odbc Data Sources with an ODBC interface. Normally older data bases.
OleDb Data Provider OleDb Data Sources that expose an OleDb interface, i.e. Access or Excel.
Oracle Data Provider Oracle For Oracle Databases.
SQL Data Provider Sql For interacting with Microsoft SQL Server.
ADO.NET Objects
SqlDataReader Object
The SqlDataReader object is a simple forward-only and read-only cursor. It requires a live connection with the data source
and provides a very efficient way of looping and consuming all or part of the result set. This object cannot be directly
instantiated. Instead, you must call the ExecuteReader method of the Command object to obtain a valid DataReader
object. When using a DataReader object, be sure to close the connection when you are done using the data reader. If not,
then the connection stays alive.
Example:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlDataReaderMyReader;
SqlConnectionMyConnection = new
SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
SqlCommandMyCommand = new SqlCommand();
MyCommand.CommandText = "SELECT * FROM Student";
MyCommand.CommandType = CommandType.Text;
MyCommand.Connection = MyConnection;
MyCommand.Connection.Open();
MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection);
gvCustomers.DataSource = MyReader;
gvCustomers.DataBind();
MyCommand.Dispose();
MyConnection.Dispose();
}
}
The SqlDataAdapter class also provides a method called Fill(). Calling the Fill() method automatically executes the
command provided by the SelectCommand property, receives the result set, and copies it to a DataTable object.
DataSet
DataSet objects are in-memory representations of data. They contain multiple Datatable objects. The DataSet is
specifically designed to help manage data in memory and to support disconnected operations on data
DataTable
The DataTable object represents a logical table in memory. It contains rows(DataRow), columns(DataColumn), primary
keys, constraints, and relations with other DataTable objects.
Example:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataSetMyDataSet = new DataSet();
SqlConnectionMyConnection = new
SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
SqlCommandMyCommand = new SqlCommand();
MyCommand.CommandText = "SELECT TOP 5 * FROM CUSTOMERS";
MyCommand.CommandType = CommandType.Text;
MyCommand.Connection = MyConnection;
SqlDataAdapterMyAdapter = new SqlDataAdapter();
MyAdapter.SelectCommand = MyCommand;
MyAdapter.Fill(MyDataSet);
gvCustomers.DataSource = MyDataSet.Tables[0];
gvCustomers.DataBind();
MyAdapter.Dispose();
MyCommand.Dispose();
MyConnection.Dispose();
}
}
SqlParameter
To add parameter/s in queriesusingSqlParameter class and providing it thenecessary information, such as parameter name,
value, type, size, direction, and so on.
State Management
View State
View state is the method that the ASP.NET page framework uses to preserve page and control values between round trips
View state is used automatically by the ASP.NET page framework to persist information that must be preserved between
postbacks.
ViewState["UserId"]=1
int userId=(int)ViewState["LanguageId"]
Cookies
ASP.NET includes two intrinsic cookie collections. The collection accessed through the Cookies collection of
HttpRequest contains cookies transmitted by the client to the server in the Cookie header. The collection accessed through
the Cookies collection of HttpResponse contains new cookies created on the server and transmitted to the client in the Set-
Cookie header.
After you add a cookie by using the HttpResponse.Cookies collection, the cookie is immediately available in the
HttpRequest.Cookies collection, even if the response has not been sent to the client.
HttpCookie objcook = newHttpCookie ("username", txtUserName.Text);
objcook.Expires = DateTime.Now.AddDays(7);
Response.Cookies.Add(objcook);
string username= Request.Cookies["username"].Value
Query Strings
A query string is information that is appended to the end of a page URL
http://www.cosmos.com/editstudent.aspx?id=100
Introduction to XML
XML stands for EXtensible Markup Language
XML is designed to transport and store data.
XML tags are not predefined. You can define your own tags
The Difference between XML and HTML
XML was designed to transport and store data, with focus on what data is
HTML was designed to display data, with focus on how data looks
Example
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
Well Formed XML Documents
A "Well Formed" XML document has correct XML syntax.
The syntax rules were described in the previous chapters:
XML documents must have a root element
XML elements must have a closing tag
XML tags are case sensitive
XML elements must be properly nested
XML attribute values must be quoted
Namespace: System.Xml
Classes: XmlDocument, XmlElement, XmlNode
XmlDocument objDoc = new XmlDocument();
objDoc.Load(HttpContext.Current.Server.MapPath("~/students.xml"));
Once you have the Graphics reference, you can call any of this class's members to draw various objects. Here are some of
Graphics class's methods:
Graphics Objects
After creating a Graphics object, you can use it draw lines, fill shapes, draw text and so on. The major objects are:
The Brush class is an abstract base class and cannot be instantiated. We always use its derived classes to instantiate a
brush object, such as SolidBrush, TextureBrush, RectangleGradientBrush, and LinearGradientBrush.
// Cleanup
g.Dispose();
oCanvas.Dispose();
}
Reflection
Reflection is able to find out details of an object, method, and create objects and invoke methods at runtime. The
System.Reflection namespace contains classes and interfaces that provide a managed view of loaded types, methods,
and fields, with the ability to dynamically create and invoke types. Programmer can use typeof operator to get the
object's type of the current instance.
Microsoft Windows services enable us to create long-running executable applications that run in their own Windows
sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do
not show any user interface.
We can then use the Services Control Manager to start, stop, pause, resume, and configure your service.
Using Microsoft Visual Studio or the Microsoft .NET Framework SDK, We can easily create services by creating an
application that is installed as a service. This type of application is called a Windows service. With framework features,
you can create services, install them, and start, stop, and otherwise control their behavior.
Threading
A thread is a sequence of instructions executed within the context of a process. MultiThreading is achieved when a
program uses multiple execution threads allowing each thread to share the CPU concurrently depending on the priority
assigned to these threads. This helps in the optimum usage of System Resources.
Namespace: System.Threading
Thread.Sleep(60000);//in mimiseconds
using System;
usingSystem.Threading;