Reading and Writing XML File
XML is an extensible markup language
XML is a text-based markup language that is fast becoming the standard for data interchange on the Web. HTML emphasis on presetation of data and XML emphasis on the Data itself. Like HTML, you identify data using tags (identifiers enclosed in angle brackets: (<…>). Collectively, the tags are known as markup. Each starting tag must have a closing tab. This is case sensitive, the opening and closing tags must match exactly and the data will come between the opening and the closing tags.
<sample> data </sample>
If there is no data i.e. empty tag then you can also write it as
<sample/>
if you are writing
<sample>
<data>this is data</data>
</sample>
this can also be written as
<sample data=”this is data”/>
where data is called an attribute and its values must be enclosed in inverted commas.
<!– This is a comment –>
sample xml file
<?xml version=’1.0′ encoding=’utf-8′?>
<!– A SAMPLE set of slides –>
<slideshow>
<title>c#</title>
<author>ajay</author>
<address>
<doorno>123</doorno>
<street>23</street>
</address>
<noofslides>1</noofslides>
</slideshow>
can also be written as
<?xml version=’1.0′ encoding=’utf-8′?>
<!– A SAMPLE set of slides –>
<slideshow title=”c#” author=”ajay” noofslides=”1″/>
You can use the dataset object to directly read or write xml files.
once the dataset has tables and data in it just call its writexml or writexmlschema method giving the name of the file to be created.
this will generate the xml/xmlschema automatically.
if you are having xml file then you can display its contents using dataset. call the dataset’s readxml method with the filename as the xmlfilename to be read.
New features of .NET 2 compared to .NET 1
There are several new language features in framework2. Some this are very usefull.
- Partial Class: Partial class will allow you to split a C# class into two or more source code files. This is very usefull to hiding the messy details you don’t need to see.
- Generics: Generic allow you to create classes that are flexible enough to work with different class types but still supports strong type checking.
- Anonymous methods: Anonymous methods allow you to define a block of code on the fly, inside another method. You can use this technique to quickly hook up an event handler.
- Iterators: Iterators give you an easy way to create classes that support enumeration, which means you can loop through the values they contain using the C# foreach ststement.
These are the main language specific features. Let us examine other features that are new ASP.NET2.
- Master Pages: Using Master Pages, you can define a template and reuse it effortlessly. Master pages ensure that every page in the web page have the same look and feel. Also maintenance become easy using master pages.
- Data Source Controls: New datasource controls
- Personalization:
- Security and Membership
- Rich Controls
- Webparts
- Administration
What are the new features of Framework 3 comapared to earlier framework?
What is difference of .net 3 Framework?
Essentials of Framework 1 and 2
NET Framework 3.0 is somewhat different from the 1.x and 2.0 .NET Framework. The first two .Net frameworks focused on allowing many different languages to communicate with a common set of libraries translated through the Common Language Runtime (CLR). Introduced with .NET 1.1 and enhanced with .NET 2.0, the CLR works on a relatively simple concept: A common runtime model executes code for any system running the .NET Framework. What this means to you as a developer is that you don’t need to keep relearning languages for different technologies. For instance, a C# developer who writes Windows Forms applications take the knowledge used for building forms and apply it to writing web pages. Similarly, a Visual Basic .NET developer can switch from writing mobile applications to writing web services. The CLR acts as an arbitrator and communicates back and forth.
.net Framework 3
The .NET 3.0 Framework is not improving upon existing technologies but rather introducing four new foundation technologies:
- Windows Presentation Foundation (WPF)
- Windows Communication Foundation (WCF)
- Windows Workflow Foundation (WWF)
- Windows CardSpace (WCS)
Each of these technologies is a new cornerstone that developers can leverage for new solutions.
Framework 3.5
.NET Framework 3.5 builds incrementally on the new features added in .NET Framework 3.0. For example, feature sets in Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF) and Windows CardSpace. In addition, .NET Framework 3.5 contains a number of new features in several technology areas which have been added as new assemblies to avoid breaking changes. They include the following:
- Deep integration of Language Integrated Query (LINQ) and data awareness. This new feature will let you write code written in LINQ-enabled languages to filter, enumerate, and create projections of several types of SQL data, collections, XML, and DataSets by using the same syntax.
- ASP.NET AJAX lets you create more efficient, more interactive, and highly-personalized Web experiences that work across all the most popular browsers.
- New Web protocol support for building WCF services including AJAX, JSON, REST, POX, RSS, ATOM, and several new WS-* standards.
- Full tooling support in Visual Studio 2008 for WF, WCF, and WPF, including the new workflow-enabled services technology.
- New classes in .NET Framework 3.5 base class library (BCL) that address many common customer requests.
.NET Framework History
- ms.net 1.0 : 2002
- -clr 1.0
- - c# 1.0
- - vb.net 1.0 (VB 7)
- - ASP.NET 1.0
- - VISUAL STUDIO 2002
- - WEB SERVICES
MS.NET 1.1 : 2003
- - CLR 1.1
- - C# 1.1 , VB.NET 1.1 ASP.NET 1.1
- - VISUAL STUDIO 2002
- - WEB SERVICE ENHANCEMENTS
MS.NET 2.0 : 2005
- - CLR 2.0
- - C# 2.0, VB.NET 2.0 ASP.NET 2.0
- - VISUAL STUDIO 2005
- - AJAX 1.0
Caching in ASP.net with examples
Caching is used to inprove the performance of our application.
normally caching is enabled on the pages which are requested a lot and for which some cached responce can be given. you can control how long the cached responce should be valid and after the time out the cache page should be removed.
There are three types of caching
- page caching(also called output caching)
- fragment cache
- data cache
Page caching
to enable page caching add the following tag in the html view of the page
<%@ OutputCache Duration=”50″ VaryByParam=”None” %>
sometimes the same page will be asked with varying parameters say list of employees belonging to a particular department
for this use the vary by param attribute of the output cache directive
try giving deptno in varybyparam attribute and then when checking the page in browser attach ?deptno = 1 to the url and check
later change it to deptno = 2
you will get various versions of the same page depending on the deptno, each version valid for 50 seconds from the time of its creation.
Fragment caching
create a user control and enable output caching for that control. when this control is placed on a page contents of this control will be comming from cache where as the remaining page will be refreshed so here as only some part of the page is comming from cache it is called fragment cache.
for crating user control, in the solution explorer right click and add new item select web user control and click add.
drag a lable contorl on it and in the source view i.e. html view type the output cache directive
<%@ OutputCache Duration=”50″ VaryByParam=”None” %>
in the load event of the control type the code
label1.Text =DateTime.Now.TimeOfDay.ToString();
now on any page this control is used this will be served from the cache for 50 secs.
Data Caching
Cache["Key"] = value;
cache["name"] = “Hello”;
string st = (string)Cache["name"];
cache["age"] = 10;
int age = (int)Cache["age"];
you can attach the time of expiration and dependencies to data caching