Dot Net Practical File
Dot Net Practical File
Dot Net Practical File
File
Of
DOT NET FRAMEWORK
1
Aim 1: Microsoft Visual Studio 2008
Installation
This Windows 7 tutorial is going to show how to install Visual Studio 2008 on Windows 7.
I'll install Microsoft Visual Studio 2008 Team Suite Edition on Microsoft Windows 7 Ultimate.
I had a clean install of Windows 7 on my new computer and I tried to install Visual Studio 2008
on Windows 7. I managed installing VS successfully with a simple and plain installation process.
I have an .iso file of the VSTS2008 Team Suite and extracted it on a folder. Within the extracted
folder the installation file is setup.exe install file.
When I double click to run the setup.exe file, the following User Account Control (UAC) screen
is asking me if I allow the setup.exe program to run.
Click "Yes" to continue with Visual Studio 2008 installation further on Windows 7.
2
The first screen in Visual Studio 2008 Setup is the below setup dialog screen.
Click the "Install Visual Studio 2008" link in order to start VS2008 on Windows 7 installation
process.
Microsoft Visual Studio Team System 2008 Setup wizard begins with the confirmation if you
want to help improve setup of Visual Studio 2008.
3
If you agree to submit anonymous information about your Visual Studio setup experiences to
Microsoft, mark the checkbox "Yes, send information about my setup experiences to Microsoft
Corporation."
The next screen in the VS 2008 setup wizard requests you to confirm that you have read and
accept the license terms.
You should also supply the Microsoft Visual Studio 2008 product key.
4
This step is which you select the Visual Studio 2008 features to setup. You have two quick
options first the default installation and the full installation.
5
Default installation will install common and recommended VS2008 features on the other hand
full installation will install all the features of MS Visual Studio 2008.
You can configure VS2008 installation in more detail by selecting the third option, Custom
installation.
The VS 2008 installation path is default "C:\Program Files\Microsoft\Visual Studio 9.0\" and
cannot be altered.
You can see the required disk space for each install option on the right bottom part of the setup
wizard.
6
The Microsoft VSTS 2008 installation process starts as seen in the below screenshot.
7
And the installation finished within one screenshot as you see here.
8
After the VS 2008 installation is completed successfully on Microsoft Windows 7 Ultimate
operating system, it is time for an update or installing the product documentation like help
documents, tutorials and samples, etc.
9
I will install MSDN documentation for VS2008 after installing service pack for VS2008
installation. I want to show you the below screenshot that I have installed the Visual Studio 2008
on my Windows 7 computer with its all features selected without any problem.
10
And here is the start page of the Microsoft Visual Studio Team System 2008 IDE with general
development settings is selected running successfully on Windows 7.
11
AIM2 : An Introduction to the .net framework?
The .NET Framework is an integral Microsoft Windows component designed to support next-
generation applications and services. Many fundamentals of the .NET Framework will be
familiar to developers who have worked in other object-oriented development environments.
Microsoft's .NET framework introduces a whole new way of programming the Microsoft
platform. Microsoft developers are primarily concerned with threads and memory (that's
basically the API programming model). This model carried over to all areas of development,
including Web development, placing a heavy burden upon programmers. .NET is built upon the
notion of managed types. Developers writing classic Windows code (and Web code) wrote
classes using C++ or Visual Basic. In many ways, types are similar to the notion of the C++ class
in that types are units of state with functionality attached to them. However, the similarity ends
there. Whereas it was incumbent upon the developer to manage instances of classes, types are
managed completely by the .NET runtime servicesthe Common Language Runtime (CLR).
Because the CLR takes over managing memory and threads, developers are much more at liberty
to concentrate on the actual application (rather than chasing down errant pointers, memory leaks,
and unexplained crashes).
ASP.NET introduces runtime services and a well-engineered class library for greatly enhancing
Web development. In a way, classic ASP was sort of taped onto the IIS/ISAPI architecture
without any real organic thought as to how early design decisions would affect developers later
on. Well, now it's later on and classic ASP.NET's warts have become fairly obvious.
Compiled code for executing application logic Configurable session state management
High-level components for managing data formatting (grids, lists, text boxes)
12
An easy-to-use custom authentication mechanism
ASP.NET 1.0 set the stage for many developers both moving into Web development and
moving to the Microsoft Platform.
ASP.NET 2.0 builds upon ASP.NET 1.0 and 1.1 by providing a number of new features in
addition to what already existed with ASP.NET 1.0. These features include
Declarative data-binding
Membership controls
Personalization controls
Programmable configuration
Administration tools
All the features of ASP.NET 1.0/1.1 are still there. However, these new features make
ASP.NET an even more compelling platform for creating Web sites.
ASP.NET 2.0 is built upon Microsoft's Common Language Runtime. In its earliest days,
programming Windows involved interacting with the operating system at a very intimate level.
For example, getting a Window to show up on a screen took many lines of C code. In addition,
Windows included a rudimentary component technologyraw Dynamic Link Libraries.
13
Dynamic Link Libraries (DLLs) represent a necessary technology to enable composing systems
dynamicallythat is, to assemble applications from several disparate binary components.
However, DLLs by themselves are not sufficient for composing systems reliablyprimarily
because it's very difficult to manage multiple versions of a component (a DLL).
During the mid-90's, the Component Object Model (COM) emerged as a way to help manage
multiple versions of a component. By stipulating strict rules about how clients and components
may interact, COM represented a technology sufficient for composing applications from
different binary components. However, COM faced a few dead ends which became apparent as
developers began building larger systems.
First, COM relied on humans following rules to get things to interoperate. For example, COM
stipulates a rule that once a programmatic interface is published, it must never change. Changing
a published COM interface after clients begin coding against it will almost certainly bring a
system to its knees. In addition, COM relied on sometimes obtuse rules as far as managing
resources. However, the coup de grace for COM was probably the disparate type systems
involved. That is, COM represented many data types differently for three separate classes of
developers: C++ developers, Visual Basic developers, and scripting developers. The different
data type systems made it extremely inconvenient to build systems built from different
languages. It could be done, but developers had to be very wary when making calls across such
component boundaries.
.NET and the Common Language Runtime (the CLR) were developed to solve the dead ends
appearing in COM near the end of the last century. When you choose to buy into the .NET
runtime, it's like putting your code in a nice hotel room when it runs. For example, the .NET
runtime loads and manages your code as it runs. Pure memory leaks are a thing of the past
because the runtime collects garbage when necessary. The problem of overrunning array
boundaries disappears because the .NET runtime keeps careful watch over memory and knows
when anything is out of place. In addition, the .NET runtime includes a new security model
making it more difficult to hack into .NET-based software. Finally, the .NET runtime introduces
a new packaging and deployment model, .NET Assemblies, which helps enforce versioning
components.
14
Figure 1: .net Framework
The top layer represents user and program interfaces, and includes Windows Forms, Web Forms,
Web Services, and Application Services. Windows Forms provide a Win32/64-based user
interface. Web Forms provide a Web-based user interface. Web Services are the most
revolutionary program interfaces because they allow programs to communicate over the Internet.
The Internet-based program interfaces, which include Web Forms and Web Services, are
implemented by ASP.NET, which is a built-in component of the .NET Framework.
The middle layer represents the .NET Framework classes, which are universally available across
multiple languages. The usage of these classes is consistent across all languages included in
the .NET Framework.
The base layer represents the common execution platform called the Common Language
Runtime (CLR). This is the most important component of the .NET Framework. The CLR
provides support for multiple languages and allows cross-language inheritance. For example, you
can inherit a class written in Visual Basic from a class written in Visual C++. Thus, with .NET,
the choice of a programming language simply depends on the user's choice. With .NET, it is
possible to create applications by using multiple languages. The multiple-language support is
possible because the CLR provides a common system of data types. In addition, the CLR
performs the memory management and monitors the complete life cycle of objects, while it
tracks objects and handles garbage collection.
Visual Studio .NET (VS.NET) is the first release of the products based on the .NET Framework.
It includes Visual Basic, Visual C++, and C#. VS.NET provides a common Integrated
Development Environment (IDE) for all languages. Therefore, developers always work in a
consistent environment irrespective of the language they use.
15
AIM 3: Familiar with the VS development environment.
Toolbox
Page Layout
Property window
Toolbox contains all the controls of the form. Just drag and drop the control from the
toolbox to the form.
Page Layout gives the design of the form appears at the run time.
16
AIM 4: Features of .NET
The following are major features of .NET.
Assemblies
An assembly is either a .DLL or .EXE that forms a part of an application. It contains MSIL code
that is executed by CLR. The following are other important points related to an assembly:
Assembly Manifest - Contains name, version, culture, and information about referenced
assemblies.
Resources - Files such as BMP or JPG file or any other files required by application..
Common Type System (CTS) specifies the rules related to data types that languages must follow.
As programs written in all languages are ultimately converted to MSIL, data types in all
languages must be convertible to certain standard data types.
CTS is a part of cross-language integration, which allows classes written in one language to be
used and extended by another language.
17
Cross-language Interoperability
.NET provides support for language interoperability. However, it doesn't mean every
program written in a language can be used by another language. To enable a program to
be used with other languages, it must be created by following a set of rules called Cross
Language Specifications (CLS).
Cross-language inheritance is the ability to create a class in C# from a class created in VB.NET.
When an exception is raised by a program written in C#, the exception can be handled by
VB.NET. This kind of exception handling is called cross-language exception handling.
.NET has brought a set of new features which are to be understood by every programmer
developing applications for Windows. There is no way any Windows programmer can
ignore.NET unless he is desperate to be outdated. Microsoft will provide.NET as part of its
operating systems in future releases. It is the platform for programmers. It is not new OS from
Microsoft or a new language. It is the environment for which you develop applications. It is rich
in terms of features.
18
AIM 5: Design a calculator with button and textbox
(with window forms)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace cal
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
string st = "";
string op = "";
float result;
19
}
20
textBox1.Clear();
}
21
Output:
22
AIM 6:To study Basic Window Controls
Button:
namespace button
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
TextBox:
23
Displays text entered at design time that can be edited by user at run time or changed
programmatically.
Combo Box:
24
Displays a drop down list of items. It is used to store multiple items but allows only
single selection.
2. RemoveAt: This method is used to remove items index wise i.e. from location.
comboBox1.Items.RemoveAt(1);
25
Both these methods will display the following output:
RadioButton:
Radio buttons are used for single selection only.
26
privatevoid button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
MessageBox.Show(radioButton1.Text);
}
elseif(radioButton2.Checked == true)
{
MessageBox.Show(radioButton2.Text);
}
else
{
MessageBox.Show("Please select a value");
}
}
27
Adding items to Checked List Box:
To add items in Check Box, Click on smart tag & select "Edit Items".
28
{
string st="";
for (Int32 i = 0; i < checkedListBox1.CheckedItems.Count; i++)
{
st += checkedListBox1.CheckedItems[i].ToString() + " ";
}
MessageBox.Show(st);
}
Displays a list of items and allow single as well as multiple selection. For multiple selection,
change the property "Selection Mode" of List box to "MultiSimple".
29
Items can be added in List box in the same way as Checked List Box.
listBox1.Items.Add("Maths");
30
Application project, depending on the programming language you want to use.A Web
Application project is always created on a Web server.
2. Select File >New > Website to open the New dialog box.
5. Specify the name of the computer where you want to create the application, in the
Location box if necessary, and click OK.A new Web Application project is displayed in the
designer window, as shown in figure below.
When you create a Web Application project, the Application Wizard creates the necessary
project files along with the page file and code behind class file as described:
31
Default.aspx: This page file consists of the user interface for the visual representation of the
Web Forms page. The file has two views, Design and HTML. The default view is Design
view.
Design view: This view represents the user interface for the Web Forms page. You
can place controls directly from the toolbox to the Web Forms page in Design view.
By default, the page layout of the Web Forms page is Grid Layout. This layout
enables you to accurately position controls on the page by using the absolute
coordinates (X,Y) of the page. In addition to Grid Layout, ASP.NET provides
another page layout, which is called Flow Layout. In Flow Layout, you can add text
to the page directly in Design mode. You can change the page layout from the default
Grid Layout to Flow Layout. To do so, right-click the page in Design view and select
Properties from the context menu. Next, in the DOCUMENT Property Pages dialog
box, from the Page Layout list box, select Flow Layout.
HTML view: This view represents the ASP.NET code for the Web Forms page. To
open HTML view, click the HTML tab in the designer. When the Web Application
project is a Visual Basic project or a C# project, the scripting language used in the
HTML page is Visual Basic or C#, respectively.
32
The Web form is only one of 11 files Visual Studio .NET generates when it creates a new
Web forms project. The purpose of each of these project files are described below.
Global.asax.vb
The code used in Global.asax. This file is not
shown in Solution Explorer.
Global.asax.cs
33
File name Contains
Projectname.vbproj.webinfo This file tracks the root virtual folder for the
Web application. This file is not shown in
Projectname.csproj.webinfo Solution Explorer.
34
File name Contains
The primary types of files that youll add to a Web application project are:
35
Code that defines objects in
.vb or .cs Class or module your application is stored in
classes.
36
Step 1:Go to the File> New Website > ASP.net website then name the website project
name.
Step2: Now drag the Textbox and Button from the toolbox to the web form.
Step3: Double click on the Button to navigate click event of the Button in coding page.
37
Working with ASP.NET validation server controls is no different from working with any
other ASP.NET server controls. Each of these controls allows you to drag and drop it onto a
design surface or to work with it directly from the code of your ASP.NET page. These
controls can also be modified so that they appear exactly as you wishensuring the visual
uniqueness that your applications might require.
The following table describes the functionality of each of the available validation server
controls.
Validation Causes:
Validation doesnt just happen; it occurs in response to an event. In most cases, it is a button
click event.The Button, LinkButton, and ImageButton server controls all have the capability
to cause a pages formvalidation to initiate. This is the default behavior. Dragging and
dropping a Button server control ontoyour form will give you the following initial result:
If you have multiple buttons on an ASP.NET page, and you dont want each and every button
to initiatethe form validation, you can set the CausesValidation property to False for all the
buttons you wantto ignore the validation process (for example, a forms Cancel button):
38
<asp:Button ID=Button1 Runat=server Text=Cancel CausesValidation=False />
At Design time:
Step 1: Place the text boxes and a button on the web form to implement the validation on them.
Step 2: Now drag the validation control on the web form Validation category from the toolbox.
39
RequiredFieldValidator Control to validate. <Textbox1>
At Run time: Debug the Web Form, Now when you press the button the validation will check
the data inputted is valid or not. If any violation of validation is there then it shows the error.
40
of COM interfaces that exposes a consumer/provider model of accessing data throughout an
enterprise. OLE DB makes no distinction as to whether the data is in a desktop database (like
Access), an enterprise database (like SQL Server or Oracle), or a non-database source (like an
Excel spreadsheet). If developers wanted to expose their data to OLE DB they needed to develop
an OLE DB provider. Unfortunately, development of OLE DB providers proved to be difficult
for all but the most talented C++ developers. Developing data consumers in OLE DB was much
simpler, but tied developers directly to Visual C++, therefore losing any language independence.
In the most recent past, Microsoft developed ActiveX Data Objects (ADO) as a COM wrapper
around OLE DB. ADO was developed specifically to make OLE DB easier to use. Soon after the
release of ADO, the Internet revolution exploded. Developers craved an easy-to-use API to make
their Web sites and Web applications database driven. ADO's script ability fit perfectly into
Microsoft's Internet Information Server (IIS) and Active Server Pages (ASPs). ADO soon
became the lingua franca of Internet Web sites. For small Web sites, ADO shined; it was easy to
understand and simple to code.
ADO.NET is a set of .NET classes that allow for the connection and manipulation of data. .NET
classes are separated into namespaces to help segment their specific functionality. In ADO.NET,
namespaces provide segregation between different parts of the managed provider model.
Command classes (SqlCommand for the SQL Managed Provider and OleDbCommand for the
OLE DB Managed Provider) can be used directly to retrieve results from database queries.
Command classes always support the IDbCommand interface, which can get a scalar result (the
first column of the first row of a result set) or out parameters of a stored procedure. This sort of
data is retrieved using IDbCommand.ExecuteScalar() and IDbCommand.ExecuteNonQuery().
DataReaders (SqlDataReader and OleDbDataReader) are classes that provide something similar
to ADO's Recordset using a forward-only cursor. In ADO, we need to be careful and make sure
we call MoveNext() and check for the end-of-record indicator. The DataReader uses a less error-
prone system that just requires that you read the current record into memory and check for the
end-of-record indicator in one step. For cases where you will need to simply get a query and
spew out the results, the DataReader is the perfect vehicle. In fact, Microsoft uses DataReaders
within the managed providers' DataAdapters to fill DataSet.
The DataSet looks much like an OLE DB RowSet or an ADO Recordset. The DataSet, however,
is much more than that. It is a complex data structure that allows for an in-memory
41
representation of almost any relational model. The DataSet holds a collection of tables that can
have optional DataRelations, Constraints, or even ForeignKeyConstraints.
Example:
At Design time:
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
if(!Page.IsPostBack)
42
bind();
adp.Fill(ds);
DetailsView1.DataSource=ds;
DetailsView1.DataBind();
43