<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Trek Innovations &#187; ASP.NET</title>
	<atom:link href="http://www.trekinnovations.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.trekinnovations.com</link>
	<description>Thoughts For You</description>
	<lastBuildDate>Wed, 10 Feb 2010 13:59:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Regular Expression To Allow only 2 Decimal Places in the Textbox Control</title>
		<link>http://www.trekinnovations.com/2009/08/regular-expression-to-allow-only-2-decimal-places-in-the-textbox-control/</link>
		<comments>http://www.trekinnovations.com/2009/08/regular-expression-to-allow-only-2-decimal-places-in-the-textbox-control/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 09:31:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[Validation]]></category>
		<category><![CDATA[Validation Expression]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=305</guid>
		<description><![CDATA[Regular Expression To Allow only 2 Decimal Places in the Textbox Control :
In order to allow only 2 decimal places in the textbox use the regular expression validator. In the validator control there will be a property called ValidationExpression,use this property to assign the valid expression as shown below.
 
&#60;asp:TextBox ID=&#8221;_tbCost&#8221; runat=&#8221;server&#8221; TabIndex=&#8221;4&#8243;&#62;&#60;/asp:TextBox&#62;
 
&#60;asp:RegularExpressionValidator ID=&#8221;_ReqExpressionPhoneNo&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><strong><span style="font-size: 14pt;" lang="EN-GB">Regular Expression To Allow only 2 Decimal Places in the Textbox Control :</span></strong></p>
<p class="MsoNormal"><span lang="EN-GB">In order to allow only 2 decimal places in the textbox use the regular expression validator. In the validator control there will be a property called ValidationExpression,use this property to assign the valid expression as shown below.</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">asp</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">:</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">TextBox</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_tbCost&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">TabIndex</span><span style="color: blue;">=&#8221;4&#8243;&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">asp</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">:</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">RegularExpressionValidator</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ReqExpressionPhoneNo&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">ErrorMessage</span><span style="color: blue;">=&#8221;Enter numbers &amp; &#8216;.&#8217; only,should contain only 2 decimal places.&#8221;</span> <span style="color: red;">ControlToValidate</span><span style="color: blue;">=&#8221;_tbCost&#8221;</span> <span style="color: red;">Display</span><span style="color: blue;">=&#8221;none&#8221;</span> <span style="color: red;">ValidationExpression</span><span style="color: blue;">=&#8221;(?!^0*$)(?!^0*\.0*$)^\d{1,18}(\.\d{1,2})?$&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">&lt;/</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">asp</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">:</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: #a31515;">RegularExpressionValidator</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">&gt;</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span><span id="more-305"></span></p>
<p class="MsoNormal"><span lang="EN-GB">This is the expression that allows only 2 decimal places</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: red;">ValidationExpression</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">=&#8221;(?!^0*$)(?!^0*\.0*$)^\d{1,18}(\.\d{1,2})?$&#8221;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;"> </span></p>
<p class="MsoNormal"><span lang="EN-GB">And also for more information on regular expressions see the below link:</span></p>
<p class="MsoNormal"><span lang="EN-GB"> </span></p>
<p class="MsoNormal">Also look at: <a href="http://regexlib.com/Search.aspx?k=decimal&amp;c=-1&amp;m=-1&amp;ps=20">http://regexlib.com/Search.aspx?k=decimal&amp;c=-1&amp;m=-1&amp;ps=20</a></p>
<p class="MsoNormal">
<p class="MsoNormal">Happy Coding……………</p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2009/08/regular-expression-to-allow-only-2-decimal-places-in-the-textbox-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Export NestedGridView To Excel</title>
		<link>http://www.trekinnovations.com/2009/04/export-nestedgridview-to-excel/</link>
		<comments>http://www.trekinnovations.com/2009/04/export-nestedgridview-to-excel/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 11:24:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Export NestedGridview to Excel]]></category>
		<category><![CDATA[NestedGridview]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=299</guid>
		<description><![CDATA[In order to export the nested gridview please follow the code below.
SalesReport.Ascx
&#60;%@ Control Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; Codebehind=&#8221;SalesReport.ascx.cs&#8221;
Inherits=&#8221;Epod.UserControls.SalesReport&#8221; %&#62;
&#60;div id=&#8221;divgridView&#8221; class=&#8221;grid&#8221;&#62;
&#60;asp:GridView ID=&#8221;gvProducts&#8221; runat=&#8221;server&#8221; AllowSorting=&#8221;false&#8221; AllowPaging=&#8221;false&#8221; AutoGenerateColumns=&#8221;False&#8221;
CellPadding=&#8221;4&#8243; GridLines=&#8221;None&#8221; ShowFooter=&#8221;false&#8221; OnRowCommand=&#8221;gvProducts_RowCommand&#8221;
Width=&#8221;100%&#8221;&#62;
&#60;Columns&#62;
&#60;asp:TemplateField ItemStyle-HorizontalAlign=&#8221;Left&#8221;&#62;
&#60;ItemTemplate&#62;
&#60;tr&#62;
&#60;td&#62;
&#60;asp:LinkButton ID=&#8221;_btnExpandandCollapse&#8221; runat=&#8221;server&#8221; Text=&#8221;&#60;img src=&#8217;../images/expand.gif&#8217; alt=&#8217;Expand to see detailed report&#8217; border=&#8217;0&#8242; /&#62;&#8221;
CssClass=&#8221;GridViewDataHyperLink&#8221; CommandArgument=&#8217;&#60;%# Container.DataItemIndex %&#62;&#8217;
CommandName=&#8217;&#60;%# Eval(&#8220;ProductId_pk&#8221;) %&#62;&#8217; ToolTip=&#8221;Expand to see the detailed report&#8221;&#62;&#60;/asp:LinkButton&#62;&#38;nbsp;&#38;nbsp;
&#60;asp:Label ID=&#8221;_lblEmployeeName&#8221; Font-Bold=&#8221;true&#8221; runat=&#8221;server&#8221; Text=&#8217;&#60;%# Eval(&#8220;ProductName&#8221;) [...]]]></description>
			<content:encoded><![CDATA[<p><strong>In order to export the nested gridview please follow the code below.</strong></p>
<p><strong>SalesReport.Ascx</strong></p>
<p>&lt;%@ Control Language=&#8221;C#&#8221; AutoEventWireup=&#8221;true&#8221; Codebehind=&#8221;SalesReport.ascx.cs&#8221;<br />
Inherits=&#8221;Epod.UserControls.SalesReport&#8221; %&gt;<br />
&lt;div id=&#8221;divgridView&#8221; class=&#8221;grid&#8221;&gt;<br />
&lt;asp:GridView ID=&#8221;gvProducts&#8221; runat=&#8221;server&#8221; AllowSorting=&#8221;false&#8221; AllowPaging=&#8221;false&#8221; AutoGenerateColumns=&#8221;False&#8221;<br />
CellPadding=&#8221;4&#8243; GridLines=&#8221;None&#8221; ShowFooter=&#8221;false&#8221; OnRowCommand=&#8221;gvProducts_RowCommand&#8221;<br />
Width=&#8221;100%&#8221;&gt;<br />
&lt;Columns&gt;<br />
&lt;asp:TemplateField ItemStyle-HorizontalAlign=&#8221;Left&#8221;&gt;<br />
&lt;ItemTemplate&gt;<br />
&lt;tr&gt;<br />
&lt;td&gt;<br />
&lt;asp:LinkButton ID=&#8221;_btnExpandandCollapse&#8221; runat=&#8221;server&#8221; Text=&#8221;&lt;img src=&#8217;../images/expand.gif&#8217; alt=&#8217;Expand to see detailed report&#8217; border=&#8217;0&#8242; /&gt;&#8221;<br />
CssClass=&#8221;GridViewDataHyperLink&#8221; CommandArgument=&#8217;&lt;%# Container.DataItemIndex %&gt;&#8217;<br />
CommandName=&#8217;&lt;%# Eval(&#8220;ProductId_pk&#8221;) %&gt;&#8217; ToolTip=&#8221;Expand to see the detailed report&#8221;&gt;&lt;/asp:LinkButton&gt;&amp;nbsp;&amp;nbsp;<br />
&lt;asp:Label ID=&#8221;_lblEmployeeName&#8221; Font-Bold=&#8221;true&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# Eval(&#8220;ProductName&#8221;) %&gt;&#8217;&gt;&lt;/asp:Label&gt;</p>
<p><span id="more-299"></span>&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td colspan=&#8221;2&#8243;&gt;<br />
&lt;asp:GridView ID=&#8221;gvProductOptions&#8221; runat=&#8221;server&#8221; CssClass=&#8221;GridView&#8221; AllowSorting=&#8221;True&#8221;<br />
Visible=&#8221;false&#8221; AutoGenerateColumns=&#8221;False&#8221; CellPadding=&#8221;4&#8243; GridLines=&#8221;None&#8221;<br />
ShowFooter=&#8221;True&#8221; AllowPaging=&#8221;true&#8221; PageSize=&#8221;25&#8243; Width=&#8221;95%&#8221; OnPageIndexChanging=&#8221;gvProductOptions_PageIndexChanging&#8221;<br />
OnSorting=&#8221;gvProductOptions_Sorting&#8221;&gt;<br />
&lt;Columns&gt;<br />
&lt;asp:BoundField HeaderText=&#8221;Option Title&#8221; DataField=&#8221;OptionTitle&#8221; SortExpression=&#8221;OptionTitle&#8221;<br />
FooterText=&#8221;Total&#8221; FooterStyle-Font-Bold=&#8221;true&#8221; ItemStyle-HorizontalAlign=&#8221;Center&#8221;/&gt;<br />
&lt;asp:BoundField HeaderText=&#8221;Quantity&#8221; DataField=&#8221;Quantity&#8221; SortExpression=&#8221;Quantity&#8221;/&gt;<br />
&lt;asp:BoundField HeaderText=&#8221;Price&#8221; DataField=&#8221;Price&#8221; SortExpression=&#8221;Price&#8221; ItemStyle-HorizontalAlign=&#8221;Center&#8221; /&gt;<br />
&lt;asp:BoundField HeaderText=&#8221;Total Discount&#8221; DataField=&#8221;TotalDiscount&#8221; SortExpression=&#8221;TotalDiscount&#8221;<br />
ItemStyle-HorizontalAlign=&#8221;Center&#8221; /&gt;<br />
&lt;asp:BoundField HeaderText=&#8221;Total BeforeDiscount&#8221; DataField=&#8221;TotalBeforeDiscount&#8221;<br />
SortExpression=&#8221;TotalBeforeDiscount&#8221; ItemStyle-HorizontalAlign=&#8221;Center&#8221; /&gt;<br />
&lt;asp:TemplateField HeaderText=&#8221;Discounted Total&#8221; FooterStyle-Font-Bold=&#8221;True&#8221;&gt;<br />
&lt;ItemTemplate&gt;<br />
&lt;asp:Label ID=&#8221;lblDiscountTotal&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# GetUnitPrice(DataBinder.Eval(Container.DataItem,&#8221;DiscountedTotal&#8221;)).ToString(&#8220;N2&#8243;)%&gt;&#8217;&gt;&lt;/asp:Label&gt;<br />
&lt;/ItemTemplate&gt;<br />
&lt;FooterTemplate&gt;<br />
&lt;asp:Label ID=&#8221;lblTotal&#8221; runat=&#8221;server&#8221; Text=&#8217;&lt;%# GetTotal().ToString(&#8220;N2&#8243;) %&gt;&#8217;&gt;&lt;/asp:Label&gt;<br />
&lt;/FooterTemplate&gt;<br />
&lt;/asp:TemplateField&gt;<br />
&lt;asp:BoundField HeaderText=&#8221;Organisation Name&#8221; DataField=&#8221;OrgName&#8221; SortExpression=&#8221;OrgName&#8221;<br />
ItemStyle-HorizontalAlign=&#8221;Center&#8221; /&gt;<br />
&lt;/Columns&gt;<br />
&lt;EmptyDataTemplate&gt;<br />
No records available<br />
&lt;/EmptyDataTemplate&gt;<br />
&lt;EmptyDataRowStyle CssClass=&#8221;EmptyDataRowStyle&#8221; /&gt;<br />
&lt;FooterStyle CssClass=&#8221;FooterStyle&#8221; /&gt;<br />
&lt;RowStyle CssClass=&#8221;RowStyle&#8221; /&gt;<br />
&lt;EditRowStyle CssClass=&#8221;EditRowStyle&#8221; /&gt;<br />
&lt;SelectedRowStyle CssClass=&#8221;SelectedRowStyle&#8221; /&gt;<br />
&lt;PagerStyle CssClass=&#8221;PagerStyle&#8221; /&gt;<br />
&lt;HeaderStyle CssClass=&#8221;HeaderStyle&#8221; /&gt;<br />
&lt;AlternatingRowStyle CssClass=&#8221;AlternatingRowStyle&#8221; /&gt;<br />
&lt;PagerSettings FirstPageText=&#8221;First&#8221; LastPageText=&#8221;Last&#8221; NextPageText=&#8221;Next&#8221; PreviousPageText=&#8221;Previous&#8221;<br />
Mode=&#8221;NextPreviousFirstLast&#8221; /&gt;<br />
&lt;/asp:GridView&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/ItemTemplate&gt;<br />
&lt;FooterTemplate&gt;<br />
&lt;/table&gt;<br />
&lt;/FooterTemplate&gt;<br />
&lt;/asp:TemplateField&gt;<br />
&lt;/Columns&gt;<br />
&lt;EmptyDataTemplate&gt;<br />
No records available<br />
&lt;/EmptyDataTemplate&gt;<br />
&lt;EmptyDataRowStyle ForeColor=&#8221;black&#8221; BackColor=&#8221;white&#8221; /&gt;<br />
&lt;/asp:GridView&gt;<br />
&lt;/div&gt;<br />
&lt;br /&gt;<br />
&lt;p&gt;<br />
&lt;asp:Button ID=&#8221;btnExportToExcel&#8221; runat=&#8221;server&#8221; Text=&#8221;Export&#8221; Visible=&#8221;false&#8221; OnClick=&#8221;btnExportToExcel_Click&#8221; /&gt;<br />
&lt;/p&gt;<br />
&lt;p&gt;<br />
&lt;asp:Label ID=&#8221;lblError&#8221; runat=&#8221;server&#8221; CssClass=&#8221;ErrorText&#8221;&gt;&lt;/asp:Label&gt;<br />
&lt;/p&gt;</p>
<p><strong>Code behind file:</strong></p>
<p><strong>Paste the following code</strong></p>
<p>#region btnExportToExcel_Click Event Start<br />
protected void btnExportToExcel_Click(object sender, EventArgs e)<br />
{<br />
Export(&#8220;SalesReport.xls&#8221;, gvProducts, &#8220;Sales Report&#8221;);<br />
}<br />
#endregion btnExportToExcel_Click Event End</p>
<p>#region ExportToExcle Methods Start</p>
<p>public static void Export(string fileName, GridView gv, string title)<br />
{<br />
HttpContext.Current.Response.Clear();<br />
HttpContext.Current.Response.AddHeader(&#8220;content-disposition&#8221;, string.Format(&#8220;attachment; filename={0}&#8221;, fileName));<br />
HttpContext.Current.Response.ContentType = &#8220;application/vnd.xls&#8221;;</p>
<p>using (StringWriter sw = new StringWriter())<br />
{<br />
HtmlTextWriter htw = new HtmlTextWriter(sw);<br />
try<br />
{<br />
// render the table into the htmlwriter<br />
RenderGrid(gv).RenderControl(htw);<br />
// render the htmlwriter into the response<br />
HttpContext.Current.Response.Write(&#8220;&#8221; + title + &#8220;&#8221;);<br />
HttpContext.Current.Response.Write(&#8220;&lt;br/&gt;&lt;br/&gt;&#8221;);<br />
HttpContext.Current.Response.Write(&#8220;Report created at: &#8221; + DateTime.Now.ToString());<br />
//HttpContext.Current.Response.Write( System.Web.HttpUtility.HtmlDecode( sw.ToString()));<br />
HttpContext.Current.Response.Write(sw.ToString());<br />
HttpContext.Current.Response.End();<br />
}<br />
catch (System.Threading.ThreadAbortException lException)<br />
{<br />
// do nothing<br />
}<br />
finally<br />
{<br />
htw.Close();<br />
}<br />
}<br />
}</p>
<p>private static Table RenderGrid(GridView grd)<br />
{<br />
// Create a form to contain the grid<br />
Table table = new Table();<br />
table.GridLines = grd.GridLines;</p>
<p>// add the header row to the table<br />
if (grd.HeaderRow != null)<br />
{<br />
PrepareControlForExport(grd.HeaderRow);<br />
table.Rows.Add(grd.HeaderRow);<br />
}</p>
<p>// add each of the data rows to the table<br />
foreach (GridViewRow row in grd.Rows)<br />
{<br />
//to allign top<br />
row.VerticalAlign = VerticalAlign.Top;<br />
row.HorizontalAlign = HorizontalAlign.Right;<br />
PrepareControlForExport(row);<br />
table.Rows.Add(row);<br />
}</p>
<p>// add the footer row to the table<br />
if (grd.FooterRow != null)<br />
{<br />
grd.FooterRow.HorizontalAlign = HorizontalAlign.Right;<br />
PrepareControlForExport(grd.FooterRow);<br />
table.Rows.Add(grd.FooterRow);<br />
}<br />
return table;<br />
}</p>
<p>private static void PrepareControlForExport(Control control)<br />
{<br />
for (int i = 0; i &lt; control.Controls.Count; i++)<br />
{<br />
Control current = control.Controls[i];<br />
if (current is GridView)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, RenderGrid((GridView)current));<br />
}<br />
if (current is LinkButton)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl(string.Empty));<br />
}<br />
if (current is Button)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl((current as Button).Text));<br />
}<br />
else if (current is ImageButton)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));<br />
}<br />
else if (current is Label)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl((current as Label).Text));<br />
}<br />
else if (current is HyperLink)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));<br />
}<br />
else if (current is DropDownList)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));<br />
}<br />
else if (current is CheckBox)<br />
{<br />
control.Controls.Remove(current);<br />
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? &#8220;Da&#8221; : &#8220;Nu&#8221;));<br />
}</p>
<p>if (current.HasControls())<br />
{<br />
PrepareControlForExport(current);<br />
}<br />
}<br />
}</p>
<p>#endregion ExportToExcle Methods End</p>
<p>This should allow you to export the nested gridview to excel.</p>
<p>Happy coding&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2009/04/export-nestedgridview-to-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Export Data from Data Table to Excel File Format using C#.NET</title>
		<link>http://www.trekinnovations.com/2008/12/export-data-from-data-table-to-excel-file-format-using-cnet/</link>
		<comments>http://www.trekinnovations.com/2008/12/export-data-from-data-table-to-excel-file-format-using-cnet/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 11:24:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[DataTable to Excel Export]]></category>
		<category><![CDATA[Excel Export Option]]></category>
		<category><![CDATA[Export Data to Excel]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=296</guid>
		<description><![CDATA[
In order to achieve this first, you need to add a component known as Excel.dll (Microsoft excel 11.0 Object Library) into your .NET project references. 
 
To do above follow below instructions:
 
Add a reference to the Microsoft Excel Object Library. To do this, follow these steps: 
a. On the Project menu, click Add Reference. [...]]]></description>
			<content:encoded><![CDATA[<p><!--[endif]--></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;">In order to achieve this first, you need to add a component known as <strong><span style="font-family: Verdana;">Excel.dll</span></strong> (<strong><span style="font-family: Verdana;">Microsoft excel 11.0 Object Library</span></strong>) into your .NET project references. </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><strong><span style="font-size: 10pt; font-family: Verdana;">To do above follow below instructions:</span></strong></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;">Add a reference to the <strong><span style="font-family: Verdana;">Microsoft Excel Object Library</span></strong>. To do this, follow these steps: </span></p>
<p class="MsoNormal" style="margin-left: 39pt; text-align: justify; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>a.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">On the <strong><span style="font-family: Verdana;">Project</span></strong> menu, click <strong><span style="font-family: Verdana;">Add Reference</span></strong>. </span></p>
<p class="MsoNormal" style="margin-left: 39pt; text-align: justify; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>b.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">On the <strong><span style="font-family: Verdana;">COM</span></strong> tab, locate <strong><span style="font-family: Verdana;">Microsoft Excel 11.0 Object Library</span></strong>, and then click <strong><span style="font-family: Verdana;">Select</span></strong>.</span></p>
<p class="MsoNormal" style="margin-left: 39pt; text-align: justify; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>c.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">Click <strong><span style="font-family: Verdana;">OK</span></strong> in the <strong><span style="font-family: Verdana;">Add References</span></strong> dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click <strong><span style="font-weight: normal; font-family: Verdana;">yes</span></strong>. </span></p>
<p class="MsoNormal" style="margin-left: 39pt; text-align: justify; text-indent: -18pt;"><span id="more-296"></span></p>
<p class="MsoNormal" style="text-align: justify;"><strong><span style="font-size: 10pt; font-family: Verdana;">The codes of the function to export data to Excel file is like below:-</span></strong><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana; color: blue;">private</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: blue;">void</span> ExportToExcelFile(System.Data.<span style="color: #2b91af;">DataTable</span> dt)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Excel.<span style="color: #2b91af;">Application</span> xlsApp = <span style="color: blue;">new</span> Excel.<span style="color: #2b91af;">ApplicationClass</span>();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Excel.<span style="color: #2b91af;">Workbook</span> xlsWorkbook;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Excel.<span style="color: #2b91af;">Worksheet</span> xlsWorksheet;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">string</span> strhdr;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">int</span> row;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">string</span> strFile = <span style="color: #a31515;">&#8220;file1.xls&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">string</span> filename = Server.MapPath(strFile);</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dt.Rows.Count &gt; 0)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Create new workbook</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorkbook = xlsApp.Workbooks.Add(<span style="color: blue;">true</span>);</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: green;">//Get the first worksheet</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet = (Excel.<span style="color: #2b91af;">Worksheet</span>)(xlsWorkbook.Worksheets[1]);</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Activate current worksheet</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Activate();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Set header row to row 1</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>row = 1;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Add table headers to worksheet</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 1] = <span style="color: #a31515;">&#8220;Enquiry Type&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 2] = <span style="color: #a31515;">&#8220;Topic Area&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 3] = <span style="color: #a31515;">&#8220;Status&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 4] = <span style="color: #a31515;">&#8220;Received Date&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span>xlsWorksheet.Cells[row, 5] = <span style="color: #a31515;">&#8220;Enquiry&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 6] = <span style="color: #a31515;">&#8220;Customer Name&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 7] = <span style="color: #a31515;">&#8220;Agency location&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 8] = <span style="color: #a31515;">&#8220;Timetaken&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Format header row (bold, extra row height, autofit width)</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A&#8221;</span> + row.ToString(), <span style="color: #a31515;">&#8220;C&#8221;</span> + row.ToString()).Font.Bold = <span style="color: blue;">true</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A&#8221;</span> + row.ToString(), <span style="color: #a31515;">&#8220;C&#8221;</span> + row.ToString()).Rows.RowHeight = 1.5 * xlsWorksheet.StandardHeight;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A&#8221;</span> + row.ToString(), <span style="color: #a31515;">&#8220;C&#8221;</span> + row.ToString()).EntireRow.AutoFit();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Freeze the columm headers</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A&#8221;</span> + (row + 1).ToString(), <span style="color: #a31515;">&#8220;C&#8221;</span> + (row + 1).ToString()).Select();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span>xlsApp.ActiveWindow.FreezePanes = <span style="color: blue;">true</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Write data to Excel worksheet</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">foreach</span> (<span style="color: #2b91af;">DataRow</span> dr <span style="color: blue;">in</span> dt.Rows)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>row += 1;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Enquiry_type"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 1] = dr[<span style="color: #a31515;">"Enquiry_type"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Topic_area"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 2] = dr[<span style="color: #a31515;">"Topic_area"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Status"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 3] = dr[<span style="color: #a31515;">"Status"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Entered_DateTime"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 4] = dr[<span style="color: #a31515;">"Entered_DateTime"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Enquiry_Description"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 5] = dr[<span style="color: #a31515;">"Enquiry_Description"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Firstname"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 6] = dr[<span style="color: #a31515;">"Firstname"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"Agency_Location"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 7] = dr[<span style="color: #a31515;">"Agency_Location"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (dr[<span style="color: #a31515;">"TimeTaken"</span>] != <span style="color: blue;">null</span>)</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.Cells[row, 8] = dr[<span style="color: #a31515;">"TimeTaken"</span>];</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Format data rows (align to center and left, autofit width and height)</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A2&#8243;</span>, <span style="color: #a31515;">&#8220;C&#8221;</span> + row.ToString()).VerticalAlignment = Excel.<span style="color: #2b91af;">XlVAlign</span>.xlVAlignCenter;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A2&#8243;</span>, <span style="color: #a31515;">&#8220;C&#8221;</span> + row.ToString()).HorizontalAlignment = Excel.<span style="color: #2b91af;">XlHAlign</span>.xlHAlignLeft;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A2&#8243;</span>, <span style="color: #a31515;">&#8220;c&#8221;</span> + row.ToString()).EntireColumn.AutoFit();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span>xlsWorksheet.get_Range(<span style="color: #a31515;">&#8220;A2&#8243;</span>, <span style="color: #a31515;">&#8220;c&#8221;</span> + row.ToString()).EntireRow.AutoFit();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Make excel workbook visible to user after all data has been added to worksheet.</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsApp.DisplayAlerts = <span style="color: blue;">false</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>xlsWorkbook.Close(<span style="color: blue;">true</span>, filename, <span style="color: blue;">null</span>);</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Export data to client machine</span></span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>strhdr = <span style="color: #a31515;">&#8220;attachment;filename=&#8221;</span> + strFile;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Clear();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.ContentType = <span style="color: #a31515;">&#8220;application/vnd.ms-excel&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.ContentEncoding = System.Text.<span style="color: #2b91af;">Encoding</span>.Default;</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Disposition&#8221;</span>, strhdr);</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.WriteFile(filename);</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Flush();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Clear();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Close();</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="text-align: justify;"><span style="font-size: 10pt; font-family: Verdana;">Happy Coding……………………</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/12/export-data-from-data-table-to-excel-file-format-using-cnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validating Controls within Ajax Tab Panels/Tab Control</title>
		<link>http://www.trekinnovations.com/2008/12/validating-controls-within-ajax-tab-panelstab-control/</link>
		<comments>http://www.trekinnovations.com/2008/12/validating-controls-within-ajax-tab-panelstab-control/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 22:08:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Ajax TabConrols]]></category>
		<category><![CDATA[Ajax TabPanels]]></category>
		<category><![CDATA[Validation Controls]]></category>
		<category><![CDATA[Validation Problems in Ajax TabControl]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=289</guid>
		<description><![CDATA[Normally when we are using Ajax TabContols in aspx page with validation controls enabled on each and every TabPanel. Suppose if iam having 3 tab panels in TabControl and every tabpanel has some validations enabled and if iam in 1st panel and I submitted the form by clicking the button and in the 1st panel [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Normally when we are using Ajax TabContols in aspx page with validation controls enabled on each and every TabPanel. Suppose if iam having 3 tab panels in TabControl and every tabpanel has some validations enabled and if iam in 1<sup>st</sup> panel and I submitted the form by clicking the button and in the 1<sup>st</sup> panel every thing is ok i.e. I filled all my required fields on the 1<sup>st</sup> TabPanel. But I left some fields blank on the 2<sup>nd</sup> and 3<sup>rd</sup> TabPanel; when you click on submit button the validations will be enabled on 2<sup>nd</sup> and 3<sup>rd</sup> panel but the tab index of the TabControl will be still on the 1<sup>st</sup> TabPanel only. But we want TabIndex to automatically change based on the validation failed on the TabPanel. In order to do that we have to write a piece of JavaScript as show below:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">script</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: red;">type</span><span style="color: blue;">=&#8221;text/javascript&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">var</span> handleTabChange = <span style="color: blue;">true</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">function</span> ValidatePage()</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span>(handleTabChange)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (Page_ClientValidate(<span style="color: #a31515;">&#8216;Tab1&#8242;</span>) == <span style="color: blue;">false</span>)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span>$find(<span style="color: #a31515;">&#8220;&lt;%=TabContainerAddEnquiry.ClientID%&gt;&#8221;</span>).set_activeTabIndex(0);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">else</span> <span style="color: blue;">if</span> (Page_ClientValidate(<span style="color: #a31515;">&#8216;Tab2&#8242;</span>) == <span style="color: blue;">false</span>)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>$find(<span style="color: #a31515;">&#8220;&lt;%=TabContainerAddEnquiry.ClientID%&gt;&#8221;</span>).set_activeTabIndex(1);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">else</span> <span style="color: blue;">if</span> (Page_ClientValidate(<span style="color: #a31515;">&#8216;Tab3&#8242;</span>) == <span style="color: blue;">false</span>)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>$find(<span style="color: #a31515;">&#8220;&lt;%=TabContainerAddEnquiry.ClientID%&gt;&#8221;</span>).set_activeTabIndex(2);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">else</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>handleTabChange = <span style="color: blue;">true</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">script</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span><span id="more-289"></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">From the above JavaScript you can see iam having if else statements and in that iam checking<span style="color: blue;"> </span>Page_ClientValidate() by passing the validation group of each and every tabpanel.</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">Iam having 3 tabpanels and evry tabpanel has got its own validation group set as you can see below highlighted with yellow Color. So basically you have to set separate validation group for each and every tabcontrol. </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size: 10pt; font-family: Verdana;">See source code here:</span></strong></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">EA</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">:</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">TabContainer</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;TabContainerAddEnquiry&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">CssClass</span><span style="color: blue;">=&#8221;scienceEnquiry&#8221;</span> <span style="color: red;">OnClientActiveTabChanged</span><span style="color: blue;">=&#8221;SaveActiveTabIndex&#8221;</span> <span style="color: red;">ActiveTabIndex</span><span style="color: blue;">=&#8221;1&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabPanel</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;tabContactDetails&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">HeaderText</span><span style="color: blue;">=&#8221;Contact Details&#8221;</span> <span style="color: red;">TabIndex</span><span style="color: blue;">=&#8221;1&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">ContentTemplate</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">p</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">&gt;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">label</span> <span style="color: red;">for</span><span style="color: blue;">=&#8221;Textbox1&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Text1:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">label</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;Textbox1&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">TextMode</span><span style="color: blue;">=&#8221;MultiLine&#8221;</span> <span style="background: yellow none repeat scroll 0% 50%; color: red;">ValidationGroup</span><span style="background: yellow none repeat scroll 0% 50%; color: blue;">=&#8221;Tab1&#8243;</span><span style="color: blue;">&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">RequiredFieldValidator</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ Textbox1ReqFieldVal&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">ControlToValidate</span><span style="color: blue;">=&#8221;Textbox1&#8243;</span> <span style="background: yellow none repeat scroll 0% 50%; color: red;">ValidationGroup</span><span style="background: yellow none repeat scroll 0% 50%; color: blue;">=&#8221;Tab1&#8243;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">SetFocusOnError</span><span style="color: blue;">=&#8221;True&#8221;</span> <span style="color: red;">Display</span><span style="color: blue;">=&#8221;None&#8221;</span> <span style="color: red;">ErrorMessage</span><span style="color: blue;">=&#8221;&lt;b&gt;Required Field Missing&lt;/b&gt;&lt;br /&gt;Recieved Date is required.&#8221;&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">RequiredFieldValidator</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">ValidatorCalloutExtender</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ Textbox1DescValExt&#8221;</span> <span style="color: red;">TargetControlID</span><span style="color: blue;">=&#8221;_Textbox Textbox1ReqFieldVal &#8220;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">HighlightCssClass</span><span style="color: blue;">=&#8221;validatorCalloutHighlight&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">Enabled</span><span style="color: blue;">=&#8221;True&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">ValidatorCalloutExtender</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">p</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ContentTemplate</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabPanel</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabPanel</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;tabEnquiryDetails&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">HeaderText</span><span style="color: blue;">=&#8221;Enquiry Details&#8221;</span> <span style="color: red;">TabIndex</span><span style="color: blue;">=&#8221;2&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">ContentTemplate</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">p</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">&gt;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">label</span> <span style="color: red;">for</span><span style="color: blue;">=&#8221;Textbox2&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Text2:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">label</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;Textbox2&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">TextMode</span><span style="color: blue;">=&#8221;MultiLine&#8221;</span> <span style="background: yellow none repeat scroll 0% 50%; color: red;">ValidationGroup</span><span style="background: yellow none repeat scroll 0% 50%; color: blue;">=&#8221;Tab2&#8243;</span><span style="color: blue;">&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">RequiredFieldValidator</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ Textbox2ReqFieldVal&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">ControlToValidate</span><span style="color: blue;">=&#8221;Textbox2&#8243;</span> <span style="background: yellow none repeat scroll 0% 50%; color: red;">ValidationGroup</span><span style="background: yellow none repeat scroll 0% 50%; color: blue;">=&#8221;Tab2&#8243;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">SetFocusOnError</span><span style="color: blue;">=&#8221;True&#8221;</span> <span style="color: red;">Display</span><span style="color: blue;">=&#8221;None&#8221;</span> <span style="color: red;">ErrorMessage</span><span style="color: blue;">=&#8221;&lt;b&gt;Required Field Missing&lt;/b&gt;&lt;br /&gt;Recieved Date is required.&#8221;&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">RequiredFieldValidator</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">ValidatorCalloutExtender</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ Textbox1DescValExt&#8221;</span> <span style="color: red;">TargetControlID</span><span style="color: blue;">=&#8221;_ Textbox2ReqFieldVal &#8220;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">HighlightCssClass</span><span style="color: blue;">=&#8221;validatorCalloutHighlight&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">Enabled</span><span style="color: blue;">=&#8221;True&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">ValidatorCalloutExtender</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">p</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ContentTemplate</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabPanel</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabPanel</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;tabAssignTo&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">HeaderText</span><span style="color: blue;">=&#8221;Assign To&#8221;</span> <span style="color: red;">TabIndex</span><span style="color: blue;">=&#8221;3&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">ContentTemplate</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">p</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">&gt;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">label</span> <span style="color: red;">for</span><span style="color: blue;">=&#8221;Textbox3&#8243;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Text3:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">label</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;Textbox3&#8243;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">TextMode</span><span style="color: blue;">=&#8221;MultiLine&#8221;</span> <span style="background: yellow none repeat scroll 0% 50%; color: red;">ValidationGroup</span><span style="background: yellow none repeat scroll 0% 50%; color: blue;">=&#8221;Tab3&#8243;</span><span style="color: blue;">&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">RequiredFieldValidator</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ Textbox3ReqFieldVal&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">ControlToValidate</span><span style="color: blue;">=&#8221;Textbox3&#8243;</span> <span style="background: yellow none repeat scroll 0% 50%; color: red;">ValidationGroup</span><span style="background: yellow none repeat scroll 0% 50%; color: blue;">=&#8221;Tab3&#8243;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">SetFocusOnError</span><span style="color: blue;">=&#8221;True&#8221;</span> <span style="color: red;">Display</span><span style="color: blue;">=&#8221;None&#8221;</span> <span style="color: red;">ErrorMessage</span><span style="color: blue;">=&#8221;&lt;b&gt;Required Field Missing&lt;/b&gt;&lt;br /&gt;Recieved Date is required.&#8221;&gt;&lt;/</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">RequiredFieldValidator</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">ValidatorCalloutExtender</span> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_ Textbox3DescValExt&#8221;</span> <span style="color: red;">TargetControlID</span><span style="color: blue;">=&#8221;_Textbox3ReqFieldVal &#8220;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">HighlightCssClass</span><span style="color: blue;">=&#8221;validatorCalloutHighlight&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">Enabled</span><span style="color: blue;">=&#8221;True&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">ValidatorCalloutExtender</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">p</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">ContentTemplate</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabPanel</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: #a31515;">EA</span><span style="color: blue;">:</span><span style="color: #a31515;">TabContainer</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">And after setting the validation groups, I need to validate the data when in click on the submit button. So in order to validate the data in button click there is a property called<span style="color: blue;"> </span><span style="color: red;">OnClientClick</span><span style="color: blue;"> </span>for button control . Use this property to call the javascript like this =&#8221;javascript:ValidatePage();&#8221; and one more thing you need to do is set the validation groups for the button control<span> </span>as shown below:</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">asp</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">:</span><span style="font-size: 10pt; font-family: Verdana; color: #a31515;">Button</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;_btnSubmit&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;</span> <span style="color: red;">Text</span><span style="color: blue;">=&#8221;Add Enquiry&#8221;</span> <span style="color: red;">CausesValidation</span><span style="color: blue;">=&#8221;true&#8221;</span> <span style="color: red;">ValidationGroup</span><span style="color: blue;">=&#8221;Tab1,Tab2,Tab3&#8243;</span> <span style="color: red;">OnClick</span><span style="color: blue;">=&#8221;_btnSubmit_Click&#8221;</span> <span style="color: red;">OnClientClick</span><span style="color: blue;">=&#8221;javascript:ValidatePage();&#8221;</span> <span style="color: blue;">/&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">This solves the problem. Happy Coding…………..</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/12/validating-controls-within-ajax-tab-panelstab-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting GridView to Excel Problem  When Using Web UserControl:</title>
		<link>http://www.trekinnovations.com/2008/12/exporting-gridview-to-excel-problem-when-using-web-usercontrol/</link>
		<comments>http://www.trekinnovations.com/2008/12/exporting-gridview-to-excel-problem-when-using-web-usercontrol/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 09:42:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Error in runat=server]]></category>
		<category><![CDATA[Export Gridview to Excel]]></category>
		<category><![CDATA[Web Usercontrol]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=283</guid>
		<description><![CDATA[This article explains how you can export your GridView control to Excel files. If you are working with web user control. Suppose if you are having your gridview in your User Control and you are trying to export the gridview data to some other format some thing like this
 
protected void _btnReports_Click(object sender, EventArgs e)
 [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; font-family: Verdana;">This article explains how you can export your GridView control to Excel files. If you are working with web user control.<span> </span>Suppose if you are having your gridview in your User Control and you are trying to export the gridview data to some other format some thing like this</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">protected</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: blue;">void</span> _btnReports_Click(<span style="color: blue;">object</span> sender, <span style="color: teal;">EventArgs</span> e)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Clear();</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Write(<span style="color: maroon;">@&#8221;&lt;!DOCTYPE HTML PUBLIC &#8220;&#8221;-//W3C//DTD HTML 4.0 Transitional//EN&#8221;"&gt;&#8221;</span>);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.AddHeader(<span style="color: maroon;">&#8220;content-disposition&#8221;</span>, <span style="color: maroon;">&#8220;inline;filename=search_topicarea.doc&#8221;</span>);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Charset = <span style="color: maroon;">&#8220;&#8221;</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Cache.SetCacheability(<span style="color: teal;">HttpCacheability</span>.NoCache);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.ContentType = <span style="color: maroon;">&#8220;application/vnd.doc&#8221;</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>System.IO.<span style="color: teal;">StringWriter</span> stringWrite = <span style="color: blue;">new</span> System.IO.<span style="color: teal;">StringWriter</span>();</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>System.Web.UI.<span style="color: teal;">HtmlTextWriter</span> htmlWrite = <span style="color: blue;">new</span> <span style="color: teal;">HtmlTextWriter</span>(stringWrite);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Render(htmlWrite);</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>_gvViewresults.RenderControl(htmlWrite);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Write(stringWrite.ToString());</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.End();</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p><span id="more-283"></span><span style="font-size: 10pt; font-family: Verdana;">And adding a little piece of code like </span><span style="font-size: 10pt; font-family: Verdana;">override the <em>Page.VerifyRenderingInServerForm </em>method as shown below</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">public</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: blue;">override</span> <span style="color: blue;">void</span> VerifyRenderingInServerForm(<span style="color: #2b91af;">Control</span> control)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">// Confirms that an HtmlForm control is rendered for the</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//specified ASP.NET server control at run time.</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: green;"> </span></p>
<p><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;">But this works in aspx page but you cannot </span><span style="font-size: 10pt; font-family: Verdana;">override the <em>Page.VerifyRenderingInServerForm </em>method in the web user control. </span></p>
<p><span style="font-size: 10pt; font-family: Verdana;"><strong>In order to solve the above problem:</strong> </span></p>
<p style="margin-left: 36pt; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>1.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">Create one aspx page </span></p>
<p style="margin-left: 36pt; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>2.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">Then drag the web user control in to this aspx page but your grid view and the button click events will be in the web user control only.</span></p>
<p style="margin-left: 36pt; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>3.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">Then in the aspx page in the Page directives tag just add </span><span style="font-size: 10pt; font-family: Verdana; color: red;">EnableEventValidation</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">=&#8221;false&#8221;.</span></p>
<p style="margin-left: 36pt; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>4.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">In the code behind file i.e. aspx.cs file now override the <em>Page.VerifyRenderingInServerForm </em>method.</span></p>
<p style="margin-left: 36pt; text-indent: -18pt;"><!--[if !supportLists]--><span style="font-size: 10pt; font-family: Verdana;"><span>5.<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal; font-family: &quot;Times New Roman&quot;;"> </span></span></span><!--[endif]--><span style="font-size: 10pt; font-family: Verdana;">This works. </span></p>
<p><span style="font-size: 10pt; font-family: Verdana; color: blue;"> </span></p>
<p class="MsoNormal"><strong><span style="font-size: 10pt; font-family: Verdana;">Sample code is given below:</span></strong><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="background: yellow none repeat scroll 0% 50%; font-size: 10pt; font-family: Verdana;">&lt;%</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">@</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: maroon;">Page</span> <span style="color: red;">Language</span><span style="color: blue;">=&#8221;C#&#8221;</span> <span style="color: red;">MasterPageFile</span><span style="color: blue;">=&#8221;~/Masters/abc.master&#8221;</span> <span style="color: red;">AutoEventWireup</span><span style="color: blue;">=&#8221;true&#8221;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">CodeFile</span><span style="color: blue;">=&#8221;create.aspx.cs&#8221;</span> <span style="color: red;">Inherits</span><span style="color: blue;">=&#8221;abc_ create &#8220;</span> <span style="color: red;">EnableEventValidation</span><span style="color: blue;">=&#8221;false&#8221;</span></span></p>
<p class="MsoNormal"><span style="background: yellow none repeat scroll 0% 50%; font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: red;">Title</span><span style="color: blue;">=&#8221;create&#8221;</span> <span style="background: yellow none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">%&gt;</span> </span></p>
<p class="MsoNormal"><span style="background: yellow none repeat scroll 0% 50%; font-size: 10pt; font-family: Verdana;">&lt;%</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">@</span><span style="background: yellow none repeat scroll 0% 50%; font-size: 10pt; font-family: Verdana;"> <span style="color: maroon;">Register</span> <span style="color: red;">Src</span><span style="color: blue;">=&#8221;../UserControls/View.ascx&#8221;</span> <span style="color: red;">TagName</span><span style="color: blue;">=&#8221;View&#8221;</span> <span style="color: red;">TagPrefix</span><span style="color: blue;">=&#8221;uc1&#8243;</span> <span style="background: yellow none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">%&gt;</span> </span></p>
<p class="MsoNormal"><span style="background: yellow none repeat scroll 0% 50%; font-size: 10pt; font-family: Verdana;">&lt;%</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">@</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: maroon;">Register</span> <span style="color: red;">Assembly</span><span style="color: blue;">=&#8221;AjaxControlToolkit&#8221;</span> <span style="color: red;">Namespace</span><span style="color: blue;">=&#8221;AjaxControlToolkit&#8221;</span> <span style="color: red;">TagPrefix</span><span style="color: blue;">=&#8221;EA&#8221;</span> <span style="background: yellow none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">%&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;</span><span style="font-size: 10pt; font-family: Verdana; color: maroon;">asp</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">:</span><span style="font-size: 10pt; font-family: Verdana; color: maroon;">Content</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: red;">ID</span><span style="color: blue;">=&#8221;Content1&#8243;</span> <span style="color: red;">ContentPlaceHolderID</span><span style="color: blue;">=&#8221;MainContent&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;Server&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">h2</span> <span style="color: red;">class</span><span style="color: blue;">=&#8221;blue&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>View Pending Enquiries</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">h2</span><span style="color: blue;">&gt;</span><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">p</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;</span><span style="color: maroon;">uc1</span><span style="color: blue;">: View</span><span style="color: red;"> id</span><span style="color: blue;">=&#8221;_View&#8221;</span> <span style="color: red;">runat</span><span style="color: blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">&lt;/</span><span style="color: maroon;">uc1</span><span style="color: blue;">: View &gt;&lt;/</span><span style="color: maroon;">p</span><span style="color: blue;">&gt;</span><span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">&lt;/</span><span style="font-size: 10pt; font-family: Verdana; color: maroon;">asp</span><span style="font-size: 10pt; font-family: Verdana; color: blue;">:</span><span style="font-size: 10pt; font-family: Verdana; color: maroon;">Content</span><span style="font-size: 10pt; font-family: Verdana;">&gt;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Data;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Configuration;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Collections;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Web;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Web.Security;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Web.UI;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Web.UI.WebControls;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Web.UI.WebControls.WebParts;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System.Web.UI.HtmlControls;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> EA.SEDB.BO.ScienceEnquiriesDBTableAdapters;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> EA.SEDB.BO;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">using</span><span style="font-size: 10pt; font-family: Verdana;"> EA.SEDB.BS;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">public</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: teal;">abc_view</span> : System.Web.UI.<span style="color: teal;">Page</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;">{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"><span> </span>#region</span><span style="font-size: 10pt; font-family: Verdana;"> Declare Variables Start</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: teal;">Abc</span>.<span style="color: teal;">UsersDataTable</span> UsersDT = <span style="color: blue;">null</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">string</span> userName = <span style="color: blue;">string</span>.Empty;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">int</span> loggedInUserId; </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"><span> </span>#endregion</span><span style="font-size: 10pt; font-family: Verdana;"> Declare Variables End </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"><span> </span>#region</span><span style="font-size: 10pt; font-family: Verdana;"> PageLoad Start</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: teal;">EventArgs</span> e)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>userName = <span style="color: teal;">HttpContext</span>.Current.User.Identity.Name; </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (!Page.IsPostBack)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (!<span style="color: blue;">string</span>.IsNullOrEmpty(userName))</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>UsersDT = <span style="color: teal;">Administration</span>.GetUserDetailsByUsername(userName); </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span> </span><span style="color: blue;">if</span> (UsersDT.Rows.Count &gt; 0)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>loggedInUserId = UsersDT[0].UserId;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>} </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (<span style="color: teal;">HttpContext</span>.Current.User.Identity.IsAuthenticated)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">if</span> (<span style="color: teal;">Roles</span>.IsUserInRole(<span style="color: teal;">ConfigurationManager</span>.AppSettings[<span style="color: maroon;">"Managers"</span>]))</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>_ViewEnquiries.ViewEnquiries_ForManager(loggedInUserId, <span style="color: teal;">ConfigurationManager</span>.AppSettings[<span style="color: maroon;">"AssignTo"</span>].ToString());</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">else</span> <span style="color: blue;">if</span> (<span style="color: teal;">Roles</span>.IsUserInRole(<span style="color: teal;">ConfigurationManager</span>.AppSettings[<span style="color: maroon;">"TeamMembers"</span>]))</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>_ViewEnquiries.ViewEnquiries_ForTeamMember(loggedInUserId, <span style="color: teal;">ConfigurationManager</span>.AppSettings[<span style="color: maroon;">"Assign"</span>].ToString());</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">else</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Redirect(<span style="color: maroon;">&#8220;~/UnauthorisedPage.aspx&#8221;</span>);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">else</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Redirect(<span style="color: maroon;">&#8220;~/UnauthorisedPage.aspx&#8221;</span>);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>} </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">override</span> <span style="color: blue;">void</span> VerifyRenderingInServerForm(<span style="color: teal;">Control</span> control)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">// Confirms that an HtmlForm control is rendered for the</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: green;"><span> </span><span style="color: green;">//specified ASP.NET server control at run time.</span> </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>} </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;"><span> </span>#endregion</span><span style="font-size: 10pt; font-family: Verdana;"> PageLoad End</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;">}</span></p>
<p>Happy Coding&#8230;&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/12/exporting-gridview-to-excel-problem-when-using-web-usercontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting GridView to Excel &#8216;GridView&#8217; must be placed inside a form tag</title>
		<link>http://www.trekinnovations.com/2008/12/exporting-gridview-to-excel-gridview-must-be-placed-inside-a-form-tag/</link>
		<comments>http://www.trekinnovations.com/2008/12/exporting-gridview-to-excel-gridview-must-be-placed-inside-a-form-tag/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 09:39:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Export Gridview to Excel]]></category>
		<category><![CDATA[Gridview]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=280</guid>
		<description><![CDATA[This article explains how you can export your GridView control to Excel files. If you are working with GridView.
Exporting Grid View to Excel Files:  
The approach is pretty much the same as it was in Gridview. The following code executes on a button click event. 
protected void _btnReports_Click(object sender, EventArgs e)
 {
 Response.Clear();
 Response.Write(@&#8221;&#60;!DOCTYPE [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; font-family: Verdana;">This article explains how you can export your GridView control to Excel files. If you are working with GridView.</span></p>
<p><strong><span style="font-size: 10pt; font-family: Verdana;">Exporting Grid View to Excel Files: </span><span style="text-decoration: underline;"><span style="font-size: 10pt; font-family: Verdana;"> </span></span></strong></p>
<p><span style="font-size: 10pt; font-family: Verdana;">The approach is pretty much the same as it was in Gridview. The following <a href="http://gridviewguy.com/ArticleDetails.aspx?articleID=86" target="_blank">code</a> executes on a button click event. </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">protected</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: blue;">void</span> _btnReports_Click(<span style="color: blue;">object</span> sender, <span style="color: teal;">EventArgs</span> e)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Clear();</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Write(<span style="color: maroon;">@&#8221;&lt;!DOCTYPE HTML PUBLIC &#8220;&#8221;-//W3C//DTD HTML 4.0 Transitional//EN&#8221;"&gt;&#8221;</span>);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.AddHeader(<span style="color: maroon;">&#8220;content-disposition&#8221;</span>, <span style="color: maroon;">&#8220;inline;filename=search_topicarea.doc&#8221;</span>);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Charset = <span style="color: maroon;">&#8220;&#8221;</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Cache.SetCacheability(<span style="color: teal;">HttpCacheability</span>.NoCache);</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.ContentType = <span style="color: maroon;">&#8220;application/vnd.doc&#8221;</span>;</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>System.IO.<span style="color: teal;">StringWriter</span> stringWrite = <span style="color: blue;">new</span> System.IO.<span style="color: teal;">StringWriter</span>(); </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>System.Web.UI.<span style="color: teal;">HtmlTextWriter</span> htmlWrite = <span style="color: blue;">new</span> <span style="color: teal;">HtmlTextWriter</span>(stringWrite);<span> </span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">//Render(htmlWrite);</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>_gvViewresults.RenderControl(htmlWrite); </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.Write(stringWrite.ToString()); </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>Response.End();</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p><span id="more-280"></span></p>
<p><span style="font-size: 10pt; font-family: Verdana;">The above shown code is almost identical to what we normally use when exporting Gridview to some other formats. But if you run this code it will not work, the reason is that we need to tell ASP.NET that there is a control in our form that will be rendered at runtime.</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;">In order to work the above shown code you need to add some piece of code as shown below i.e <span> </span>just override the <em>Page.VerifyRenderingInServerForm </em>method. </span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: blue;">public</span><span style="font-size: 10pt; font-family: Verdana;"> <span style="color: blue;">override</span> <span style="color: blue;">void</span> VerifyRenderingInServerForm(<span style="color: #2b91af;">Control</span> control)</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana;"><span> </span><span style="color: green;">// Confirms that an HtmlForm control is rendered for the</span></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: Verdana; color: green;"><span> </span><span style="color: green;">//specified ASP.NET server control at run time.</span> </span></p>
<p><span style="font-size: 10pt; font-family: Verdana;"><span> </span>}</span></p>
<p><span style="font-size: 10pt; font-family: Verdana;">Now if you try to export your GridView to excel it will work fine. </span></p>
<p><span style="font-size: 10pt; font-family: Verdana;">Happy Coding……….</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/12/exporting-gridview-to-excel-gridview-must-be-placed-inside-a-form-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming XML with C# &amp; Connecting Data and XML via ADO .NET</title>
		<link>http://www.trekinnovations.com/2008/11/programming-xml-with-c-connecting-data-and-xml-via-ado-net/</link>
		<comments>http://www.trekinnovations.com/2008/11/programming-xml-with-c-connecting-data-and-xml-via-ado-net/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 21:46:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[How to Load Data Using a DataSet]]></category>
		<category><![CDATA[Programming Xml using ADO.NET]]></category>
		<category><![CDATA[Programming Xml Using C#]]></category>
		<category><![CDATA[Reading XML using a Dataset]]></category>
		<category><![CDATA[ReadXml Method]]></category>
		<category><![CDATA[ReadXmlSchema method]]></category>
		<category><![CDATA[What is XmlDataDocument?]]></category>
		<category><![CDATA[WriteXml Method]]></category>
		<category><![CDATA[Writing XML using a Dataset]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=222</guid>
		<description><![CDATA[Connecting Data &#38; XML via ADO.NET 
In this article you can see how to work with XML documents with the help of ADO.NET. In this there are two approaches to work with XML and ADO.
1. You can use ADO.NET to access XML documents.
2. You can use ADO.NET and XML to access XML. Apart from this, [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Connecting Data &amp; XML via ADO.NET</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">In this article you can see how to work with XML documents with the help of ADO.NET. In this there are two approaches to work with XML and ADO.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">1. You can use ADO.NET to access XML documents.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">2. You can use ADO.NET and XML to access XML. Apart from this, you can access RDBMS using ADO.NET and XML.NET.</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span id="more-222"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><!--[if gte vml 1]><v:shapetype  id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"  path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter" /> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0" /> <v:f eqn="sum @0 1 0" /> <v:f eqn="sum 0 0 @1" /> <v:f eqn="prod @2 1 2" /> <v:f eqn="prod @3 21600 pixelWidth" /> <v:f eqn="prod @3 21600 pixelHeight" /> <v:f eqn="sum @0 0 1" /> <v:f eqn="prod @6 1 2" /> <v:f eqn="prod @7 21600 pixelWidth" /> <v:f eqn="sum @8 21600 0" /> <v:f eqn="prod @7 21600 pixelHeight" /> <v:f eqn="sum @10 21600 0" /> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect" /> <o:lock v:ext="edit" aspectratio="t" /> </v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1025" type="#_x0000_t75"  alt="http://www.trekinnovations.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif"  style='width:.75pt;height:.75pt;visibility:visible;mso-wrap-style:square'> <v:imagedata src="file:///C:\DOCUME~1\RAJESH~1\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif"   o:title="trans" /> </v:shape><![endif]--><!--[if !vml]--><img src="file:///C:/DOCUME~1/RAJESH~1/LOCALS~1/Temp/msohtmlclip1/01/clip_image001.gif" alt="http://www.trekinnovations.com/wp-includes/js/tinymce/plugins/wordpress/img/trans.gif" width="1" height="1" /><!--[endif]--></span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">First we will see how to read XML using a Dataset</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">Reading XML using a Dataset</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Normally in ADO.NET, we can access the data using the Dataset class. The Dataset class implements methods and properties to work with XML documents. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">In this article first we discuss the methods that read XML data.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">ReadXml Method</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ReadXml is used to read a data stream or an XML file and to store into a Dataset object, later which can be used to display the data in a tabular format. ReadXmlmethod has eight overloaded forms. ReadXML can read a text, string, stream, TextReader, XmlReader, and combination formats. In the following example, first we create a new DataSet object as follows:</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">DataSet ds =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new </span><span style="color: black;">DataSet();</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">After creating a dataset object we will call the ReadXML method to read the xml file into the dataset as follows</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Fill with the data</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.ReadXml(</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;books.xml &#8220;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">We should remember one thing when we are working with Datasets we have to add some references like some namespaces</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">System.Data </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">System.Data.Common </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now we are going to see how the ReadXmlSchema method works</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">ReadXmlSchema method</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Basically ReadXMLSchema method reads an XML schema in a DataSet object. You can use a string, stream,Text Reader and XmlReader. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">In the below example we will see how to read a file using ReadXmlSchema. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">First create an object for the dataset</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">DataSet ds = </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">new </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">DataSet( );</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Then using the ReadSchema method read the XML file like this</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.ReadSchema (</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">@&#8221;c:\books. xml&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">See the below example which uses XMLTextReader as input of ReadXmlSchema</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">DataSet ds =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new</span><span style="color: black;"> DataSet(</span><span style="color: maroon;">&#8220;New DataSet&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now we are going to read xml using XmlTextReader as follows</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlTextReader </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">objXmlReader =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new</span> <span style="color: teal;">XmlTextReader</span>(<span style="color: maroon;">@&#8221;c:\books.Xml&#8221;</span>);</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Now Call Read xml schema method which takes the parameter as XmlTextReader</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.ReadXmlSchema(objXmlReader);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Now close the XmlTextReader</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">objXmlReader.Close();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">Writing XML using a Dataset</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Dataset class not only contains methods to read the data but still it has got methods to write XML file from dataset in to the file also. Now we will see writeXml method.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">WriteXml Method</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">WriteXml method is used to write the data from Datasetto an XML file. By using WriteXml method, you can write data to a file, stream, TextWriter, or XmlWriter. In this example let’s creates a Dataset and fills the corresponding data into the Dataset, and then writes the data into an XML file. Below is the example for WriteXml Method. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Using</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">System; </span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Using</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">System.IO;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Using </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">System.Xml;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Using</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">System.Data;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Namespace</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">XmlDataset</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">{</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Class </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">XmlDataset</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">{</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Public</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> <span style="color: black;">Main ()</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">{</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataSet </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new</span> <span style="color: teal;">DataSet</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;DataSet&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.Namespace =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;EmpNamespace&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Now create DataTable and add columns to the datatable</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataTable </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">dt = <span style="color: blue;">new</span> <span style="color: teal;">DataTable</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;Employee&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataColumn</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">col1 = </span><span style="color: blue;">new</span> <span style="color: teal;">DataColumn</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;Name&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataColumn</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">col2 =</span> <span style="color: blue;">new</span> <span style="color: teal;">DataColumn</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;Address&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Columns.Add(col1);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Columns.Add(col2);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.Tables.Add(dt);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Add Employee Data to the table</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Create a new row and add the data to the corresponding columns</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataRow </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr; dr = dt.NewRow();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Name"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Rajesh&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Address"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Hagley Road&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Rows.Add(dr);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr = dt.NewRow();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Name"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Tim Easton&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Address"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;London&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Rows.Add(dr);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr = dt.NewRow();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Name"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Sara&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Address"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Oxford&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now add the datarows to the datatable</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Rows.Add(dr);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// After adding the rows to the datatable use AcceptChanges method if there are any changes</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.AcceptChanges();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Now order to stored the data in Xml File, we create a new StreamWriter and then save the data in to the Xml file as follows</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">StreamWriter </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">myStreamWriter = </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">new</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">StreamWriter</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">(</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">@&#8221;c:\xmldata.xml&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">);</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now for the dataset use the writeXml method which writes the data from dataset to Xml file, it takes the parameter as streamwriter </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// It writes the data in to the xml file</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.WriteXml(myStreamWriter);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">myStreamWriter.Close();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">return</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">}</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">}</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">}</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now in order to see the output of this program, open the xmldata.xml file. You can see the standard XML file as shown below. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">Output for WriteXml method</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin: 0cm 30pt 10pt 24pt; text-align: justify; text-indent: -24pt; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">-</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">DataSet</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: red;"> xmlns</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">=&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;"> </span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: red;">EmpNamespace</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;"> &#8220;&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin: 0cm 42pt 10pt 36pt; text-align: justify; text-indent: -24pt; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">-</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">&lt;</span><span style="color: #990000;">Student</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 54pt 10pt 48pt; text-align: justify; text-indent: -24pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Name</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Rajesh</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Name</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 54pt 10pt 48pt; text-align: justify; text-indent: -24pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Address</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Hagley Road</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Address</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 42pt 10pt 24pt; text-align: justify; text-indent: -12pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Student</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin: 0cm 42pt 10pt 36pt; text-align: justify; text-indent: -24pt; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">-</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">&lt;</span><span style="color: #990000;">Student</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 54pt 10pt 48pt; text-align: justify; text-indent: -24pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Name</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Tim Easton</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Name</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 54pt 10pt 48pt; text-align: justify; text-indent: -24pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Address</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">London</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Address</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 42pt 10pt 24pt; text-align: justify; text-indent: -12pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Student</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin: 0cm 42pt 10pt 36pt; text-align: justify; text-indent: -24pt; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">-</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">&lt;</span><span style="color: #990000;">Student</span><span style="color: blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 54pt 10pt 48pt; text-align: justify; text-indent: -24pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Name</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Sara</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Name</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 54pt 10pt 48pt; text-align: justify; text-indent: -24pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Address</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Oxford</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Address</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 42pt 10pt 24pt; text-align: justify; text-indent: -12pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #990000;">Student</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin: 0cm 30pt 10pt 12pt; text-align: justify; text-indent: -12pt; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">&lt;/</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">DataSet</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;"> &gt;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-right: 30pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now we will see the Write Xml Schema method how it works.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">Write xml schema method</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Write xml schema method writes the dataset structure into an XML schema. Using this method you can write the data to a stream, text, TextWriter, or Xmlwriter. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Below is the example for the write xml schema.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">// Create object for the dataset</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataSet </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds = </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">new</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: teal;">DataSet</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;DataSet&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.Namespace =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;EmpNamespace&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Now create DataTable and add columns to the datatable</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataTable </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new</span> <span style="color: teal;">DataTable</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;Employee&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataColumn</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">col1 =</span> <span style="color: blue;">new</span> <span style="color: teal;">DataColumn</span>(<span style="color: maroon;">&#8220;Name&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataColumn</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">col2 =</span> <span style="color: blue;">new</span> <span style="color: teal;">DataColumn</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;Address&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Columns.Add(col1);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Columns.Add(col2);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.Tables.Add(dt);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Add Employee Data to the table</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Create a new row and add the data to the corresponding columns</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataRow </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr; dr = dt.NewRow();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Name"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Rajesh&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Address"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Hagley Road&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Rows.Add(dr);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr = dt.NewRow();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Name"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Tim Easton&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Address"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;London&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Rows.Add(dr);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr = dt.NewRow();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Name"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] = </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;Sara&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dr [</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">"Address"</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">] =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: maroon;">&#8220;Oxford&#8221;</span><span style="color: black;">;</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now add the datarows to the datatable</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">dt.Rows.Add(dr);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// After adding the rows to the datatable use AcceptChanges method if there are any changes</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.AcceptChanges();</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now create an object for the xmlTextWriter </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlTextWriter</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">writer =</span> <span style="color: blue;">new</span> <span style="color: teal;">XmlTextWriter</span><span style="color: black;">(</span><span style="color: teal;">Console</span>.Out);</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// using the writeXmlSchema method write the data</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds.WriteXmlSchema(writer);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now we will see about the XmlDataDocumet</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">What is XmlDataDocument?</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">XmlDataDocument is a class defined within the System.Xml namespace. Basically it extends the XmlDocument class. The XmlDataDocument class allows the information stored within a DataSet to be treated as XML. Using this class, developers can manipulate data stored within a DataSet as XML or relational data.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">Load and LoadXml from the XmlDataDocument</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">In order to load the data in to xmlDataDocument either you can user Load method or the LoadXmlmethod. The difference between Load and LoadXml is Load method takes the parameter as a filename string or TextReader. But in the case of LoadXml it takes an Xml file. For better explanation see the below example.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now create an object for the XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> doc = <span style="color: blue;">new</span> <span style="color: teal;">XmlDataDocument</span>( );</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now using Load method load the xml file in to the document</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">doc.Load(<span style="color: maroon;">&#8220;c:\\ Employees.xml&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Now see how to load xml file using LoadXml</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> doc = <span style="color: blue;">new</span> <span style="color: teal;">XmlDataDocument</span>( );</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">doc.LoadsXml (<span style="color: maroon;">&#8220;&lt;Name&gt; Abc &lt;/ Name&gt;&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">How to Load Data Using a DataSet</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now we will see how to load data using DataSet. Dataset object has methods to read XML documents. These methods to read Xml documents are ReadXmlSchema and LoadXml. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">See the below example how to read xml schema and how to read xml file</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">First create object for the XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">doc =</span> <span style="color: blue;">new</span> <span style="color: teal;">XmlDataDocument</span><span style="color: black;">( );</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">doc.DataSet.ReadXmlSchema (</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;test. Xsd&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Or </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">doc.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataSet</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">.ReadXml (</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;&lt;Name&gt; Abc &lt;/ Name &gt;&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">How to Displaying XML Data In a DataSet Format?</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now you can get DataSet object from an XmlDataDocument object by using its DataSet property. In order to read XML document in a dataset, first of all we have to read data into document. We can read a document using the ReadXml method of the DataSet object. You can see in the below example.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">xmlDocument =</span> <span style="color: blue;">new</span> <span style="color: teal;">XmlDataDocument</span><span style="color: black;">();</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">xmlDocument.DataSet.ReadXml (</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;c:\\ document.xml&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">// In order to see the data in the dataset just bind the xmldocument to the gridview by using DefaultViewManager propety in the dataset.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">GridView1.DataSource = xmlDocument.DataSet.DefaultViewManager;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #1802be;">If you need the complete code for this you can see below:</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">Public</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">Data ( )</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">{</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//Now create an XmlDataDocument object and read an XML file</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlDataDocument </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">xmldoc = </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">new</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: teal;">XmlDataDocument</span><span style="color: black;">();</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">xmldoc.DataSet.ReadXml(</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;C:\\books.xml&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">);</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Create a DataSet object and fill with the dataset</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// of XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataSet </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds = </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">new</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: teal;">DataSet</span><span style="color: black;">(</span><span style="color: maroon;">&#8220;Books DataSet&#8221;</span><span style="color: black;">);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds = xmldoc.DataSet;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Attach dataset view to the GridView control</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">GridView1.DataSource = ds.DefaultViewManager;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">}</span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: navy;">Now See how to Save Data from<em> </em>DataSet to XML ?</span></strong><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now you will see how to save data form dataset to xml. In this you can save data of a DataSet as an XML document using the Save method of XmlDataDocument. Actually the XmlDocument class defines the Save method. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now create a DataSet object and fill it using a DataAdapter. The below shown example reads the Employees table from the Northwind Oracle database and fills the data into the DataSet.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// write the select query which details you want to retrive from database</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">string</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">query =</span> <span style="color: maroon;">&#8220;SELECT * FROM Employees&#8221;</span>;</span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Give the connection string i.e connection to the database</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: blue;">string</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"> connString =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #a31515;">Data Source=NorthWind.mdb; User ID=scott; Password=tiger&#8221;;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Create an object for the oracle data adapter and pass the quey and the connection string to the adapter</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #2b91af;">OracleDataAdapter </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">objAdapter =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">OracleDataAdapter</span><span style="color: black;">(query, connString);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">// Now the adaptor will get the data and whe have to store the data</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: green;">//So create a new dataset object and fill the dataset by using data adapter’s fill method</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">DataSet </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">ds =</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: blue;">new</span> <span style="color: teal;">DataSet</span><span style="color: black;">();</span></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">objAdapter.Fill(ds);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="margin-bottom: 0.0001pt; text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Now, you create an instance of XmlDataDocument with the DataSet as an argument and call the Save method to save the data as an XML document:</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: teal;">XmlDataDocument</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> <span style="color: black;">doc =</span> <span style="color: blue;">new</span> <span style="color: teal;">XmlDataDocument</span><span style="color: black;">(ds);</span></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">doc.Save(</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: maroon;">&#8220;C:\\XmlData.xml&#8221;</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">);</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal" style="text-align: justify; line-height: normal;"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Thats it and happy coding&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;. </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></p>
<p class="MsoNormal"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/11/programming-xml-with-c-connecting-data-and-xml-via-ado-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Controls collection cannot be modified because the control contains code blocks (i.e. ).</title>
		<link>http://www.trekinnovations.com/2008/11/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie/</link>
		<comments>http://www.trekinnovations.com/2008/11/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 13:04:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Controls collection cannot be modified because the control contains code blocks]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=136</guid>
		<description><![CDATA[The Controls collection cannot be modified because the control contains code blocks (i.e. &#60;% &#8230; %&#62;).

 
Basically this error occurs when a code block is placed in the MasterPage like this

&#60;%@  Master Language=&#8221;C#&#8221; AutoEventWireup=&#8221;True&#8221; Inherits=&#8221;TrainingWeb&#8221; CodeBehind=&#8221;TrainingWeb.master.cs&#8221; %&#62;
&#60;%@ Register Src=&#8221;UserControls/TopMenu.ascx&#8221; TagName=&#8221;TopMenu&#8221; TagPrefix=&#8221;uc1&#8243; %&#62;
&#60;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&#62;
&#60;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&#62;
&#60;head id=&#8221;Head1&#8243; runat=&#8221;server&#8221;&#62;
    &#60;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=iso-8859-1&#8243; [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial;"><span style="color: #000000;">The Controls collection cannot be modified because the control contains code blocks (i.e. &lt;% &#8230; %&gt;).</span></span></p>
<p><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial;"></p>
<div id="attachment_137" class="wp-caption alignright" style="width: 310px"><a href="http://www.trekinnovations.com/wp-content/uploads/2008/11/error.jpg"><img class="size-medium wp-image-137" title="Error Page" src="http://www.trekinnovations.com/wp-content/uploads/2008/11/error-300x187.jpg" alt="Error Page" width="300" height="187" /></a><p class="wp-caption-text">Error Page</p></div>
<p><font style="font-size: 10pt; mso-bidi-font-family: Arial;" face="Verdana"> </p>
<p></font></span><span style="font-size: 10pt; color: #000000; font-family: Verdana; mso-bidi-font-family: Arial;">Basically this error occurs when a code block is placed in the MasterPage like this</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: x-small; font-family: Verdana;"><span id="more-136"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; background: yellow; font-family: Verdana; mso-bidi-font-family: Arial; mso-highlight: yellow; mso-no-proof: yes;">&lt;%</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">@</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: #ff0000;">Master</span> <span style="color: #ff0000;">Language</span><span style="color: #0000ff;">=&#8221;C#&#8221;</span> <span style="color: #ff0000;">AutoEventWireup</span><span style="color: #0000ff;">=&#8221;True&#8221;</span> <span style="color: #ff0000;">Inherits</span><span style="color: #0000ff;">=&#8221;TrainingWeb&#8221;</span> <span style="color: #ff0000;">CodeBehind</span><span style="color: #0000ff;">=&#8221;TrainingWeb.master.cs&#8221;</span> <span style="background: yellow; mso-highlight: yellow;">%&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; background: yellow; font-family: Verdana; mso-bidi-font-family: Arial; mso-highlight: yellow; mso-no-proof: yes;">&lt;%</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">@</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #a31515;">Register</span> <span style="color: #ff0000;">Src</span><span style="color: #0000ff;">=&#8221;UserControls/TopMenu.ascx&#8221;</span> <span style="color: #ff0000;">TagName</span><span style="color: #0000ff;">=&#8221;TopMenu&#8221;</span> <span style="color: #ff0000;">TagPrefix</span><span style="color: #0000ff;">=&#8221;uc1&#8243;</span> <span style="background: yellow; mso-highlight: yellow;">%&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;!</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">DOCTYPE</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #ff0000;">html</span> <span style="color: #ff0000;">PUBLIC</span> <span style="color: #0000ff;">&#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;</span> <span style="color: #0000ff;">&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">html</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">head</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">=&#8221;Head1&#8243;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">meta</span> <span style="color: #ff0000;">http-equiv</span><span style="color: #0000ff;">=&#8221;Content-Type&#8221;</span> <span style="color: #ff0000;">content</span><span style="color: #0000ff;">=&#8221;text/html; charset=iso-8859-1&#8243;</span> <span style="color: #0000ff;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">title</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #a31515;">title</span><span style="color: #0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">link</span> <span style="color: #ff0000;">href</span><span style="color: #0000ff;">=&#8221;styles.css&#8221;</span> <span style="color: #ff0000;">rel</span><span style="color: #0000ff;">=&#8221;stylesheet&#8221;</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">=&#8221;text/css&#8221;</span> /&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="background: aqua; color: #0000ff; mso-highlight: aqua;">&lt;</span><span style="background: aqua; color: #a31515; mso-highlight: aqua;">script</span><span style="background: aqua; mso-highlight: aqua;"> <span style="color: #ff0000;">language</span><span style="color: #0000ff;">=&#8221;JavaScript&#8221;</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">=&#8217;</span>&lt;%= ResolveClientUrl(&#8220;~/mm_menu.js&#8221;)%&gt;<span style="color: #0000ff;">&#8216;&gt;&lt;/</span><span style="color: #a31515;">script</span><span style="color: #0000ff;">&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;/</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">head</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">body</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">form</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">=&#8221;form1&#8243;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221;&gt;</span></span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">ContentPlaceHolder</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">=&#8221;ContentPlaceHolder1&#8243;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221;&gt;</span></span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">ContentPlaceHolder</span><span style="color: #0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">form</span><span style="color: #0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;/</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">body</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;/</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">html</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">As you can see from the above code with the highlited colour if you mention the code block like this you can get the above error.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="color: #0000ff;">SOLUTION:</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">In order to avoid this error just<span style="mso-spacerun: yes;">  </span>copy the codeblock from the head tag to the content place holder in the master page like this</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; background: yellow; font-family: Verdana; mso-bidi-font-family: Arial; mso-highlight: yellow; mso-no-proof: yes;">&lt;%</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">@</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: #ff0000;">Master</span> <span style="color: #ff0000;">Language</span><span style="color: #0000ff;">=&#8221;C#&#8221;</span> <span style="color: #ff0000;">AutoEventWireup</span><span style="color: #0000ff;">=&#8221;True&#8221;</span> <span style="color: #ff0000;">Inherits</span><span style="color: #0000ff;">=&#8221;TrainingWeb&#8221;</span> <span style="color: #ff0000;">CodeBehind</span><span style="color: #0000ff;">=&#8221;TrainingWeb.master.cs&#8221;</span> <span style="background: yellow; mso-highlight: yellow;">%&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; background: yellow; font-family: Verdana; mso-bidi-font-family: Arial; mso-highlight: yellow; mso-no-proof: yes;">&lt;%</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">@</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #a31515;">Register</span> <span style="color: #ff0000;">Src</span><span style="color: #0000ff;">=&#8221;UserControls/TopMenu.ascx&#8221;</span> <span style="color: #ff0000;">TagName</span><span style="color: #0000ff;">=&#8221;TopMenu&#8221;</span> <span style="color: #ff0000;">TagPrefix</span><span style="color: #0000ff;">=&#8221;uc1&#8243;</span> <span style="background: yellow; mso-highlight: yellow;">%&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;!</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">DOCTYPE</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #ff0000;">html</span> <span style="color: #ff0000;">PUBLIC</span> <span style="color: #0000ff;">&#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;</span> <span style="color: #0000ff;">&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">html</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #ff0000;">xmlns</span><span style="color: #0000ff;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">head</span><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">=&#8221;Head1&#8243;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">meta</span> <span style="color: #ff0000;">http-equiv</span><span style="color: #0000ff;">=&#8221;Content-Type&#8221;</span> <span style="color: #ff0000;">content</span><span style="color: #0000ff;">=&#8221;text/html; charset=iso-8859-1&#8243;</span> <span style="color: #0000ff;">/&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">title</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #a31515;">title</span><span style="color: #0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">link</span> <span style="color: #ff0000;">href</span><span style="color: #0000ff;">=&#8221;styles.css&#8221;</span> <span style="color: #ff0000;">rel</span><span style="color: #0000ff;">=&#8221;stylesheet&#8221;</span> <span style="color: #ff0000;">type</span><span style="color: #0000ff;">=&#8221;text/css&#8221;</span> /&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;/</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">head</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">body</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">form</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">=&#8221;form1&#8243;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">ContentPlaceHolder</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">=&#8221;ContentPlaceHolder1&#8243;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="background: aqua; color: #0000ff; mso-highlight: aqua;">&lt;</span><span style="background: aqua; color: #a31515; mso-highlight: aqua;">script</span><span style="background: aqua; mso-highlight: aqua;"> <span style="color: #ff0000;">language</span><span style="color: #0000ff;">=&#8221;JavaScript&#8221;</span> <span style="color: #ff0000;">src</span><span style="color: #0000ff;">=&#8217;</span>&lt;%= ResolveClientUrl(&#8220;~/mm_menu.js&#8221;)%&gt;<span style="color: #0000ff;">&#8216;&gt;&lt;/</span><span style="color: #a31515;">script</span><span style="color: #0000ff;">&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">asp</span><span style="color: #0000ff;">:</span><span style="color: #a31515;">ContentPlaceHolder</span><span style="color: #0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">form</span><span style="color: #0000ff;">&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;/</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">body</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&lt;/</span><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">html</span><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">&gt;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: Verdana; mso-bidi-font-family: Arial; mso-no-proof: yes;">This solves the problem.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/11/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concurrence Mode Instance using WCF</title>
		<link>http://www.trekinnovations.com/2008/11/concurrence-mode-instance-using-wcf/</link>
		<comments>http://www.trekinnovations.com/2008/11/concurrence-mode-instance-using-wcf/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 15:06:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Concurrence Mode]]></category>
		<category><![CDATA[Instance using WCF]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=95</guid>
		<description><![CDATA[Concurrence Mode Instance specifies a service class supports single/multi-threaded modes of operation or not.
WCF follows an asynchronous messaging. It makes extensive use of asynchronous I/O, and as a result, each received message may be dispatched to a receiving object by different threads. Because of this feature allows WCF to use the CPU efficiently, and as [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size: 10pt; color: #000000; line-height: 115%; font-family: Verdana;"><span style="color: #000000;"><span>Concurrence Mode</span> </span>Instance specifies a service class supports single/multi-threaded modes of operation or not.</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size: 10pt; color: #000000; line-height: 115%; font-family: Verdana;">WCF follows an asynchronous messaging. It makes extensive use of asynchronous I/O, and as a result, each received message may be dispatched to a receiving object by different threads. Because of this feature allows WCF to use the CPU efficiently, and as a result, allows WCF applications to scale.</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size: 10pt; color: #000000; line-height: 115%; font-family: Verdana;">Below given example make clear the concurrence mode instance, how service class works with ConcurrencyMode instance property on the ServiceBehaviorAttribute type with respect to the client requests. </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span id="more-95"></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Types of modes:</span></p>
<p class="MsoNormal" style="MARGIN: 6pt 0cm 12pt"><strong style="mso-bidi-font-weight: normal"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"><span style="color: #0000ff;">Single:</span></span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> only one thread will access the incoming object at a time</span></p>
<p class="MsoNormal" style="MARGIN: 6pt 0cm 12pt"><strong style="mso-bidi-font-weight: normal"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"><span style="color: #0000ff;">Multiple</span></span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"><span style="color: #0000ff;">: </span>multiple threads will access the incoming object concurrently</span></p>
<p class="MsoNormal" style="MARGIN: 6pt 0cm 12pt"><strong style="mso-bidi-font-weight: normal"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"><span style="color: #0000ff;">Reentrant:</span></span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> only one thread will access the incoming object at a time, but callbacks will re-enter that object on another thread </span><span style="font-size: 10pt; color: #000000; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; font-family: Verdana;">The service class specifies ConcurrencyMode as <strong><span style="mso-no-proof: yes"><span style="mso-spacerun: yes">  </span></span></strong></span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">// Single mode will use the same instance for all the clients concurrently </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="color: #0000ff;"><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,InstanceContextMode = InstanceContextMode.Single)]</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">// PerCall will use the same instance for all the clients concurrently </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="color: #0000ff;"><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">// Multiple mode will use the multiple instance for the clients concurrently </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="color: #0000ff;"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">[</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">ServiceBehavior<strong>(ConcurrencyMode = </strong>ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">//Reentrant mode will use to call other method of another object (if required), which is not allowed in Single</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.Single)]</span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">The service class contains the following</span></p>
<p class="ListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">1.<span style="font-family: 'Times New Roman';">      </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Constructor, which is useful to create new GUID for every instance of service class</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">2.<span style="font-family: 'Times New Roman';">      </span></span></span><strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-no-proof: yes;">getInfo()</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-no-proof: yes; mso-bidi-font-weight: bold;">, returns message to the client</span></p>
<p class="ListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l0 level1 lfo2"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">3.<span style="font-family: 'Times New Roman';">      </span></span></span><strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-no-proof: yes;">getInfo2()</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-no-proof: yes; mso-bidi-font-weight: bold;">, returns message to the client</span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Implementation Steps follows as below</span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="ListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">1)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Create new <em style="mso-bidi-font-style: normal">WCF Service Library</em> Project with the name <strong style="mso-bidi-font-weight: normal">WCFLib</strong></span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">2)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Rename Iservice.cs to <span style="color: #2b91af; mso-no-proof: yes;">IServicedClass</span>.cs from Solution Explorer</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">3)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Rename Service.cs to <span style="color: #2b91af; mso-no-proof: yes;">ServicedClass</span>.cs from Solution Explorer</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">4)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add Reference to System.ServiceModel from Solution Explorer</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">5)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Write the following code in <span style="color: #2b91af; mso-no-proof: yes;">IServicedClass</span>.cs</span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> System.ServiceModel;</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">namespace</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> WCFLib</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>[</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ServiceContract</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">]</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">public</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">interface</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">IServicedClass</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>[</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">OperationContract</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">]</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> getInfo();</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>[</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">OperationContract</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">]</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> getInfo2();</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">}</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="ListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">6)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Write the following code in <span style="color: #2b91af; mso-no-proof: yes;">ServicedClass</span>.cs</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> System.ServiceModel;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> System.Threading;</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">namespace</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> WCFLib</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">     </span>/* Concurrency Start */</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">// Single mode will use the same instance for all the clients concurrently </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">//to see run 2 client programs</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">      </span>[</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ServiceBehavior</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">(ConcurrencyMode = </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ConcurrencyMode</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.Multiple, </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">          </span>InstanceContextMode = </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">InstanceContextMode</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.Single)]</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">   </span>/* Concurrency End */</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">public</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">class</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ServicedClass</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">:</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">IServicedClass</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">private</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Guid</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> id;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">public</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> ServicedClass()</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span>id = </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Guid</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.NewGuid();</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>}</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">public</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> getInfo()</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Thread</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.Sleep(3000);</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">return</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-no-proof: yes;">&#8220;*** getInfo called on Object id : &#8220;</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> + id.ToString() + </span></strong><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-no-proof: yes;">&#8220;***&#8221;</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>}</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>[</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">OperationBehavior</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">]</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">public</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> getInfo2()</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">return</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-no-proof: yes;">&#8220;*** getInfo2 called on Object id : &#8220;</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> + id.ToString() + </span></strong><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-no-proof: yes;">&#8220;***&#8221;</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">}</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt 36pt"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Note : Rebuild the service (<strong style="mso-bidi-font-weight: normal">WCFLib</strong> project) after changing the <strong style="mso-bidi-font-weight: normal">ServiceBehavior</strong> for concurrence instance. </span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">7)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Build only <strong><span style="mso-no-proof: yes">WCFLib</span></strong> project</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore"> <img src='http://www.trekinnovations.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> <span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add new <em style="mso-bidi-font-style: normal">Console Application</em> with the name<span style="mso-spacerun: yes">  </span><strong style="mso-bidi-font-weight: normal">WCFSerCon</strong> in the solution</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">9)<span style="font-family: 'Times New Roman';">     </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add Reference to System.ServiceModel</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">10)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add Reference to WCFLib.dll</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">11)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Write the following code in <span style="color: #2b91af; mso-no-proof: yes;">Program</span>.cs</span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> System.ServiceModel;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> WCFLib;</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">namespace</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> WCFSerCon</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">class</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Program</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">static</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">void</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> Main(</span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">[] args)</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ServiceHost</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> host = </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">new</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ServiceHost</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">(</span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">typeof</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">(</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ServicedClass</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">));</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> address = </span></strong><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-no-proof: yes;">&#8220;net.tcp://localhost:1099/Myobject&#8221;</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">NetTcpBinding</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> binding = </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">new</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">NetTcpBinding</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">();</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span>host.AddServiceEndpoint(</span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">typeof</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">(</span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">IServicedClass</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">), binding, address);</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span>host.Open();</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.WriteLine(<span style="color: #a31515;">&#8220;Server is Read and Running&#8230;&#8221;</span><strong>);</strong></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.ReadLine();</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">}</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">12)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Build only <strong style="mso-bidi-font-weight: normal">WCFSerCon</strong> project</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">13)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add new <em style="mso-bidi-font-style: normal">Console Application</em> with the name<span style="mso-spacerun: yes">  </span><strong style="mso-bidi-font-weight: normal">WCFClientCon</strong> in the solution</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">14)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add Reference to System.ServiceModel</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">15)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Add Reference to WCFLib.dll</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">16)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Write the following code in <span style="color: #2b91af; mso-no-proof: yes;">Program</span>.cs</span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> System.Threading;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> System.ServiceModel;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">using</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> WCFLib;</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">namespace</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> WCFClientCon</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">class</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Program</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">static</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">void</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> Main(</span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">[] args)</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">string</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> address = </span></strong><span style="font-size: 10pt; color: #a31515; font-family: Verdana; mso-no-proof: yes;">&#8220;net.tcp://localhost:1099/Myobject&#8221;</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">;</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">NetTcpBinding</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> binding = </span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">new</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">NetTcpBinding</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">();</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">ChannelFactory</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">&lt;<span style="color: #2b91af;">IServicedClass</span>&gt; cf = <span style="color: #0000ff;">new</span><strong> </strong><span style="color: #2b91af;">ChannelFactory</span>&lt;<span style="color: #2b91af;">IServicedClass</span>&gt;(binding, address);</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">IServicedClass</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> obj = cf.CreateChannel();</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">         </span></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">         </span></span></strong><span style="font-size: 10pt; color: #008000; font-family: Verdana; mso-no-proof: yes;">//Concurrancy example</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">for</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> (</span></strong><span style="font-size: 10pt; color: #0000ff; font-family: Verdana; mso-no-proof: yes;">int</span><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> i = 0; i &lt; 10; i++)</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span>{</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">                </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.Write(<span style="color: #2b91af;">DateTime</span>.Now.ToLongTimeString());</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">                </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.WriteLine(obj.getInfo());</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">                </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Thread</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.Sleep(1000);</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">                </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.WriteLine(obj.getInfo2());</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span>}</span></strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.WriteLine();</span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.WriteLine(<span style="color: #a31515;">&#8220;Press any key&#8230;&#8221;</span><strong>);</strong></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">            </span></span></strong><span style="font-size: 10pt; color: #2b91af; font-family: Verdana; mso-no-proof: yes;">Console</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">.ReadLine();</span><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">        </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;"><span style="mso-spacerun: yes">    </span>}</span></strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt 36pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"><strong><span style="font-size: 10pt; font-family: Verdana; mso-no-proof: yes;">}</span></strong><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">17)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Build only <strong style="mso-bidi-font-weight: normal">WCFClientCon</strong> project</span></p>
<p class="ListParagraphCxSpMiddle" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">18)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Set <strong style="mso-bidi-font-weight: normal">WCFSerCon </strong>as start up project and Run using ctrl+F5</span></p>
<p class="ListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">19)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Now server is ready and you can find the following screen</span> </p>
<div><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </p>
<p></span></div>
<div><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"></span></div>
<p><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"></p>
<div id="attachment_96" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.trekinnovations.com/wp-content/uploads/2008/11/wcf-concurrence1.jpg"><img class="size-medium wp-image-96" title="WCF-Concurrence" src="http://www.trekinnovations.com/wp-content/uploads/2008/11/wcf-concurrence1-300x151.jpg" alt="WCF-Concurrence Server Ready" width="300" height="151" /></a><p class="wp-caption-text">WCF-Concurrence Server Ready</p></div>
<p> </p>
<p> </p>
<p></span></span></p>
<p class="ListParagraphCxSpFirst" style="MARGIN: 0cm 0cm 0pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">20)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Set <strong style="mso-bidi-font-weight: normal">WCFClientCon </strong>as start up project and Run using ctrl+F5</span></p>
<p class="ListParagraphCxSpLast" style="MARGIN: 0cm 0cm 10pt 36pt; TEXT-INDENT: -18pt; mso-list: l1 level1 lfo1"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana; mso-bidi-font-family: Verdana; mso-fareast-font-family: Verdana;"><span style="mso-list: Ignore">21)<span style="font-family: 'Times New Roman';"> </span></span></span><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;">Now client application is executing and you can find the following output </span><span style="font-size: 10pt; font-family: Verdana;"> </span> </p>
<div><span style="font-size: 10pt; font-family: Verdana;"><div id="attachment_102" class="wp-caption aligncenter" style="width: 310px"> i.e Single mode will use the same instance for all the clients concurrently  22) Instead of the above Service concurrence Mode, if we will write the following statement in   same file, WCFLib/ServicedClass.cs [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)] i.e.  PerCall will use the same instance for all the clients concurrently  We can get the following output  WCF Cconcurrence PerCall OutPut&#8221;]<a href="http://www.trekinnovations.com/wp-content/uploads/2008/11/wcfconcurrence-output2.jpg"><img class="size-medium wp-image-102" title="WCF Concurrence-Output" src="http://www.trekinnovations.com/wp-content/uploads/2008/11/wcfconcurrence-output2-300x194.jpg" alt="WCF Concurrence- Single Output" width="300" height="194" /></a><p class="wp-caption-text">WCF Concurrence- Single Output The service class specifies ConcurrencyMode as [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple,InstanceContextMode = InstanceContextMode.Single)</p></div><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></span></div>
<div><span style="font-size: 10pt; font-family: Verdana;"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </span></span></div>
<p><span style="font-size: 10pt; font-family: Verdana;"><span style="font-size: 10pt; line-height: 115%; font-family: Verdana;"> </p>
<p></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/11/concurrence-mode-instance-using-wcf/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>What&#8217;s new on .Net 3.5 Framework &amp; Visual Studio 2008</title>
		<link>http://www.trekinnovations.com/2008/11/whats-new-on-net-35-framework-visual-studio-2008/</link>
		<comments>http://www.trekinnovations.com/2008/11/whats-new-on-net-35-framework-visual-studio-2008/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 13:54:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[New Features For .Net 3.5&VS 2008]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://www.trekinnovations.com/?p=83</guid>
		<description><![CDATA[Visual Studio 2008 &#38; .Net Framework 3.5 Features 
The newley introduced .NET Framework 3.5 with Visual Studio 2008  provides developers to rapidly create applications that deliver high quality and rich user experiences. Visual Studio 2008 and .NET 3.5 contains a ton of new functionality and improvements which enables organizations of every size to rapidly create secure, manageable, and reliable [...]]]></description>
			<content:encoded><![CDATA[<h2 style="text-align: justify;"><span style="color: #0000ff;">Visual Studio 2008 &amp; .Net Framework 3.5 Features</span><span style="color: #000000;"><span style="font-size: 11pt; color: #000000; font-family: Verdana;"><span style="font-size: 10pt; color: #000000; font-family: Verdana;"><span style="color: #000000;"><span style="font-size: 11pt; color: #000000; font-family: Verdana;"><span style="font-size: 10pt; color: #000000; font-family: Verdana;"> </span></span></span></span></span></span></h2>
<p><span style="font-size: 10pt; color: #000000; font-family: Verdana;">The newley introduced .NET Framework 3.5 with Visual Studio 2008  provides developers to rapidly create applications that deliver high quality and rich user experiences. Visual Studio 2008 and .NET 3.5 contains a ton of new functionality and improvements which enables organizations of every size to rapidly create secure, manageable, and reliable applications that are optimized for Windows Vista™, SQL Server and the Web.</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: center;"><a href="http://www.trekinnovations.com/wp-content/uploads/2008/11/visualstudio.jpg"><span style="color: #000000;"><img class="size-medium wp-image-86 aligncenter" title="VisualStudio 2008" src="http://www.trekinnovations.com/wp-content/uploads/2008/11/visualstudio-300x130.jpg" alt="" width="300" height="130" /></span></a></p>
<p style="text-align: justify;"><span style="color: #000000;"><span style="font-size: 10pt; color: #000000; font-family: Verdana;">Visual Studio .NET based Windows application benefits from increased WPF designer performance.  Web development improvements include enhanced features like JavaScript IntelliSense, JavaScript Debugging,supports SQL Server 2008, ADO.NET Entity Framework, ADO.NET Data Services. It provides more powerful new graphics for the development and provides very rich data scaffolding.</span></span> </p>
<p><span style="color: #0000ff;"><span id="more-83"></span></span></p>
<p>  </p>
<h3 style="text-align: justify;"><span style="color: #0000ff;">The .NET 3.5 Framework SP1 delivers the following:</span></h3>
<ul style="text-align: justify;">
<li>Increased Performance for WPF based applications, without having to change any code</li>
<li>WCF improvements that give developers more control over the way they access data and services</li>
<li>Improvements such as the ADO.NET Data Services, ADO.NET Entity Framework  and support for SQL Server 2008</li>
<li>ASP.NET Dynamic Data to facilitate rapid data driven development  </li>
</ul>
<h3 style="text-align: justify;"><span style="color: #0000ff;">New Features of Visual studio 2008 and .Net 3.5:</span></h3>
<p style="text-align: justify;">1. <strong>Visual Studio 2008 Multi-Targeting Support.</strong><strong>    </strong></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size: 10pt; color: #000000; font-family: Verdana;">– .NET Framework 2.0, 3.0 and 3.5</span></p>
<p style="text-align: justify;"><strong>2.<span style="font-size: small; font-family: Times New Roman;">VS 2008</span><span> CSS Web Designer and CSS Support</span></strong></p>
<p style="text-align: justify;"><strong>3.ASP.NET AJAX and JavaScript Support</strong><strong> </strong></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; font-family: Verdana;">   . Visual Studio 2008 Javascript Intellisense<br />
   • Visual Studio 2008 JavaScript Debugging.<br />
   • Visual Studio 2008 CSS Web Designer and CSS Support<br />
   • Visual Studio 2008 Vertical Split View Support</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"> </p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>4.ADO.NET Entity Framework</strong></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>5.ADO.NET Data Services</strong></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>6.ASP.NET Dynamic Data Priview</strong></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>7.Language Improvements and LINQ</strong> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;">   </p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="font-size: 10pt; color: #000000; font-family: Verdana;">    • Anonymous Types<br />
    • Extension Methods<br />
    • Lambda Expressions<br />
    . LINQ to Data Sets<br />
    • LINQ to SQL<br />
    • LINQ to XML<br />
    • LINQ to Objects</span></p>
<p> <strong><span style="color: #0000ff;">Some of Other Visual Studio 2008 Features are:</span></strong>   </p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span style="font-size: 10pt; color: #000000; font-family: Verdana;">    • In-built Silverlight Library<br />
     . Windows Communication Foundation Support<br />
    • Windows Presentation Foundation Support and WPF improvements<br />
    • Inbuilt AJAX Extender Controls<br />
    • Intellisense Improvements in visual studio 2008<br />
    • In-built C++ SDK<br />
    • Nested ASP.NET Master Pages</span></p>
<p style="text-align: justify;"> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.trekinnovations.com/2008/11/whats-new-on-net-35-framework-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
