<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4351333993867117809</id><updated>2011-07-08T04:57:57.601+05:30</updated><category term='important-links'/><title type='text'>New Reader</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-1611644225550680929</id><published>2010-05-12T14:24:00.011+05:30</published><updated>2010-05-12T19:30:19.455+05:30</updated><title type='text'>Creating Run time table in Silverlight using html </title><content type='html'>Hi, after a long time I am back with a new post. Recently during a completly dynamic silverlight framework developement I had to create dynamic layout which can create tabular layout as was created in html. eg. &lt;a href="http://3.bp.blogspot.com/_c83J-PNKWTc/S-qn_2rL55I/AAAAAAAAA5I/A9w5jeeL8h8/s1600/Table.png"&gt;&lt;img style="MARGIN: 0px 10px 10px 0px; WIDTH: 265px; FLOAT: left; HEIGHT: 175px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5470369412845135762" border="0" alt="" src="http://3.bp.blogspot.com/_c83J-PNKWTc/S-qn_2rL55I/AAAAAAAAA5I/A9w5jeeL8h8/s320/Table.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_c83J-PNKWTc/S-qqUh3MdfI/AAAAAAAAA5Q/-2DK0z9zI-4/s1600/Tablecode.png"&gt;&lt;img style="MARGIN: 0px 10px 10px 0px; WIDTH: 202px; FLOAT: left; HEIGHT: 320px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5470371967058867698" border="0" alt="" src="http://3.bp.blogspot.com/_c83J-PNKWTc/S-qqUh3MdfI/AAAAAAAAA5Q/-2DK0z9zI-4/s320/Tablecode.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can see here the html for a table and its representation. I had to read this html at runtime and create a similar layout in silverlight at run time. That layout was actually the layout of the main shell of the framework.&lt;br /&gt;The html part I put into somewhere in the clientbin and instructed in the code to read it using web-client. Once the xml was read it was sent to be processed by the service class.&lt;br /&gt;&lt;br /&gt;Entity:&lt;br /&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; VAlignment&lt;br /&gt;    {&lt;br /&gt;        bottom = 1, middle = 2, top = 3, stretch = 4&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; HAlignment&lt;br /&gt;    {&lt;br /&gt;        center = 1, left = 2, right = 3, stretch = 4&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; Unit&lt;br /&gt;    {&lt;br /&gt;        pixcel = 1, percent = 2&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TableBase&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; HAlignment _HAlign;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; VAlignment _VAlign;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _Height;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; _height;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _Width;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; _width;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SetWidth&lt;br /&gt;        {&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                _Width = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(_Width, &lt;span class="kwrd"&gt;out&lt;/span&gt; _width))&lt;br /&gt;                {&lt;br /&gt;                    WidthUnit = Unit.pixcel;&lt;br /&gt;                }&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (_Width.Trim().Length &amp;gt; 0 &amp;amp;&amp;amp; _Width.Trim().Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] { &lt;span class="str"&gt;'%'&lt;/span&gt; }).Length &amp;gt; 1)&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(_Width.Trim().Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] { &lt;span class="str"&gt;'%'&lt;/span&gt; })[0], &lt;span class="kwrd"&gt;out&lt;/span&gt; _width))&lt;br /&gt;                        {&lt;br /&gt;                            WidthUnit = Unit.percent;&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (_Width.Trim().Length &amp;gt; 0 &amp;amp;&amp;amp; _Width.Trim().Substring(_Width.Trim().Length - 2, _Width.Trim().Length).ToLower() == &lt;span class="str"&gt;"px"&lt;/span&gt;)&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(_Width.Trim().Substring(0, _Width.Trim().Length - 2), &lt;span class="kwrd"&gt;out&lt;/span&gt; _width))&lt;br /&gt;                            {&lt;br /&gt;                                WidthUnit = Unit.pixcel;&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _Width;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; GetWidth&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _width;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SetHeight&lt;br /&gt;        {&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                _Height = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(_Height, &lt;span class="kwrd"&gt;out&lt;/span&gt; _height))&lt;br /&gt;                {&lt;br /&gt;                    HeightUnit = Unit.pixcel;&lt;br /&gt;                }&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (_Height.Trim().Length &amp;gt; 0 &amp;amp;&amp;amp; _Height.Trim().Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] { &lt;span class="str"&gt;'%'&lt;/span&gt; }).Length &amp;gt; 1)&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(_Height.Trim().Split(&lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;char&lt;/span&gt;[] { &lt;span class="str"&gt;'%'&lt;/span&gt; })[0], &lt;span class="kwrd"&gt;out&lt;/span&gt; _height))&lt;br /&gt;                        {&lt;br /&gt;                            HeightUnit = Unit.percent;&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (_Height.Trim().Length &amp;gt; 0 &amp;amp;&amp;amp; _Height.Trim().Substring(_Height.Trim().Length - 2, _Height.Trim().Length).ToLower() == &lt;span class="str"&gt;"px"&lt;/span&gt;)&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.TryParse(_Height.Trim().Substring(0, _Height.Trim().Length - 2), &lt;span class="kwrd"&gt;out&lt;/span&gt; _height))&lt;br /&gt;                            {&lt;br /&gt;                                HeightUnit = Unit.pixcel;&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _Height;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; GetHeight&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _height;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Unit WidthUnit { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Unit HeightUnit { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SetHAlign&lt;br /&gt;        {&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"center"&lt;/span&gt;) _HAlign = HAlignment.center;&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"left"&lt;/span&gt;) _HAlign = HAlignment.left;&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"right"&lt;/span&gt;) _HAlign = HAlignment.right;&lt;br /&gt;                        &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"stretch"&lt;/span&gt;) _HAlign = HAlignment.stretch;&lt;br /&gt;                            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                                _HAlign = HAlignment.center;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; HAlignment GetHAlign&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _HAlign;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; SetVAlign&lt;br /&gt;        {&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"middle"&lt;/span&gt;) _VAlign = VAlignment.middle;&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"bottom"&lt;/span&gt;) _VAlign = VAlignment.bottom;&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"top"&lt;/span&gt;) _VAlign = VAlignment.top;&lt;br /&gt;                        &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower() == &lt;span class="str"&gt;"stretch"&lt;/span&gt;) _VAlign = VAlignment.stretch;&lt;br /&gt;                            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                                _VAlign = VAlignment.middle;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; VAlignment GetVAlign&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; _VAlign;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Table : TableBase&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; List&amp;lt;TypeRow&amp;gt; TR { get; set; }&lt;br /&gt;    }&lt;/pre&gt;---------------------------------------------------------------------------------------------&lt;br /&gt;Helper Class:&lt;br /&gt;&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; XElement XMLStructure()&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; XElement.Load(&lt;span class="str"&gt;@"Data/LayoutStructure.xml"&lt;/span&gt;);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;Table&amp;gt; GetTables()&lt;br /&gt;        {&lt;br /&gt;            XElement documentRoot = XMLStructure();&lt;br /&gt;            List&amp;lt;Table&amp;gt; tblList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Table&amp;gt;();&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (XNode node &lt;span class="kwrd"&gt;in&lt;/span&gt; documentRoot.Nodes())&lt;br /&gt;            {&lt;br /&gt;                XElement childElement = XElement.Parse(node.ToString());&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (childElement.Name.LocalName == &lt;span class="str"&gt;"table"&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    Table tbl = &lt;span class="kwrd"&gt;new&lt;/span&gt; Table();&lt;br /&gt;                    tbl.Name = childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetWidth = childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetHeight = childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetHAlign = childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetVAlign = childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                    tbl.TR = getTR(childElement);&lt;br /&gt;                    tblList.Add(tbl);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; tblList;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;TypeRow&amp;gt; getTR(XElement doc)&lt;br /&gt;        {&lt;br /&gt;            List&amp;lt;TypeRow&amp;gt; trList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;TypeRow&amp;gt;();&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (XNode node &lt;span class="kwrd"&gt;in&lt;/span&gt; doc.Nodes())&lt;br /&gt;            {&lt;br /&gt;                XElement childElement = XElement.Parse(node.ToString());&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (childElement.Name.LocalName == &lt;span class="str"&gt;"tr"&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    TypeRow tr = &lt;span class="kwrd"&gt;new&lt;/span&gt; TypeRow();&lt;br /&gt;                    tr.Name = childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tr.SetWidth = childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tr.SetHeight = childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tr.SetHAlign = childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tr.SetVAlign = childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                    tr.TD = getTD(childElement);&lt;br /&gt;                    trList.Add(tr);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; trList;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;TypeData&amp;gt; getTD(XElement doc)&lt;br /&gt;        {&lt;br /&gt;            List&amp;lt;TypeData&amp;gt; tdList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;TypeData&amp;gt;();&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (XNode node &lt;span class="kwrd"&gt;in&lt;/span&gt; doc.Nodes())&lt;br /&gt;            {&lt;br /&gt;                XElement childElement = XElement.Parse(node.ToString());&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (childElement.Name.LocalName == &lt;span class="str"&gt;"td"&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    TypeData td = &lt;span class="kwrd"&gt;new&lt;/span&gt; TypeData();&lt;br /&gt;                    td.Name = childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    td.SetWidth = childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    td.SetHeight = childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    td.SetHAlign = childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    td.SetVAlign = childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                    td.TABLE = getTable(childElement);&lt;br /&gt;                    tdList.Add(td);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; tdList;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;Table&amp;gt; getTable(XElement obj)&lt;br /&gt;        {&lt;br /&gt;            List&amp;lt;Table&amp;gt; tblList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Table&amp;gt;();&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (XNode node &lt;span class="kwrd"&gt;in&lt;/span&gt; obj.Nodes())&lt;br /&gt;            {&lt;br /&gt;                XElement childElement = XElement.Parse(node.ToString());&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (childElement.Name.LocalName == &lt;span class="str"&gt;"table"&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    Table tbl = &lt;span class="kwrd"&gt;new&lt;/span&gt; Table();&lt;br /&gt;                    tbl.Name = childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"id"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetWidth = childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"width"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetHeight = childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"height"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetHAlign = childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"align"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;                    tbl.SetVAlign = childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;) != &lt;span class="kwrd"&gt;null&lt;/span&gt; ? childElement.Attribute(&lt;span class="str"&gt;"valign"&lt;/span&gt;).Value : &lt;span class="str"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;                    tbl.TR = getTR(childElement);&lt;br /&gt;                    tblList.Add(tbl);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; tblList;&lt;br /&gt;        }&lt;/pre&gt;------------------------------------------------------------------------------------------&lt;br /&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Service Class:&lt;/span&gt;&lt;/pre&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; UIElement GetUI()&lt;br /&gt;{&lt;br /&gt;    GridList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Grid&amp;gt;();&lt;br /&gt;    IEnumerable&amp;lt;Table&amp;gt; TableCollection = XmlHelper.GetTables();&lt;br /&gt;    Grid grd = &lt;span class="kwrd"&gt;new&lt;/span&gt; Grid();&lt;br /&gt;    grd.SetValue(Grid.RowProperty, 0);&lt;br /&gt;    grd.SetValue(Grid.ColumnProperty, 0);&lt;br /&gt;    grd.Width = LayoutWidth;&lt;br /&gt;    grd.Height = LayoutHeight;&lt;br /&gt;    &lt;span class="kwrd"&gt;if&lt;/span&gt; (TableCollection.Count() &amp;gt; 0)&lt;br /&gt;    {&lt;br /&gt;        grd = CreateTable(TableCollection.First(), grd);&lt;br /&gt;        SetPostProperties(grd);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; grd;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetPostProperties(Grid grd)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="kwrd"&gt;double&lt;/span&gt; widthSum=0, heightSum=0, cntWidth=0, cntHeight=0;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (grd.Children.Count != grd.RowDefinitions.Count)&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (UIElement ele &lt;span class="kwrd"&gt;in&lt;/span&gt; grd.Children)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (ele.GetType().Name == &lt;span class="str"&gt;"Grid"&lt;/span&gt;)&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;double&lt;/span&gt;.IsNaN(((Grid)ele).Width))&lt;br /&gt;                            widthSum += ((Grid)ele).Width;&lt;br /&gt;                        &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                            cntWidth += 1;&lt;br /&gt;&lt;br /&gt;               &lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (grd.Children.Count != grd.ColumnDefinitions.Count)&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (UIElement ele &lt;span class="kwrd"&gt;in&lt;/span&gt; grd.Children)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (ele.GetType().Name == &lt;span class="str"&gt;"Grid"&lt;/span&gt;)&lt;br /&gt;                    {&lt;br /&gt;              &lt;br /&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;double&lt;/span&gt;.IsNaN(((Grid)ele).Height))&lt;br /&gt;                            heightSum += ((Grid)ele).Height;&lt;br /&gt;                        &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                            cntHeight += 1;&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt;(cntWidth==0) cntWidth=1;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt;(cntHeight==0) cntHeight=1;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (UIElement ele &lt;span class="kwrd"&gt;in&lt;/span&gt; grd.Children)&lt;br /&gt;            {&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (ele.GetType().Name == &lt;span class="str"&gt;"Grid"&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.IsNaN(((Grid)ele).Width) &amp;amp;&amp;amp; cntWidth&amp;gt;0) ((Grid)ele).Width = (((Grid)((Grid)ele).Parent).Width - widthSum) / cntWidth;&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;double&lt;/span&gt;.IsNaN(((Grid)ele).Height) &amp;amp;&amp;amp; cntHeight&amp;gt;0) ((Grid)ele).Height = (((Grid)((Grid)ele).Parent).Height - heightSum) / cntHeight;&lt;br /&gt;&lt;br /&gt;                    SetPostProperties((Grid)ele);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span class="preproc"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; Grid CreateTable(Table tab, Grid grd)&lt;br /&gt;        {&lt;br /&gt;            grd = SetGridProperty(tab, grd);&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (TypeRow tr &lt;span class="kwrd"&gt;in&lt;/span&gt; tab.TR)&lt;br /&gt;            {&lt;br /&gt;                RowDefinition rd = &lt;span class="kwrd"&gt;new&lt;/span&gt; RowDefinition();&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (tr.HeightUnit == 0)&lt;br /&gt;                    rd.Height = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(1.0,GridUnitType.Star);&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    rd.Height = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(tr.GetHeight);&lt;br /&gt;&lt;br /&gt;                grd.RowDefinitions.Add(rd);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0;&lt;br /&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (TypeRow tr &lt;span class="kwrd"&gt;in&lt;/span&gt; tab.TR)&lt;br /&gt;            {&lt;br /&gt;                Grid grdchild = &lt;span class="kwrd"&gt;new&lt;/span&gt; Grid();&lt;br /&gt;                grdchild = SetGridProperty(tr, grdchild);&lt;br /&gt;                grdchild.SetValue(Grid.RowProperty, i);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (TypeData td &lt;span class="kwrd"&gt;in&lt;/span&gt; tr.TD)&lt;br /&gt;                {&lt;br /&gt;                    ColumnDefinition cd = &lt;span class="kwrd"&gt;new&lt;/span&gt; ColumnDefinition();&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (td.WidthUnit == 0)&lt;br /&gt;                        cd.Width = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(1.0, GridUnitType.Star);&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                        cd.Width = &lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(td.GetWidth);&lt;br /&gt;                    grdchild.ColumnDefinitions.Add(cd);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;int&lt;/span&gt; j = 0;&lt;br /&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (TypeData td &lt;span class="kwrd"&gt;in&lt;/span&gt; tr.TD)&lt;br /&gt;                {&lt;br /&gt;                    Grid grdgrandchild = &lt;span class="kwrd"&gt;new&lt;/span&gt; Grid();&lt;br /&gt;                    grdgrandchild = SetGridProperty(td, grdgrandchild);            &lt;br /&gt;                    grdgrandchild.SetValue(Grid.ColumnProperty, j);&lt;br /&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (td.TABLE.Count &amp;gt; 0)&lt;br /&gt;                    {&lt;br /&gt;                        Grid paramGrid = &lt;span class="kwrd"&gt;new&lt;/span&gt; Grid();&lt;br /&gt;                        paramGrid.SetValue(Grid.RowProperty, i);&lt;br /&gt;                        paramGrid.SetValue(Grid.ColumnProperty, j);&lt;br /&gt;                        Table childtab = td.TABLE.First();&lt;br /&gt;                        grdgrandchild.Children.Add(CreateTable(childtab, paramGrid));&lt;br /&gt;                        &lt;span class="rem"&gt;//SetGridProperty(childtab, paramGrid);&lt;/span&gt;&lt;br /&gt;                    }&lt;br /&gt;                    j++;&lt;br /&gt;&lt;br /&gt;                    GridList.Add(grdgrandchild);&lt;br /&gt;                    grdchild.Children.Add(grdgrandchild);&lt;br /&gt;                    &lt;span class="rem"&gt;//SetGridProperty(td, grdgrandchild);&lt;/span&gt;&lt;br /&gt;                }&lt;br /&gt;                GridList.Add(grdchild);&lt;br /&gt;                grd.Children.Add(grdchild);&lt;br /&gt;                &lt;span class="rem"&gt;//SetGridProperty(tr, grdchild);&lt;/span&gt;&lt;br /&gt;                i++;&lt;br /&gt;            }&lt;br /&gt;            GridList.Add(grd);&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; grd;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; Grid SetGridProperty(TableBase tab, Grid grd)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class="rem"&gt;//grd.ShowGridLines = true;&lt;/span&gt;&lt;br /&gt;            &lt;span class="rem"&gt;//grd.Background = new SolidColorBrush(Colors.Orange);&lt;/span&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt;(tab.Name!=&lt;span class="str"&gt;""&lt;/span&gt;)&lt;br /&gt;                grd.Name = tab.Name;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.Name == &lt;span class="str"&gt;"ContentGrid"&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                grd.ColumnDefinitions.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ColumnDefinition() {Width=&lt;span class="kwrd"&gt;new&lt;/span&gt; GridLength(0.0) });&lt;br /&gt;                grd.ColumnDefinitions.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ColumnDefinition());&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (grd.Parent != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; grd.Parent.GetType().Name == &lt;span class="str"&gt;"Grid"&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                grd.Width = ((Grid)grd.Parent).ActualWidth;&lt;br /&gt;                grd.Height = ((Grid)grd.Parent).ActualHeight;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.WidthUnit == Unit.percent)&lt;br /&gt;                grd.Width = (grd.ActualWidth * tab.GetWidth) / 100;&lt;br /&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.WidthUnit == Unit.pixcel)&lt;br /&gt;                    grd.Width = tab.GetWidth;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.HeightUnit == Unit.percent)&lt;br /&gt;                grd.Height = (grd.ActualHeight * tab.GetHeight) / 100;&lt;br /&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.HeightUnit == Unit.pixcel)&lt;br /&gt;                    grd.Height = tab.GetHeight;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetVAlign == VAlignment.bottom) grd.VerticalAlignment = VerticalAlignment.Bottom;&lt;br /&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetVAlign == VAlignment.middle) grd.VerticalAlignment = VerticalAlignment.Center;&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetVAlign == VAlignment.stretch) grd.VerticalAlignment = VerticalAlignment.Stretch;&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetVAlign == VAlignment.top) grd.VerticalAlignment = VerticalAlignment.Top;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetHAlign == HAlignment.center) grd.HorizontalAlignment = HorizontalAlignment.Center;&lt;br /&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetHAlign == HAlignment.left) grd.HorizontalAlignment = HorizontalAlignment.Left;&lt;br /&gt;                &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetHAlign == HAlignment.right) grd.HorizontalAlignment = HorizontalAlignment.Right;&lt;br /&gt;                    &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (tab.GetHAlign == HAlignment.stretch) grd.HorizontalAlignment = HorizontalAlignment.Stretch;&lt;br /&gt;&lt;br /&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; grd;&lt;br /&gt;        }&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-1611644225550680929?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/1611644225550680929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=1611644225550680929' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1611644225550680929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1611644225550680929'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2010/05/creating-run-time-table-in-silverlight.html' title='Creating Run time table in Silverlight using html &lt;tr&gt;&lt;td&gt;'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_c83J-PNKWTc/S-qn_2rL55I/AAAAAAAAA5I/A9w5jeeL8h8/s72-c/Table.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-3868532856316761440</id><published>2007-12-17T12:39:00.000+05:30</published><updated>2007-12-17T12:54:38.139+05:30</updated><title type='text'>MVC Framework - The bird’s eye view</title><content type='html'>&lt;span style="font-size:85%;"&gt;During the weekend I came across Dino Esposito’s blog and found few interesting lines. Here it goes…&lt;br /&gt;&lt;em&gt;&lt;span style="color:#330099;"&gt;“It seems that the bar of software preview has been moved one more tick down. There was a time when any software was top secret until publicly released. Next, we assisted to pre-release announcements and demos. Next, we were allowed to play ourselves with beta versions for longer and longer times. And our feedback was first appreciated and then requested. Next, it was the season of CTPs, progressive alpha versions that precede the beta stage–the teen-age of software.With the MVC framework we reached the notable point of publicly discussing a piece of software that is not even a CTP. I wonder what would be the next step. Discussing ideas, I bet. And after that?”&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;It made me enough curious about MVC Framework May be not because I am very aggressive about new things but at least because you must be updated every minute in this industry or just get ready to die and that I don’t want…&lt;br /&gt;There is not enough material available on this as it is in its infancy but I found some interesting things that I want to share with you…The first thing is the ScottGu’s presentation on this at Alt.Net. &lt;/span&gt;&lt;a href="http://www.hanselman.com/blog/ScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx"&gt;&lt;span style="font-size:85%;"&gt;See video&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt;. And next is &lt;/span&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx"&gt;&lt;span style="font-size:85%;"&gt;ScottGu’s blog&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; on the same. These two sources are native and apart from them I went across several blogs from the attendees of the Alt.Net presentation. I tried to assemble all the main content and some of my findings in this article and hope it might be helpful.&lt;br /&gt;Starting with some issues…Being an ASP.Net developer I often run through a problem – How to write a unit test in a tightly coupled system. You may ask why to develop a tightly coupled application if I want to follow the test driven design. Then what I can do…I can use the MVC (Master view controller) pattern to develop my application. In fact ASP.Net itself supports the MVC by code behind model where you can say each aspx.vb class as a controller and aspx as a view. I will brief about the MVC as we will go a little further. For now I am stating another problem…ASP.Net is based on two primary things…Postback and Viewstate. And both of them have several problems associated with them. Trust me. Just do a googling on the phrase “Viewstate Problem” and you will find millions of entries.&lt;br /&gt;So as the name suggests, MVC Framework is primarily based on and tried to remove the complexity of implementation of MVC design pattern. What is MVC pattern is all about?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:85%;"&gt;Model-View-Controller (MVC) Pattern&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes.&lt;br /&gt;&lt;strong&gt;Model.&lt;/strong&gt; The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).&lt;br /&gt;&lt;strong&gt;View.&lt;/strong&gt; The view manages the display of information.&lt;br /&gt;&lt;strong&gt;Controller.&lt;/strong&gt; The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;It is important to note that both the view and the controller depend on the model. However, the model depends on neither the view nor the controller. This is one the key benefits of the separation. This separation allows the model to be built and tested independent of the visual presentation. The separation between view and controller is secondary in many rich-client applications, and, in fact, many user interface frameworks implement the roles as one object. In Web applications, on the other hand, the separation between view (the browser) and controller (the server-side components handling the HTTP request) is very well defined. &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms998540.aspx"&gt;&lt;span style="font-size:85%;"&gt;Read More&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; to learn how to implement MVC pattern.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;strong&gt;Now, in ScottGu’s word some of the key points of MVC Framework:&lt;/strong&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="color:#6633ff;"&gt;It enables clean separation of concerns, testability, and TDD(Test Driven Design) by default. All core contracts within the MVC framework are interface based and easily mockable (it includes interface based IHttpRequest/IHttpResponse intrinsics). You can unit test the application without having to run the Controllers within an ASP.NET process (making unit testing fast). You can use any unit testing framework you want to-do this testing (including NUnit, MBUnit, MS Test, etc). &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="color:#6633ff;"&gt;It is highly extensible and pluggable. Everything in the MVC framework is designed so that it can be easily replaced/customized (for example: you can optionally plug-in your own view engine, routing policy, parameter serialization, etc). It also supports using existing dependency injection and IOC container models (Windsor, Spring.Net, NHibernate, etc). &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="color:#6633ff;"&gt;It includes a very powerful URL mapping component that enables you to build applications with clean URLs. URLs do not need to have extensions within them, and are designed to easily support SEO and REST-friendly naming patterns. For example, I could easily map the /products/edit/4 URL to the “Edit” action of the ProductsController class in my project above, or map the /Blogs/scottgu/10-10-2007/SomeTopic/ URL to a “DisplayPost” action of a BlogEngineController class. &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="color:#6633ff;"&gt;The MVC framework supports using the existing ASP.NET .ASPX, .ASCX, and .Master markup files as “view templates” (meaning you can easily use existing ASP.NET features like nested master pages, &lt;%= %&gt; snippets, declarative server controls, templates, data-binding, localization, etc). It does not, however, use the existing post-back model for interactions back to the server. Instead, you’ll route all end-user interactions to a Controller class instead - which helps ensure clean separation of concerns and testability (it also means no viewstate or page lifecycle with MVC based views). &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="color:#6633ff;"&gt;The ASP.NET MVC framework fully supports existing ASP.NET features like forms/windows authentication, URL authorization, membership/roles, output and data caching, session/profile state management, health monitoring, configuration system, the provider architecture, etc.&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;There are some good implementation examples available on this framework:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;/span&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx"&gt;&lt;span style="font-size:85%;"&gt;ASP.NET MVC Framework by ScottGu&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/li&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;li&gt;&lt;/span&gt;&lt;a href="http://blogs.msdn.com/brada/archive/2007/11/14/rss-feed-with-the-new-asp-net-mvc-framework.aspx"&gt;&lt;span style="font-size:85%;"&gt;RSS Feed with the new ASP.NET MVC Framework by Brad Abrams&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/li&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;li&gt;&lt;/span&gt;&lt;a href="http://www.hanselman.com/silverlight/ScottHaAtAltNetConf/"&gt;&lt;span style="font-size:85%;"&gt;Hanselman’s demo at Alt.Net conference.&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:85%;"&gt;I guess, now you are much familiar with MVC framework, but this is the time to elaborate few of the points that ScottGu has pointed out in his blog. The first point is Dependency Injection. What is this??? Now a day the focus is on reusing existing components and wiring together disparate components to form a cohesive architecture. But this wiring can quickly become a scary task because as application size and complexity increase, so do dependencies. One way to mitigate the proliferation of dependencies is by using Dependency Injection (DI), which allows you to inject objects into a class, rather than relying on the class to create the object itself. Wanna go in detail? Wait for my next post in which I am planning to elaborate DI and Spring.Net and describe about limitations of Factory, Abstract Factory, Builder and Container.&lt;br /&gt;&lt;br /&gt;The next thing that ScottGu has talked about is REST (Representational State Transfer)…&lt;br /&gt;Well, REST is an architectural pattern that defines how network resources should be defined and addressed in order to gain shorter response times, clear separation of concerns between the front-end and back-end of a networked system. REST is based on three following principles:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;An application expresses its state and implements its functionality by acting on logical resources.&lt;/li&gt;&lt;li&gt;Each resource is addressed using a specific URL syntax.&lt;/li&gt;&lt;li&gt;All addressable resources feature a contracted set of operations.&lt;/li&gt;&lt;/ul&gt;As you can see, the MVC Framework fulfills it entirely.&lt;br /&gt;&lt;br /&gt;The MVC Framework doesn’t support classic postbacks and viewstate and doesn’t consider any URL as the endpoint to a physical server file to parse and compile to a class. In ASP.NET, you have a 1:1 correspondence between a URL and a resource. The only exception to this rule is when you use completely custom HTTP handlers bound to a particular path.&lt;br /&gt;&lt;br /&gt;In the MVC Framework, a URL is seen as the mean to address a logical server resource, but not necessarily an ASPX file to parse. So the URLs employed by the pages of an MVC Framework application have a custom format that the application itself mandates. In the end, the MVC Framework employs a centralized HTTP handler that recognizes an application-specific syntax for links. In addition, each addressable resource exposes a well-known set of operations and a uniform interface for executing operations.&lt;br /&gt;&lt;br /&gt;So here’s an alternate way of looking at the MVC Framework. It is an ASP.NET framework that performs data exchange by using a REST model versus the postback model of classic ASP.NET. Each page is split into two distinct components -controller and view - that operate over the same model of data. This is opposed to the classic code-behind model where no barrier is set that forces you to think in terms of separation of concerns and controllers and views. However, by keeping the code-behind class as thin as possible, and designing the business layer appropriately, a good developer could achieve separation of concerns even without adopting MVC and its overhead. MVC, however, is a model superior to a properly-done code-behind for its inherent support for test-driven development.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-3868532856316761440?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/3868532856316761440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=3868532856316761440' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/3868532856316761440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/3868532856316761440'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/12/mvc-framework-birds-eye-view.html' title='MVC Framework - The bird’s eye view'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-8469589632535011914</id><published>2007-09-18T23:08:00.001+05:30</published><updated>2009-12-07T16:12:19.429+05:30</updated><title type='text'></title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-8469589632535011914?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/8469589632535011914/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=8469589632535011914' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/8469589632535011914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/8469589632535011914'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/09/blog-post.html' title=''/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-7795819395834508926</id><published>2007-09-18T23:00:00.000+05:30</published><updated>2007-09-18T23:05:49.064+05:30</updated><title type='text'></title><content type='html'>&lt;a href="http://www.eggheadcafe.com/articles/20060407.asp"&gt;Caching concept : ASP.Net&lt;/a&gt; - Get very nice article on caching concepts in ASP.Net 2.o&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-7795819395834508926?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/7795819395834508926/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=7795819395834508926' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/7795819395834508926'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/7795819395834508926'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/09/caching-concept-asp.html' title=''/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-7751532224406156516</id><published>2007-07-25T23:14:00.000+05:30</published><updated>2007-07-25T23:22:27.138+05:30</updated><title type='text'>Visual Studio Orcas features</title><content type='html'>&lt;span style="font-size:85%;"&gt;Visual Studio Orcas, due for release at the end of 2007, promises numerous improvements for Visual Basic, a data query called the Language Integrated Query (LINQ), a new Entity Framework for ADO.NET and updated tools for ASP.NET AJAX and Office 2007 &lt;span style="font-family:georgia;"&gt;development&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Multi-targeting&lt;/strong&gt;&lt;br /&gt;Visual Studio Orcas is &lt;span &gt;billed&lt;/span&gt; as the design surface for the .NET Framework 3.5, which itself is the merger of the .NET 3.0 toolset introduced earlier this year with updated versions of ASP.NET, ADO.NET, Visual Basic, C# and the CLR.&lt;br /&gt;At the same time, though, Orcas allows developers to work backwards and develop specifically for .NET 2.0 or 3.0. In the words of Jeff King, program manager on the Visual Studio team, the tool and the framework are decoupled: "It really buys you freedom."&lt;br /&gt;Once a framework version has been selected, Visual Studio Orcas will enable the reference features that are appropriate for that version of the framework. (In other words, don't try using LINQ in a .NET 2.0 application.)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;N-tier application development&lt;br /&gt;&lt;/strong&gt;An n-tier application is spread among any number of different systems, typically a service layer, an access layer and a business logic layer. With such a model, it is easy to share validation logic between entities, said Young Joo, a Visual Basic program manager.&lt;br /&gt;Unfortunately, developing such applications in Visual Studio 2005 is "pretty much impossible," Joo said, because a dataset and the code that connects it to a database are in the same file. The change in Visual Studio Orcas is subtle but important, as the table and the dataset now reside in different layers.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;An improved designer&lt;br /&gt;&lt;/strong&gt;King described the Visual Studio 2005 designer as little more the Internet Explorer renderer turned into an editor. To improve upon this, the Visual Studio group turned to Expression, the Microsoft product suite for Web designers.&lt;br /&gt;The new designer allows developers to apply styles in line, with an existing class, with a new class or with Internet Explorer. "We default manually nowadays," King said. In addition, changes such as margins and paddings around images can be applied to rules and not just individually. This also makes for cleaner CSS files.&lt;br /&gt;Finally, the designer offers a split view, so developers can look at source code and design simultaneously. This is a response to the growing trend of development using two monitors, King said.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ASP.NET AJAX and VSTO for Office 2007&lt;/strong&gt;&lt;br /&gt;Right now, developers aiming to build cutting edge Web applications have to download the ASP.NET AJAX framework, and those who want to develop for Office 2007 have to download Visual Studio 2005 Tools for Office Second Edition.&lt;br /&gt;Both ASP.NET AJAX and VSTO 2005 SE will be directly incorporated into Visual Studio Orcas. VSTO will come with a new runtime, which will run both Office 2007 and Office 2003 add-ins, while ASP.NET AJAX will come with a variety of JavaScript tools, such as IntelliSense and robust debugging.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;The ADO.NET Entity Framework&lt;br /&gt;&lt;/strong&gt;The biggest changes to ADO.NET revolve around its Entity Framework, which, unfortunately, is now slated to be released quite a while after Visual Studio 2008. This framework consists of a conceptual layer, which fits between an application's logical database layer and its object layer, and the Entity Data Model, said Julia Lerman, consultant and owner of The Data Farm.&lt;br /&gt;Run the Entity Data Model Wizard in Visual Studio Orcas and the output is three files -- a conceptual model that talks to object classes, a logical model that the relational database talks to, and map between the conceptual and logical models.&lt;br /&gt;Within the conceptual layer, one finds entity types bundled into sets, associations that define the relationship between entities, and sets of associations. The information in this layer will handle the back and forth with SQL Server without touching data access code, Lerman said.&lt;br /&gt;Once entities have been created, developers can use the either CreateQuery or new LINQ to Entities query to retrieve entity objects, data records or anonymous types, Lerman said.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;LINQ: The Language Integrated Query&lt;br /&gt;&lt;/strong&gt;In Visual Studio 2005, querying a dataset typically involves a stored procedure, a newly created view and a bit of ADO.NET filtering. This is the case because data exists in rows, while .NET code deals with objects. "They are always two different worlds," said Jeff King, a program manager on the Visual Studio team. "LINQ puts queries inside the languages and merges the worlds together."&lt;br /&gt;At its most basic level, the Language Integrated Query, a feature of both Visual Basic and C#, uses the concept of the SQL Select statement to make its queries. However, there are two important differences, said Markus Egger, president and chief software architect at EPS Software Corp. and publisher of CoDe Magazine.&lt;br /&gt;First, LINQ statements begin with a From statement instead of the Select statement. By listing the data source first, IntelliSense is triggered, Egger said.&lt;br /&gt;Second, since C# and Visual Basic are object-oriented languages, he said, "whatever you can express in C# or VB you can make part of LINQ queries." This encompasses anything that is IEnumerable -- entities, collections and even XML. Moreover, since the queries are being made in an object-oriented environment, Egger said, "you can do very, very complex things that result in a completely different result set," such as calling up an instance of objects that did not exist in the source at all.&lt;br /&gt;LINQ also brings about the introduction of several new language concepts for Visual Basic and C#. The expression tree, for example, is a data representation of the LINQ expression that bridges the gap between the .NET code and the SQL Server. In addition, property initialization makes it possible to create an object and set its properties in a single line of code.&lt;br /&gt;Other new language concepts, which will be discussed below, include implicit types and extension methods.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;VB 9: Implicit types&lt;/strong&gt;&lt;br /&gt;In a nutshell, author and consultant Billy Hollis said, implicit types provide strong typing without forcing developers to figure out the type they need. The compiler does the work for them, since the type is inferred from the initializer expression.&lt;br /&gt;Implicit types work well when looping through a collection, Hollis said, since in such a scenario a developer is likely to be looking only for a key and a value and will not know, or care, what the index type is.&lt;br /&gt;In addition, inferring types makes it possible for extensions to bind to data types such as XML. This is fundamental to making LINQ work, Hollis said.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;VB 9: Extension Methods&lt;/strong&gt;&lt;br /&gt;Extension methods, which Hollis described as "syntactic sugar," are another Visual Basic 9 feature coming straight from LINQ, since all LINQ query operators are extension methods. These methods are marked with custom attributes and are then added to other objects automatically (so long as they are not already there).&lt;br /&gt;Hollis said extension methods can be used just about anywhere a developer would use a normal function. However, they cannot contain optional parameters, parameter arrays or generic arguments that have not been typed. Also, late binding cannot be done with extension methods, he said.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;VB 9: IntelliSense&lt;br /&gt;&lt;/strong&gt;IntelliSense, already referred to as "Intellicrack" in some development circles, is set in Visual Basic 9 to encompass keywords, member variables and anything in scope. "Anything that would make sense there, IntelliSense will put it in," Hollis said.&lt;br /&gt;Moreover, IntelliSense will work with implicit types, once the compiler has figured out what is they type, Egger said.&lt;br /&gt;In addition, LINQ, as stated, is set up to take advantage of IntelliSense. In SQL syntax, the Select query comes first, but in LINQ, the From statement comes first. With the data source listed first, IntelliSense has a chance to kick in.&lt;br /&gt;VB 9: Relaxed delegates, initializers and more For additional information on what's new in Visual Basic 9, including relaxed delegates and initializers, check out the MSDN article Overview of Visual Basic 9.0. The emphasis there is on productivity gains developers can expect to enjoy when building data-oriented applications with an increasingly dynamic language. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-7751532224406156516?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/7751532224406156516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=7751532224406156516' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/7751532224406156516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/7751532224406156516'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/07/visual-studio-orcas-features.html' title='Visual Studio Orcas features'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-1639150649011135499</id><published>2007-07-05T11:32:00.000+05:30</published><updated>2007-07-05T12:30:37.006+05:30</updated><title type='text'>Application Development: What's new in ADO.NET version 2.0</title><content type='html'>&lt;span class="contentText"&gt;With the first, public alpha version of the coming release of Visual Studio .NET—christened "Whidbey"—now in the hands of developers, it's time to start thinking about your applications and how they might be affected as you move to this new version. Although the move from version 1.0 to 1.1 of the .NET Framework was trivial and involved mostly bug fixes, performance enhancements, and the integration of previously separate technologies such as the ODBC and Oracle .NET Data Providers, version 2.0 changes the story for data access. It includes a host of new features, some of which may cause you to rethink how data is accessed and manipulated in your applications.&lt;!--&lt;span class="a2"&gt;--&gt;&lt;br /&gt;&lt;br /&gt;In this article, I'll give you a brief rundown of what I see as the most significant new features in ADO.NET and how you might take advantage of them in your implementations.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span class="subhead1"&gt;Providing a wider view of data&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;Before delving into the specific features of ADO.NET v2.0, let me preface the discussion by noting that one of the overall design goals of this version was to allow a higher degree of interoperability between data accessed relationally, accessed as XML, and accessed as custom objects. Since these three make up the "ruling triumvirate" in representing data in an application, ADO.NET v2.0 was designed to make it easier for developers to use the appropriate model when desired within and across applications.&lt;br /&gt;&lt;br /&gt;For example, in applications built using a service-oriented architecture (SOA), persistent business data will often be manipulated relationally; data that represents the process and encapsulates business rules will be manipulated as objects; and message and lookup data that must be serialized for transport will be handled as XML. To present the new features, I've factored them into two broad buckets: the new features that provide this wider view of data and the features that enhance or extend the relational paradigm.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span class="subhead1"&gt;Widening the .NET&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;There are two primary new features you'll want to explore in the area of extending your ability to handle data. Let's take a look at each.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;&lt;span class="subhead2"&gt;&lt;i&gt;ObjectSpaces&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;This technology was previewed several years ago at PDC and will now be released in Whidbey. Simply put, &lt;i&gt;ObjectSpaces&lt;/i&gt; provides an object-relational mapping layer in the &lt;i&gt;System.Data.ObjectSpaces&lt;/i&gt; namespace, which instantiates and populates custom objects from a relational database. This works through XML metadata stored in a mappings file that is passed to the constructor of the &lt;i&gt;ObjectSpace&lt;/i&gt; class, which maps relational objects to .NET objects and relational types to .NET types.&lt;br /&gt;&lt;br /&gt;The programming model supports queries (&lt;i&gt;ObjectQuery&lt;/i&gt;) and maintains sets of objects in memory (&lt;i&gt;ObjectSet&lt;/i&gt;), access to streams of objects (&lt;i&gt;ObjectReader&lt;/i&gt;), and even lazy loading of objects to improve performance (&lt;i&gt;ObjectList&lt;/i&gt; and &lt;i&gt;ObjectHolder&lt;/i&gt;). &lt;b&gt;&lt;a name="Listing_A"&gt;&lt;/a&gt; &lt;span style="text-decoration: underline;"&gt;&lt;/span&gt;&lt;/b&gt;Following is an example of how the programming model looks:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre&gt;// Create the mappings&lt;/pre&gt;&lt;pre&gt;ObjectSpace oa = new ObjectSpace(&lt;i&gt;mappings-file&lt;/i&gt;, &lt;i&gt;connection&lt;/i&gt;);&lt;/pre&gt;&lt;pre&gt;// Query the data&lt;/pre&gt;&lt;pre&gt;ObjectQuery oq = new ObjectQuery(Product, "category='Equipment'");&lt;/pre&gt;&lt;pre&gt;ObjectReader or = oa.GetObjectReader(oq);&lt;/pre&gt;&lt;pre&gt;// Traverse the data&lt;/pre&gt;&lt;pre&gt;while (or.Read())&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre&gt;   Product p = (Product)or.Current;&lt;/pre&gt;&lt;pre&gt;   Console.WriteLine(p.Name);&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;span class="contentText"&gt;&lt;br /&gt;Although in the current release, &lt;i&gt;ObjectSpaces&lt;/i&gt; works only with SQL Server 2000 and SQL Server "Yukon" (the release of SQL Server more or less synchronized with the release of Whidbey), this technology will be extended to access other relational stores in the future. &lt;i&gt;ObjectSpaces&lt;/i&gt; is ideal when you want to represent your data using a domain model and encapsulate business logic as methods on your custom objects, since it will save you from writing the tiresome code needed to load from and persist your objects to a relational data store.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;&lt;span class="subhead2"&gt;SQLXML and &lt;i&gt;XmlAdapter&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;!-- missing include --&gt;Although the ADO.NET DataSet has always included the ability to load data as XML and serialize its contents as XML, the translation between the two ways of representing data always included some tension. For example, in order for the XML to load into a DataSet, its schema couldn't be overly complex, and it needed to map well into the relational DataTables of the DataSet.&lt;br /&gt;&lt;br /&gt;Although DataSet support of XML has been enhanced in version 2 to allow loading of XML with multiple in-line schemas, loading schemas with repeated element names in different namespaces, and loading/serializing directly from DataTable objects, the data must still be relational in nature to work with the DataSet. To overcome this, version 2 includes the &lt;i&gt;System.Xml.XmlAdapter&lt;/i&gt; class. This class is analogous to the &lt;i&gt;DataAdapter&lt;/i&gt; classes in that it is a liaison between a data source and a representation of the data, but is used to query and load XML from an XML View into an &lt;i&gt;XPathDocument&lt;/i&gt; object (called &lt;i&gt;XPathDocument2&lt;/i&gt; in the alpha; however, that will be renamed to &lt;i&gt;XPathDocument&lt;/i&gt; before release).&lt;br /&gt;&lt;br /&gt;XML Views allow relational tables (in SQL Server only) to be mapped to an XML schema via mappings files; they are the core component of the SQLXML 3.0 technology, once provided separately from the .NET Framework but now migrated into ADO.NET v2 (including the ability to bulk-load XML into SQL Server) in the &lt;i&gt;System.Data.SqlXml&lt;/i&gt; namespace. Using this approach, you can provide a set of XML Views for your SQL Server data, query the data with the &lt;i&gt;XQuery&lt;/i&gt; language using the new &lt;i&gt;XQueryProcessor&lt;/i&gt; class and the &lt;i&gt;Fill&lt;/i&gt; method of the &lt;i&gt;XmlAdapter&lt;/i&gt;, and manipulate the data using the &lt;i&gt;XPathDocument&lt;/i&gt;, &lt;i&gt;XPathEditor&lt;/i&gt;, &lt;i&gt;XPathNavigator&lt;/i&gt;, and &lt;i&gt;XPathChangeNavigator&lt;/i&gt; classes.&lt;br /&gt;&lt;br /&gt;The changes are written to SQL Server by calling the &lt;i&gt;Update&lt;/i&gt; method of the &lt;i&gt;XmlAdapter,&lt;/i&gt; which relies on the XML View to write the SQL statements to execute using a mappings file. The advantage of this approach is that you can treat your SQL Server data no differently than other XML data stores and can take advantage of the full fidelity of the XML when making changes. &lt;b&gt;&lt;a name="Listing_B"&gt;&lt;/a&gt; &lt;/b&gt;See a simple example of the programming model.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre&gt;// Set up the connection and query&lt;/pre&gt;&lt;pre&gt;SqlConnection con = new SqlConnection(&lt;i&gt;connection-string&lt;/i&gt;);&lt;/pre&gt;&lt;pre&gt;XQueryProcessor xq = new XQueryProcessor();&lt;/pre&gt;&lt;pre&gt;xq.XmlViewSchemaDictionary.Add("&lt;i&gt;name&lt;/i&gt;", new XmlTextReader("&lt;i&gt;mappings-file&lt;/i&gt;"));&lt;/pre&gt;&lt;pre&gt;xq.Compile(…);&lt;/pre&gt;&lt;pre&gt;// Set up the datasource&lt;/pre&gt;&lt;pre&gt;XmlDataSourceResolver xd = new XmlDataSourceResolver();&lt;/pre&gt;&lt;pre&gt;xd.Add("MyDB", con);&lt;/pre&gt;&lt;pre&gt;// Configure the XmlAdapter&lt;/pre&gt;&lt;pre&gt;XmlAdapter xa = new XmlAdapter(xd);&lt;/pre&gt;&lt;pre&gt;XPathDocument xp = new XPathDocument();&lt;/pre&gt;&lt;pre&gt;// Execute the query and populate the document&lt;/pre&gt;&lt;pre&gt;xa.Fill(xp, xq.XmlCommand);&lt;/pre&gt;&lt;pre&gt;// Navigate the document…&lt;/pre&gt;&lt;pre&gt;XPathNavigator xn = xp.CreateXPathNavigator();&lt;/pre&gt;&lt;pre&gt;// Or edit the document and change the data&lt;/pre&gt;&lt;pre&gt;XPathEditor xe = xp.CreateXPathEditor();&lt;/pre&gt;&lt;pre&gt;// Set the schema and update the database&lt;/pre&gt;&lt;pre&gt;MappingSchema ms = new MappingSchema("&lt;i&gt;mappings-file&lt;/i&gt;");&lt;/pre&gt;&lt;pre&gt;xa.Update(xp, ms);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;span class="contentText"&gt;Of course, XML Views simply provide the mapping of the data to and from SQL Server. If you're not using SQL Server, you can still take advantage of the substantial changes to &lt;i&gt;XPathDocument&lt;/i&gt; (that will supersede and make obsolete the &lt;i&gt;XmlDocument&lt;/i&gt; class) and its related classes to more easily query, navigate, and edit XML that you load from other sources.&lt;br /&gt;&lt;br /&gt;For example, you can use a new &lt;i&gt;XmlFactory&lt;/i&gt; class to create a related set of &lt;i&gt;XmlReader&lt;/i&gt;, &lt;i&gt;XmlWriter&lt;/i&gt;, and &lt;i&gt;XPathNavigator&lt;/i&gt; classes for an XML document. These classes now support the ability to read and write .NET types to and from XML documents. And, of course, performance has improved for reading and writing with &lt;i&gt;XmlTextReader&lt;/i&gt; and &lt;i&gt;XmlTextWriter,&lt;/i&gt; and when using XSLT.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="contentText"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;" class="subhead1"&gt;Extending the relational paradigm&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;The second broad set of changes relates to those made in ADO.NET v2.0 to enhance relational database access. I've organized these into changes that all developers can take advantage of, regardless of the underlying database you write to and regardless of those that will require SQL Server 2000 or the next version of SQL Server, Yukon.&lt;!--&lt;span class="a2"&gt;--&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Provider factory&lt;/span&gt;&lt;br /&gt;Although the design of .NET Data Providers is based on a common set of interfaces and base classes, in v1.0 or v1.1, Microsoft did not ship factory classes to help developers write polymorphic data access code. As a result, developers did so on their own.&lt;br /&gt;&lt;br /&gt;In version 2, ADO.NET includes factory classes inherited from &lt;i&gt;System.Data.Common.DbProviderFactory&lt;/i&gt; to create the standard connection, command, data reader, table, parameter, permissions, and data adapter classes; these help you write code that targets multiple databases. A factory is accessed using the &lt;i&gt;GetFactory&lt;/i&gt; method of the &lt;i&gt;DbProviderFactories&lt;/i&gt; class and can be configured in the application's configuration file using the &lt;i&gt;DbProviderConfigurationHandler&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Asynchronous data access&lt;/span&gt;&lt;br /&gt;Commands executed by ADO.NET in version 1.0 using the &lt;i&gt;ExecuteNonQuery&lt;/i&gt;, &lt;i&gt;ExecuteReader&lt;/i&gt;, and &lt;i&gt;ExecuteXmlReader&lt;/i&gt; methods of &lt;i&gt;SqlCommand&lt;/i&gt; were synchronous and would block the current thread until the results were returned by the server. In v2.0, each of these methods includes both &lt;i&gt;Begin&lt;/i&gt; and &lt;i&gt;End&lt;/i&gt; versions to support asynchronous execution from the client's perspective.&lt;br /&gt;&lt;br /&gt;This technique employs the familiar asynchronous programming model using the &lt;i&gt;AsyncCallback&lt;/i&gt; delegate in .NET, and so includes the &lt;i&gt;SqlAsyncResult&lt;/i&gt; class to implement the &lt;i&gt;IAsyncResult&lt;/i&gt; interface. While this feature works only for &lt;i&gt;SqlClient&lt;/i&gt; at the moment, look for it to perhaps be extended to other providers before the release. &lt;span style="font-weight: bold;"&gt;&lt;/span&gt;Following is an example of setting up an asynchronous command. (Note that the &lt;i&gt;SqlAsyncResult&lt;/i&gt; class is not included in the alpha at this time, so the code will not execute.)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre&gt;// Set up the connection and command&lt;/pre&gt;&lt;pre&gt;SqlConnection con = new SqlConnection(&lt;i&gt;connection-string&lt;/i&gt;);&lt;/pre&gt;&lt;pre&gt;SqlCommand cm = new SqlCommand(&lt;i&gt;SQL statement&lt;/i&gt;, con);&lt;/pre&gt;&lt;pre&gt;cm.Open();&lt;/pre&gt;&lt;pre&gt;cm.BeginExecuteNonQuery(new AsyncCallback(DoneExecuting), null);&lt;/pre&gt;&lt;pre&gt;// Thread is free, do other things&lt;/pre&gt;&lt;pre&gt;…&lt;/pre&gt;&lt;pre&gt;// Callback method&lt;/pre&gt;&lt;pre&gt;private void DoneExecuting(SqlAsyncResult ar)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre&gt;   int numRows = ar.EndExecuteNonQuery(ar);&lt;/pre&gt;&lt;pre&gt;   // print the number of rows affected&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;span class="contentText"&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Batch updates&lt;/span&gt;&lt;br /&gt;In version 1.0, a &lt;i&gt;DataAdapter&lt;/i&gt; always sent changes to rows one at a time to the server. In version 2.0, the &lt;i&gt;DataAdapter&lt;/i&gt; exposes an &lt;i&gt;UpdateBatchSize&lt;/i&gt; property that, if supported by the data provider, allows changed rows to be sent to the server in groups. This cuts down on the number of round-trips to the server and therefore increases performance.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Data paging&lt;/span&gt;&lt;br /&gt;In both SqlClient and OracleClient, the command object now exposes an &lt;i&gt;ExecutePageReader&lt;/i&gt; method that allows you to pass in the starting row and the number of rows to return from the server. This allows for more efficient data access by retrieving only the rows you need to display. However, this feature reads the rows currently in the table, so subsequent calls may contain rows from the previous page because of inserts, or from the latter pages because of deletes. It therefore works best with relatively static data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Binary DataSet remoting&lt;/span&gt;&lt;br /&gt;Version 2.0 now allows DataSets to be serialized using a binary format when employing .NET remoting. This both increases the performance of remoting data between .NET applications and reduces the number of bytes transferred.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;DataSet and DataReader transfer&lt;/span&gt;&lt;br /&gt;In version 1.1, you could only load a DataSet from a &lt;i&gt;DataAdapter&lt;/i&gt;. But in version 2.0, you can also load one directly using a &lt;i&gt;DataReader&lt;/i&gt; and the &lt;i&gt;Load&lt;/i&gt; method. Conversely, you can now generate a &lt;i&gt;DataTableReader&lt;/i&gt; (inherited from &lt;i&gt;DbDataReader&lt;/i&gt;) with the &lt;i&gt;GetDataReader&lt;/i&gt; method in order to traverse the contents of a DataSet. This feature makes it easy to load a DataSet and view its data.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span class="subhead1"&gt;Climbing Yukon&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;In this category are the new features of ADO.NET v2.0 that relate directly to the new release of the SQL Server code named Yukon, due out in the same time frame:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;MARS&lt;/span&gt;&lt;br /&gt;Multiple active result sets (MARS) allows you to work with more than one concurrent result set on a single connection to Yukon. This can be efficient if you need to open a &lt;i&gt;SqlDataReader&lt;/i&gt; and, during the traversal, execute a command against a particular row. MARS allows both commands to share the same &lt;i&gt;SqlConnection&lt;/i&gt; object so that a second connection to SQL Server is not required.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Change notification&lt;/span&gt;&lt;br /&gt;One of the most interesting new features of Yukon is its ability to support notifications. ADO.NET v2.0 includes programmatic support for this feature by including a &lt;i&gt;SqlNotificationRequest&lt;/i&gt; object that can be bound to a &lt;i&gt;SqlCommand&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;When data returned from the command changes in the database, a message is sent to the specified notification queue. ADO.NET code can then query the queue either by using an asynchronous query that blocks until a message is sent or by periodically checking the queue using new Transact-SQL syntax.&lt;br /&gt;&lt;br /&gt;To make this feature even easier to work with, a &lt;i&gt;SqlDependency&lt;/i&gt; class that sets up an asynchronous delegate is included. This will be called when the data changes, and it can be used like other dependencies in conjunction with the ASP.NET caching engine. &lt;b&gt;&lt;a name="Listing_D"&gt;&lt;/a&gt; &lt;a href="http://builder.com.com/5100-6386-5161213-2.html#Listing%20D" onclick="MM_openBrWindow('/5110-6386-5161219.html','','width=680,height=600,top=0,left=0,toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes')"&gt;&lt;/a&gt;&lt;/b&gt;An example of using a &lt;i&gt;SqlDependency&lt;/i&gt; object-&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre&gt;// Set up the connection and command&lt;/pre&gt;&lt;pre&gt;SqlConnection con = new SqlConnection(&lt;i&gt;connection-string&lt;/i&gt;);&lt;/pre&gt;&lt;pre&gt;SqlCommand cm = new SqlCommand(&lt;i&gt;SELECT statement&lt;/i&gt;, con);&lt;/pre&gt;&lt;pre&gt;SqlDependency dep = new SqlDependency(cm);&lt;/pre&gt;&lt;pre&gt;dep.OnChanged += new OnChangedEventHandler (HandleChange);&lt;/pre&gt;&lt;pre&gt;SqlDataReader dr = cm.ExecuteReader();&lt;/pre&gt;&lt;pre&gt;// Process the data&lt;/pre&gt;&lt;pre&gt;…&lt;/pre&gt;&lt;pre&gt;private void HandleChange (object sender, SqlNotificationEventArgs e)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre&gt;  // A change has been made to the data&lt;/pre&gt;&lt;pre&gt;  // Inspect the type of change using e.Type&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;span class="contentText"&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Yukon types&lt;/span&gt;&lt;br /&gt;ADO.NET v2.0 supports the full set of Yukon data types, including XML and User Defined Types (UDTs). This means that columns in Yukon defined as XML can be retrieved as &lt;i&gt;XmlReader&lt;/i&gt; objects, and that UDTs can be passed to stored procedures and returned from queries as standard .NET types. This allows your applications to work with data as fully formed objects while interacting with the database using the objects. This feature can be used profitably when writing managed code that runs in-process in SQL Server, allowing both the managed stored procedure and the client code to use the same .NET type.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Server-side cursors&lt;/span&gt;&lt;br /&gt;Because it often caused applications to perform poorly, ADO.NET v1.0 and v1.1 did away with the server-side cursors for ADO v2.x. ADO.NET v2.0 now reintroduces the concept in Yukon using the &lt;i&gt;ExecuteResultset&lt;/i&gt; and &lt;i&gt;ExecuteRow&lt;/i&gt; methods of the &lt;i&gt;SqlCommand&lt;/i&gt; object and the &lt;i&gt;SqlResultset&lt;/i&gt; class.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;SqlResultset&lt;/i&gt; class offers a fully scrollable and updateable cursor that can be useful for applications that need to traverse a large amount of data and update only a few rows. Although this feature can be used from client applications such as ASP.NET, it is mainly intended for use when writing managed code that runs in-process with Yukon in the form of stored procedures.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead2"&gt;Bulk copy&lt;/span&gt;&lt;br /&gt;Although not restricted to Yukon, ADO.NET v2.0 now allows programmatic access to the BCP or bulk copy API exposed by SQL Server. This is done using the &lt;i&gt;SqlBulkCopyOperation&lt;/i&gt; and &lt;i&gt;SqlBulkCopyColumnAssociator&lt;/i&gt; classes in the &lt;i&gt;System.Data.SqlClient&lt;/i&gt; namespace.&lt;br /&gt;&lt;span style="font-weight: bold;" class="subhead1"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-1639150649011135499?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/1639150649011135499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=1639150649011135499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1639150649011135499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1639150649011135499'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/07/application-development-whats-new-in.html' title='Application Development: What&apos;s new in ADO.NET version 2.0'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-8665973339243762647</id><published>2007-07-05T11:12:00.000+05:30</published><updated>2007-07-05T11:15:28.766+05:30</updated><title type='text'>What's New in ASP.NET 2.0?</title><content type='html'>&lt;p&gt;ASP.NET is a programming framework built on the common language runtime that can be used on a server to build powerful Web applications. The first version of ASP.NET offered several important advantages over previous Web development models. ASP.NET 2.0 improves upon that foundation by adding support for several new and exciting features in the areas of developer productivity, administration and management, extensibility, and performance: &lt;/p&gt;  &lt;h3&gt;Developer Productivity&lt;/h3&gt; ASP.NET 2.0 encapsulates common Web tasks into application services and controls that can be easily reused across web sites. With these basic building blocks, many scenarios can now be implemented with far less custom code than was required in previous versions. With ASP.NET 2.0 it is possible to significantly reduce the amount of code and concepts necessary to build common scenarios on the web. &lt;ul&gt;&lt;li&gt;&lt;b&gt;New Server Controls.&lt;/b&gt; ASP.NET 2.0 introduces many new server controls that enable powerful declarative support for data access, login security, wizard navigation, menus, treeviews, portals, and more. Many of these controls take advantage of core application services in ASP.NET for scenarios like data access, membership and roles, and personalization. Some of the new families of controls in ASP.NET 2.0 are described below.&lt;br /&gt;&lt;br /&gt;   &lt;ul&gt;&lt;li&gt;&lt;b&gt;Data Controls.&lt;/b&gt; Data access in ASP.NET 2.0 can be accomplished completely declaratively (no code) using the new data-bound and data source controls. There are new data source controls to represent different data backends such as SQL database, business objects, and XML, and there are new data-bound controls for rendering common UI for data, such as gridview, detailsview, and formview..&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;b&gt;Navigation Controls.&lt;/b&gt; The navigation controls provide common UI for navigating between pages in your site, such as treeview, menu, and sitemappath. These controls use the site navigation service in ASP.NET 2.0 to retrieve the custom structure you have defined for your site.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;b&gt;Login Controls.&lt;/b&gt; The new login controls provide the building blocks to add authentication and authorization-based UI to your site, such as login forms, create user forms, password retrieval, and custom UI for logged in users or roles. These controls use the built-in membership and role services in ASP.NET 2.0 to interact with the user and role information defined for your site.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;b&gt;Web Part Controls.&lt;/b&gt; Web parts are an exciting new family of controls that enable you to add rich, personalized content and layout to your site, as well as the ability to edit that content and layout directly from your application pages. These controls rely on the personalization services in ASP.NET 2.0 to provide a unique experience for each user in your application.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;/ul&gt;   &lt;/li&gt;&lt;li&gt;&lt;b&gt;Master Pages.&lt;/b&gt; This feature provides the ability to define common structure and interface elements for your site, such as a page header, footer, or navigation bar, in a common location called a "master page", to be shared by many pages in your site. In one simple place you can control the look, feel, and much of functionality for an entire Web site. This improves the maintainability of your site and avoids unnecessary duplication of code for shared site structure or behavior.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;b&gt;Themes and Skins.&lt;/b&gt; The themes and skins features in ASP.NET 2.0 allow for easy customization of your site's look-and-feel. You can define style information in a common location called a "theme", and apply that style information globally to pages or controls in your site. Like Master Pages, this improves the maintainability of your site and avoid unnecessary duplication of code for shared styles.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;b&gt;Personalization.&lt;/b&gt; Using the new personalization services in ASP.NET 2.0 you can easily create customized experiences within Web applications. The Profile object enables developers to easily build strongly-typed, sticky data stores for user accounts and build highly customized, relationship based experiences. At the same time, a developer can leverage Web Parts and the personalization service to enable Web site visitors to completely control the layout and behavior of the site, with the knowledge that the site is completely customized for them. Personalizaton scenarios are now easier to build than ever before and require significantly less code and effort to implement.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;li&gt;&lt;b&gt;Localization.&lt;/b&gt; Enabling globalization and localization in Web sites today is difficult, requiring large amounts of custom code and resources. ASP.NET 2.0 and Visual Studio 2005 provide tools and infrastructure to easily build Localizable sites including the ability to auto-detect incoming locale's and display the appropriate locale based UI. Visual Studio 2005 includes built-in tools to dynamically generate resource files and localization references. Together, building localized applications becomes a simple and integrated part of the development experience.&lt;br /&gt;&lt;br /&gt;    &lt;/li&gt;&lt;/ul&gt;  &lt;h3&gt;Administration and Management&lt;/h3&gt; ASP.NET 2.0 is designed with administration and manageability in mind. We recognize that while simplifying the development experience is important, deployment and maintenance in a production environment is also a key component of an application's lifetime. ASP.NET 2.0 introduces several new features that further enhance the deployment, management, and operations of ASP.NET servers. &lt;ul&gt;&lt;li&gt;&lt;b&gt;Configuration API.&lt;/b&gt; ASP.NET 2.0 contains new configuration management APIs, enabling users to programmatically build programs or scripts that create, read, and update Web.config and machine.config configuration files.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;ASP.NET MMC Admin Tool.&lt;/b&gt; ASP.NET 2.0 provides a new comprehensive admin tool that plugs into the existing IIS Administration MMC, enabling an administrator to graphically read or change common settings within our XML configuration files.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Pre-compilation Tool.&lt;/b&gt; ASP.NET 2.0 delivers a new application deployment utility that enables both developers and administrators to precompile a dynamic ASP.NET application prior to deployment. This precompilation automatically identifies any compilation issues anywhere within the site, as well as enables ASP.NET applications to be deployed without any source being stored on the server (one can optionally remove the content of .aspx files as part of the compile phase), further protecting your intellectual property.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Health Monitoring and Tracing.&lt;/b&gt; ASP.NET 2.0 also provides new health-monitoring support to enable administrators to be automatically notified when an application on a server starts to experience problems. New tracing features will enable administrators to capture run-time and request data from a production server to better diagnose issues. ASP.NET 2.0 is delivering features that will enable developers and administrators to simplify the day-to-day management and maintenance of their Web applications. &lt;/li&gt;&lt;/ul&gt;   &lt;h3&gt;Flexible Extensibility&lt;/h3&gt; ASP.NET 2.0 is a well-factored and open system, where any component can be easily replaced with a custom implementation. Whether it is server controls, page handlers, compilation, or core application services, you'll find that all are easily customizable and replaceable to tailor to your needs. Developers can plug in custom code anywhere in the page lifecycle to further customize ASP.NET 2.0 to their needs. &lt;ul&gt;&lt;li&gt;&lt;b&gt;Provider-driven Application Services.&lt;/b&gt; ASP.NET 2.0 now includes built-in support for membership (user name/password credential storage) and role management services out of the box. The new personalization service enables quick storage/retrieval of user settings and preferences, facilitating rich customization with minimal code. The new site navigation system enables developers to quickly build link structures consistently across a site. As all of these services are provider-driven, they can be easily swapped out and replaced with your own custom implementation. With this extensibility option, you have complete control over the data store and schema that drives these rich application services.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Server Control Extensibility.&lt;/b&gt; ASP.NET 2.0 includes improved support for control extensibility, such as more base classes that encapsulate common behaviors, improved designer support, more APIs for interacting with client-side script, metadata-driven support for new features like themes and accessibility verification, better state management, and more.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Data Source Controls.&lt;/b&gt; Data access in ASP.NET 2.0 is now performed declaratively using data source controls on a page. In this model, support for new data backend storage providers can be easily added by implementing custom data source controls. Additionally, the SqlDataSource control that ships in the box has built-in support for any ADO.NET managed provider that implements the new provider factory model in ADO.NET.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Compilation Build Providers.&lt;/b&gt; Dynamic compilation in ASP.NET 2.0 is now handled by extensible compilation build providers, which associate a particular file extension with a handler that knows how to compile that extension dynamically at runtime. For example, .resx files can be dynamically compiled to resources, .wsdl files to web service proxies, and .xsd files to typed DataSet objects. In addition to the built-in support, it is easy to add support for additional extensions by implementing a custom build provider and registering it in Web.config.&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Expression Builders.&lt;/b&gt; ASP.NET 2.0 introduces a declarative new syntax for referencing code to substitute values into the page, called Expression Builders. ASP.NET 2.0 includes expression builders for referencing string resources for localization, connection strings, application settings, and profile values. You can also write your own expression builders to create your own custom syntax to substitute values in a page rendering. &lt;/li&gt;&lt;/ul&gt;   &lt;h3&gt;Performance and Scalability&lt;/h3&gt; ASP.NET is built to perform, using a compiled execution model for handling page requests and running on the world's fastest web server, Internet Information Services. ASP.NET 2.0 also introduces key performance benefits over previous versions. &lt;ul&gt;&lt;li&gt;&lt;b&gt;64-Bit Support.&lt;/b&gt; ASP.NET 2.0 is now 64-bit enabled, meaning it can take advantage of the full memory address space of new 64-bit processors and servers. Developers can simply copy existing 32-bit ASP.NET applications onto a 64-bit ASP.NET 2.0 server and have them automatically be JIT compiled and executed as native 64-bit applications (no source code changes or manual re-compile are required).&lt;br /&gt;&lt;br /&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Caching Improvements.&lt;/b&gt; ASP.NET 2.0 also now includes automatic database server cache invalidation. This powerful and easy-to-use feature allows developers to aggressively output cache database-driven page and partial page content within a site and have ASP.NET automatically invalidate these cache entries and refresh the content whenever the back-end database changes. Developers can now safely cache time-critical content for long periods without worrying about serving visitors stale data.&lt;/li&gt;&lt;/ul&gt;  The remainder of the QuickStart presents practical examples of these and other features in ASP.NET.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: georgia;font-size:100%;" &gt;&lt;div&gt; &lt;h3&gt;Events and Life Cycle of a Page (ASP.Net 1.x VS ASP.Net 2.0):&lt;/h3&gt;&lt;/div&gt; &lt;div&gt;In the ASP.NET runtime the life cycle of a page is marked by a series of events. In ASP.NET 1.x, based on user interaction a page request is sent to the Web server. The event that is initiated by the page request is &lt;b&gt;Init&lt;/b&gt;. After the Init event, &lt;b&gt;Load&lt;/b&gt; event is raised. Following the Load event, &lt;b&gt;PreRender&lt;/b&gt; event is raised. Finally, the &lt;b&gt;Unload&lt;/b&gt; event is raised and an output page is returned to the client.  &lt;p&gt;ASP.NET 2.0 adds a few new events to allow you to follow the request processing more closely and precisely.&lt;br /&gt;These new events are discussed in the following table.&lt;/p&gt; &lt;p&gt; &lt;b&gt;New Events in ASP.NET 2.0:&lt;/b&gt;&lt;/p&gt;  &lt;table style="border-collapse: collapse;" bordercolordark="#808080" bordercolorlight="#ffffff" bgcolor="#c0c0c0" border="1" bordercolor="#808080" width="100%"&gt; &lt;tbody&gt; &lt;tr bgcolor="#808080"&gt; &lt;th&gt; &lt;p align="left"&gt;Events&lt;/p&gt;&lt;/th&gt; &lt;th&gt; &lt;p align="left"&gt;Description&lt;/p&gt;&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt; &lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;PreInit&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top"&gt; &lt;p&gt;This occurs before the page begins initialization. This is the first event in the life of an ASP.NET 2.0 page.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt; &lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;InitComplete&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top"&gt; &lt;p&gt;This occurs when the page initialization is completed.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt; &lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;PreLoad&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top"&gt; &lt;p&gt;This occurs immediately after initialization and before the page begins loading the state information.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt; &lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;LoadComplete&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top"&gt; &lt;p&gt;This occurs at the end of the load stage of the page's life cycle.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top"&gt; &lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;b&gt;PreRenderComplete&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top"&gt; &lt;p&gt;This occurs when the pre-rendering phase is complete and all child controls have been created. After this event, the personalization data and the view state are saved and the page renders to HTML.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;This new features enable developer to dynamically modify the page output and the state of constituent controls by handling these events.&lt;/p&gt;&lt;/div&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-8665973339243762647?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/8665973339243762647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=8665973339243762647' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/8665973339243762647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/8665973339243762647'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/07/whats-new-in-aspnet-20.html' title='What&apos;s New in ASP.NET 2.0?'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-5700220638297955917</id><published>2007-07-05T11:06:00.000+05:30</published><updated>2007-07-05T11:07:29.809+05:30</updated><title type='text'>What's New in the .NET Framework 2.0</title><content type='html'>&lt;div class="text"&gt;   &lt;p&gt;The first version of the .NET Framework (1.0) was released in 2002 to much enthusiasm. The latest version, the .NET Framework 2.0, was introduced in 2005 and is considered a major release of the framework.&lt;/p&gt; &lt;p&gt;With each release of the framework, Microsoft has always tried to ensure that there were minimal breaking changes to code developed. Thus far, they have been very successful at this goal.&lt;/p&gt; &lt;blockquote&gt;Make sure that you create a staging server to completely test the upgrade of your applications to the .NET Framework 2.0 as opposed to just upgrading a live application.&lt;/blockquote&gt; &lt;p&gt;The following details some of the changes that are new to the .NET Framework 2.0 as well as new additions to Visual Studio 2005 — the development environment for the .NET Framework 2.0.&lt;/p&gt;  &lt;h4&gt;SQL Server integration&lt;/h4&gt; &lt;p&gt;After a long wait, the latest version of SQL Server has finally been released. This version, SQL Server 2005, is quite special in so many ways. Most importantly for the .NET developer is that SQL Server 2005 is now hosting the CLR. Microsoft has developed their .NET offering for developers so that the .NET Framework 2.0, Visual Studio 2005 and SQL Server 2005 are all now tied together — meaning that these three products are now released in unison. This is quite important as it is rather well known that most applications built use all three of these pieces and that they all need to be upgraded together in such a way that they work with each other in a seamless manner.&lt;/p&gt; &lt;p&gt;Due to the fact that SQL Server 2005 now hosts the CLR, this means that you can now avoid building database aspects of your application using the T-SQL programming language. Instead, you can now build items such as your stored procedures, triggers and even data types in any of the .NET-compliant languages, such as C#.&lt;/p&gt; &lt;p&gt;SQL Server Express is the 2005 version of SQL Server that replaces MSDE. This version doesn't have the strict limitations MSDE had.&lt;/p&gt;  &lt;h4&gt;64-Bit support&lt;/h4&gt; &lt;p&gt;Most programming today is done on 32-bit machines. It was a monumental leap forward in application development when computers went from 16-bit to 32-bit. More and more enterprises are moving to the latest and greatest 64-bit servers from companies such as Intel (Itanium chips) and AMD (x64 chips) and the .NET Framework 2.0 has now been 64-bit enabled for this great migration.&lt;/p&gt; &lt;p&gt;Microsoft has been working hard to make sure that everything you build in the 32-bit world of .NET will run in the 64-bit world. This means that everything you do with SQL Server 2005 or ASP.NET will not be affected by moving to 64-bit. Microsoft themselves made a lot of changes to the CLR in order to get a 64-bit version of .NET to work. Changes where made to things such as garbage collection (to handle larger amounts of data), the JIT compilation process, exception handling, and more.&lt;/p&gt; &lt;p&gt;Moving to 64-bit gives you some powerful additions. The most important (and most obvious reason) is that 64-bit servers give you a larger address space. Going to 64-bit also allows for things like larger primitive types. For instance, an integer value of 2^32 will give you 4,294,967,296 — while an integer value of 2^64 will give you 18,446,744,073,709,551,616. This comes in quite handy for those applications that need to calculate things such as the U.S. debt or other high numbers.&lt;/p&gt; &lt;p&gt;Companies such as Microsoft and IBM are pushing their customers to take a look at 64-bit. One of the main areas of focus are on database and virtual storage capabilities as this is seen as an area in which it makes a lot of sense to move to 64-bit for.&lt;/p&gt; &lt;p&gt;Visual Studio 2005 can install and run on a 64-bit computer. This IDE has both 32-bit and 64-bit compilers on it. One final caveat is that the 64-bit .NET Framework is meant only for Windows Server 2003 SP1 or better as well as other 64-bit Microsoft operating systems that might come our way.&lt;/p&gt; &lt;p&gt;When you build your applications in Visual Studio 2005, you can change the build properties of your application so that it compiles specifically for 64-bit computers. To find this setting, you will need to pull up your application's properties and click on the Build tab from within the Properties page. On the Build page, click on the Advanced button and this will pull up the Advanced Compiler Setting dialog. From this dialog, you can change the target CPU from the bottom of the dialog. From here, you can establish your application to be built for either an Intel 64-bit computer or an AMD 64-bit computer. This is shown here in Figure 1.&lt;/p&gt;  &lt;img src="http://media.wiley.com/assets/986/97/575341-fgfm01.jpg" alt="Figure 1" border="0" height="357" width="500" /&gt;&lt;br /&gt;&lt;span class="text"&gt;&lt;i&gt;Figure 1: Building your application for 64-bit&lt;/i&gt;&lt;/span&gt;  &lt;h4&gt;Generics&lt;/h4&gt; &lt;p&gt;In order to make collections a more powerful feature and also increase their efficiency and usability, generics were introduced to the .NET Framework 2.0. This introduction to the underlying framework means that languages such as C# and Visual Basic 2005 can now build applications that use generic types. The idea of generics is nothing new. They look similar to C++ templates but are a bit different. You can also find generics in other languages, such as Java. Their introduction into the .NET Framework 2.0 languages is a huge benefit for the user.&lt;/p&gt; &lt;p&gt;Generics enable you to make a generic collection that is still strongly typed — providing fewer chances for errors (because they occur at runtime), increasing performance, and giving you Intellisense features when you are working with the collections.&lt;/p&gt; &lt;p&gt;To utilize generics in your code, you will need to make reference to the &lt;code&gt;System.Collections.Generic&lt;/code&gt; namespace. This will give you access to generic versions of the &lt;code&gt;Stack&lt;/code&gt;, &lt;code&gt;Dictionary&lt;/code&gt;, &lt;code&gt;SortedDictionary&lt;/code&gt;, &lt;code&gt;List&lt;/code&gt; and &lt;code&gt;Queue&lt;/code&gt; classes. The following demonstrates the use of a generic version of the &lt;code&gt;Stack&lt;/code&gt; class:&lt;/p&gt;   &lt;blockquote&gt;&lt;pre&gt;void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;  System.Collections.Generic.Stack&lt;string&gt; myStack =&lt;br /&gt;     New System.Collections.Generic.Stack&lt;string&gt;();&lt;br /&gt;  myStack.Push("St. Louis Rams");&lt;br /&gt;  myStack.Push("Indianapolis Colts");&lt;br /&gt;  myStack.Push("Minnesota Vikings");&lt;br /&gt;&lt;br /&gt;  Array myArray;&lt;br /&gt;  myArray = myStack.ToArray();&lt;br /&gt;&lt;br /&gt;  foreach(string item in myArray)&lt;br /&gt;  {&lt;br /&gt;     Label1.Text += item + "&lt;br /&gt;";&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;In the above example, the &lt;code&gt;Stack&lt;/code&gt; class is explicitly cast to be of type &lt;code&gt;string&lt;/code&gt;. Here, you specify the collection type with the use of brackets. This example, casts the &lt;code&gt;Stack&lt;/code&gt; class to type &lt;code&gt;string&lt;/code&gt; using &lt;code&gt;Stack&lt;string&gt;&lt;/code&gt;. If you wanted to cast it to something other than a &lt;code&gt;Stack&lt;/code&gt; class of type &lt;code&gt;string&lt;/code&gt; (for instance, &lt;code&gt;int&lt;/code&gt;), then you would specify &lt;code&gt;Stack&lt;int&gt;&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;Because the collection of items in the &lt;code&gt;Stack&lt;/code&gt; class is cast to a specific type immediately as the &lt;code&gt;Stack&lt;/code&gt; class is created, the &lt;code&gt;Stack&lt;/code&gt; class no longer casts everything to type &lt;code&gt;object&lt;/code&gt; and then later (in the &lt;code&gt;foreach&lt;/code&gt; loop) to type &lt;code&gt;string&lt;/code&gt;. This process is called boxing, and it is expensive. Because this code is specifying the types up front, the performance is increased for working with the collection.&lt;/p&gt; In addition to just working with various collection types, you can also use generics with classes, delegates, methods and more.  &lt;h4&gt;Anonymous methods&lt;/h4&gt; &lt;p&gt;Anonymous methods enable you to put programming steps within a delegate that you can then later execute instead of creating an entirely new method. For instance, if you were not using anonymous methods, you would use delegates in a manner similar to the following:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;public partial class Default_aspx&lt;br /&gt;{&lt;br /&gt;  void Page_Load(object sender, EventArgs e)&lt;br /&gt;  {&lt;br /&gt;     this.Button1.Click += ButtonWork;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  void ButtonWork(object sender, EventArgs e)&lt;br /&gt;  {&lt;br /&gt;     Label1.Text = "You clicked the button!";&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;But using anonymous methods, you can now put these actions directly in the delegate as shown here in the following example:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;public partial class Default_aspx&lt;br /&gt;{&lt;br /&gt;  void Page_Load(object sender, EventArgs e)&lt;br /&gt;  {&lt;br /&gt;     this.Button1.Click += delegate(object&lt;br /&gt;   myDelSender, EventArgs myDelEventArgs)&lt;br /&gt;     {&lt;br /&gt;        Label1.Text = "You clicked the button!";&lt;br /&gt;     };&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;When using anonymous methods, there is no need to create a separate method. Instead you place the necessary code directly after the delegate declaration. The statements and steps to be executed by the delegate are placed between curly braces and closed with a semicolon.&lt;/p&gt;  &lt;h4&gt;Nullable types&lt;/h4&gt; &lt;p&gt;Due to the fact that generics has been introduced into the underlying .NET Framework 2.0, it is now possible to create nullable value types — using &lt;code&gt;System.Nullable&lt;t&gt;&lt;/code&gt;. This is ideal for situations such as creating sets of nullable items of type &lt;code&gt;int&lt;/code&gt;. Before this, it was always difficult to create an &lt;code&gt;int&lt;/code&gt; with a null value from the get-go or to later assign null values to an &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;To create a nullable type of type &lt;code&gt;int&lt;/code&gt;, you would use the following syntax:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;System.Nullable&lt;int&gt; x = new System.Nullable&lt;int&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;There is a new type modifier that you can also use to create a type as nullable. This is shown in the following example:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;int? salary = 800000&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;This ability to create nullable types is not a C#-only item as this ability was built into .NET Framework itself and, as stated, is there due to the existence of the new generics feature in .NET. For this reason, you will also find nullable types in Visual Basic 2005 as well.&lt;/p&gt;  &lt;h4&gt;Iterators&lt;/h4&gt; &lt;p&gt;Iterators enable you to use &lt;code&gt;foreach&lt;/code&gt; loops on your own custom types. To accomplish this, you need to have your class implement the &lt;code&gt;IEnumerable&lt;/code&gt; interface as shown here:&lt;/p&gt;   &lt;blockquote&gt;&lt;pre&gt;using System;&lt;br /&gt;using Systm.Collections;&lt;br /&gt;&lt;br /&gt;public class myList&lt;br /&gt;{&lt;br /&gt;  internal object[] elements;&lt;br /&gt;  internal int count;&lt;br /&gt;&lt;br /&gt;  public IEnumerator GetEnumerator()&lt;br /&gt;  {&lt;br /&gt;     yield return "St. Louis Rams";&lt;br /&gt;     yield return "Indianapolis Colts";&lt;br /&gt;     yield return "Minnesota Vikiings";&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;In order to use the &lt;code&gt;IEnumerator&lt;/code&gt; interface, you will need to make a reference to the &lt;code&gt;System.Collections&lt;/code&gt; namespace. With this all in place, you can then iterate through the custom class as shown here:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;  myList IteratorList = new myList();&lt;br /&gt;&lt;br /&gt;  foreach(string item in IteratorList)&lt;br /&gt;  {&lt;br /&gt;     Response.Write(item.ToString() + "&lt;br /&gt;");&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;h4&gt;Partial Classes&lt;/h4&gt; &lt;p&gt;Partial classes are a new feature to the .NET Framework 2.0 and again C# takes advantage of this addition. Partial classes allow you to divide up a single class into multiple class files, which are later combined into a single class when compiled.&lt;/p&gt; &lt;p&gt;To create a partial class, you simply need to use the &lt;code&gt;partial&lt;/code&gt; keyword for any classes that are to be joined together with a different class. The &lt;code&gt;partial&lt;/code&gt; keyword precedes the &lt;code&gt;class&lt;/code&gt; keyword for the classes that are to be combined with the original class. For instance, you might have a simple class called &lt;code&gt;Calculator&lt;/code&gt; as shown here:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;public class Calculator&lt;br /&gt;{&lt;br /&gt;  public int Add(int a, int b)&lt;br /&gt;  {&lt;br /&gt;     return a + b;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;From here, you can create a second class that attaches itself to this first class as shown here in the following example:&lt;/p&gt;  &lt;blockquote&gt;&lt;pre&gt;public partial class Calculator&lt;br /&gt;{&lt;br /&gt;  public int Subtract(int a, int b)&lt;br /&gt;  {&lt;br /&gt;     return a - b;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/blockquote&gt;  &lt;p&gt;When compiled, these classes will be brought together into a single Calculator class instance as if they were built together to begin with.&lt;/p&gt;  &lt;h3&gt;Where C# Fits In&lt;/h3&gt; &lt;p&gt;In one sense, C# can be seen as being the same thing to programming languages as .NET is to the Windows environment. Just as Microsoft has been adding more and more features to Windows and the Windows API over the past decade, Visual Basic 2005 and C++ have undergone expansion. Although Visual Basic and C++ have ended up as hugely powerful languages as a result of this, both languages also suffer from problems due to the legacies of how they have evolved.&lt;/p&gt; &lt;p&gt;In the case of Visual Basic 6 and earlier versions, the main strength of the language was the fact that it was simple to understand and didn't make many programming tasks easy, largely hiding the details of the Windows API and the COM component infrastructure from the developer. The downside to this was that Visual Basic was never truly object-oriented, so that large applications quickly became disorganized and hard to maintain. As well, because Visual Basic's syntax was inherited from early versions of BASIC (which, in turn, was designed to be intuitively simple for beginning programmers to understand, rather than to write large commercial applications), it didn't really lend itself to well-structured or object-oriented programs.&lt;/p&gt; &lt;p&gt;C++, on the other hand, has its roots in the ANSI C++ language definition. It isn't completely ANSI-compliant for the simple reason that Microsoft first wrote its C++ compiler before the ANSI definition had become official, but it comes close. Unfortunately, this has led to two problems. First, ANSI C++ has its roots in a decade-old state of technology, and this shows up in a lack of support for modern concepts (such as Unicode strings and generating XML documentation), and for some archaic syntax structures designed for the compilers of yesteryear (such as the separation of declaration from definition of member functions). Second, Microsoft has been simultaneously trying to evolve C++ into a language that is designed for high-performance tasks on Windows, and in order to achieve that they've been forced to add a huge number of Microsoft-specific keywords as well as various libraries to the language. The result is that on Windows, the language has become a complete mess. Just ask C++ developers how many definitions for a string they can think of: &lt;code&gt;char*&lt;/code&gt;, &lt;code&gt;LPTSTR&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;CString&lt;/code&gt; (MFC version), &lt;code&gt;CString&lt;/code&gt; (WTL version), &lt;code&gt;wchar_t*&lt;/code&gt;, &lt;code&gt;OLECHAR*&lt;/code&gt;, and so on.&lt;/p&gt; &lt;p&gt;Now enter .NET —a completely new environment that is going to involve new extensions to both languages. Microsoft has gotten around this by adding yet more Microsoft-specific keywords to C++, and by completely revamping Visual Basic into Visual Basic .NET into Visual Basic 2005, a language that retains some of the basic VB syntax but that is so different in design that we can consider it to be, for all practical purposes, a new language.&lt;/p&gt; &lt;p&gt;It's in this context that Microsoft has decided to give developers an alternative — a language designed specifically for .NET, and designed with a clean slate. Visual C# 2005 is the result. Officially, Microsoft describes C# as a "simple, modern, object-oriented, and type-safe programming language derived from C and C++." Most independent observers would probably change that to "derived from C, C++, and Java." Such descriptions are technically accurate but do little to convey the beauty or elegance of the language. Syntactically, C# is very similar to both C++ and Java, to such an extent that many keywords are the same, and C# also shares the same block structure with braces ({}) to mark blocks of code, and semicolons to separate statements. The first impression of a piece of C# code is that it looks quite like C++ or Java code. Beyond that initial similarity, however, C# is a lot easier to learn than C++, and of comparable difficulty to Java. Its design is more in tune with modern developer tools than both of those other languages, and it has been designed to give us, simultaneously, the ease of use of Visual Basic, and the high-performance, low-level memory access of C++ if required. Some of the features of C# are:&lt;/p&gt;  &lt;ul&gt;&lt;li&gt;Full support for classes and object-oriented programming, including both interface and implementation inheritance, virtual functions, and operator overloading.&lt;/li&gt;&lt;li&gt;A consistent and well-defined set of basic types.&lt;/li&gt;&lt;li&gt;Built-in support for automatic generation of XML documentation.&lt;/li&gt;&lt;li&gt;Automatic cleanup of dynamically allocated memory.&lt;/li&gt;&lt;li&gt;The facility to mark classes or methods with user-defined attributes. This can be useful for documentation and can have some effects on compilation (for example, marking methods to be compiled only in debug builds).&lt;/li&gt;&lt;li&gt;Full access to the .NET base class library, as well as easy access to the Windows API (if you really need it, which won't be all that often).&lt;/li&gt;&lt;li&gt;Pointers and direct memory access are available if required, but the language has been designed in such a way that you can work without them in almost all cases.&lt;/li&gt;&lt;li&gt;Support for properties and events in the style of Visual Basic.&lt;/li&gt;&lt;li&gt;Just by changing the compiler options, you can compile either to an executable or to a library of .NET components that can be called up by other code in the same way as ActiveX controls (COM components).&lt;/li&gt;&lt;li&gt;C# can be used to write ASP.NET dynamic Web pages and XML Web services.&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;Most of the above statements, it should be pointed out, do also apply to Visual Basic 2005 and Managed C++. The fact that C# is designed from the start to work with .NET, however, means that its support for the features of .NET is both more complete, and offered within the context of a more suitable syntax than for those other languages. While the C# language itself is very similar to Java, there are some improvements, in particular, Java is not designed to work with the .NET environment.&lt;/p&gt; &lt;p&gt;Before we leave the subject, we should point out a couple of limitations of C#. The one area the language is not designed for is time-critical or extremely high performance code — the kind where you really are worried about whether a loop takes 1,000 or 1,050 machine cycles to run through, and you need to clean up your resources the millisecond they are no longer needed. C++ is likely to continue to reign supreme among low-level languages in this area. C# lacks certain key facilities needed for extremely high performance apps, including the ability to specify inline functions and destructors that are guaranteed to run at particular points in the code. However, the proportions of applications that fall into this category are very low.&lt;/p&gt;  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-5700220638297955917?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/5700220638297955917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=5700220638297955917' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/5700220638297955917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/5700220638297955917'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/07/whats-new-in-net-framework-20.html' title='What&apos;s New in the .NET Framework 2.0'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-5129567862865339752</id><published>2007-07-04T14:35:00.000+05:30</published><updated>2007-07-04T14:44:19.775+05:30</updated><title type='text'>Introduction to .NET 3.0 for Architects</title><content type='html'>&lt;span style="font-size:78%;"&gt;    Posted by    &lt;strong&gt;Mohammad Akif&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;The latest version of Microsoft's .NET, .NET Framework 3.0, opens up new possibilities for developing the next generation of business solution software. It is designed to enhance productivity, reduce infrastructure plumbing, provide an identity meta-system, and facilitate development of enterprise-class services, work flow solutions and immersive user experiences.&lt;br /&gt;&lt;p&gt;During my discussions with a wide variety of architects I have learned that Solution Architects care very much about security, open standards, interoperability, services oriented architecture, relationship between key technologies (for example Workflow Foundation and Biztalk) and productivity. In this article, I have attempted to provide a description of .NET 3.0 in terms of areas that are of significant interest for the architect community.&lt;/p&gt;&lt;h2&gt;.NET versions &lt;/h2&gt; &lt;p&gt;It has been almost six years since Microsoft released the first version of the .NET Framework. The 3.0 incarnation is the first framework being distributed with the operating system, i.e. with every Windows Vista installation and is also supported on Windows XP SP2 and Windows Server 2003. Until .NET 3.0, each version of the .NET framework was also accompanied by a new Common Language Runtime, hereafter referred to as the CLR. Microsoft has not modified the CLR for the 3. 0 version of the .NET framework and this is an important point to understand.&lt;/p&gt; &lt;img style="width: 570px; height: 404px;" alt="" _href="img://image1.jpg" src="http://www.infoq.com/resource/articles/akif-dotnet-architect/en/resources/image1.jpg" /&gt; &lt;p&gt;As .NET 2.0 and 3.0 share the same CLR, everything written in .NET 2.0 works in .NET 3.0 which is an important and significant departure from previous versions. In terms of change, for those who love algebra equations the relationship can be summed anecdotally as:&lt;/p&gt; &lt;p&gt;&lt;em&gt;.NET 3.0 = .NET 2.0 + WCF + WPF + WCS + WF&lt;/em&gt;&lt;/p&gt; &lt;p&gt;I will provide a definition of each of the acronyms, but anytime you get confused about the relationship between .NET 2.0 and 3.0, keep the above equation foremost in mind. One of the key philosophies behind .NET 3.0 is to provide functionality that can be considered ‘infrastructure plumbing' as part of the framework. This allows you to focus on your key business problem.&lt;/p&gt; &lt;p&gt;The .NET Framework 3.0 achieves this objective through four key standards-based pillars corresponding to areas identified and requested by our customers. It also introduced a key new language called XAML. XAML is a declarative XML-based language that defines objects and their properties in XML allowing customers to develop workflows (WF) and immersive user experiences (WPF) declaratively. Let us explore the key pillars of the .NET 3.0 framework in greater detail.&lt;/p&gt; &lt;h2&gt;Windows Communication Foundation (WCF)&lt;/h2&gt; &lt;p&gt;WCF allows you to architect services by offering a standards- based framework and a composable architecture. The three key design philosophies for WCF are interoperability, productivity and service-oriented development.&lt;/p&gt; &lt;img style="width: 551px; height: 389px;" alt="" _href="img://image2.jpg" src="http://www.infoq.com/resource/articles/akif-dotnet-architect/en/resources/image2.jpg" /&gt; &lt;p&gt;Microsoft provides a number of messaging layer channels and service model layer behaviors that can be added and removed easily. It also allows you to define your own custom instances, for example you can write or buy a custom encoder for ASCII and insert it as a reusable channel in the messaging layer that can be used across various systems. WCF interoperates with existing investments and combines and extends existing Microsoft distributed systems technologies like Enterprise Services, System.Messaging, Microsoft .NET Remoting, ASMX and Web Services Extensions (WSE). This change implies that you can use a single model for different types of application behaviours which significantly reduces the complexity in application development. WCF also offers interoperability with non-Microsoft applications through support of the WS-I basic profile and a number of additional WS-* standards.&lt;/p&gt; &lt;p&gt;Finally in terms of productivity you can get a significant order of magnitude difference in developing secure transactional web services using WCF. Think of WCF as tens of thousands of lines of code that you would need to develop, generate and maintain, but instead are provided now as part of the base framework. WCF offers one of the first core programming frameworks that have been designed from the ground-up for services oriented development.&lt;/p&gt; &lt;h2&gt;Windows Workflow (WF)&lt;/h2&gt; &lt;img alt="" _href="img://image3.jpg" src="http://www.infoq.com/resource/articles/akif-dotnet-architect/en/resources/image3.jpg" /&gt; &lt;p&gt;Workflow Foundation is an enterprise class workflow development framework and engine that has taken declarative workflow mainstream for the first time. WF supports human, system, sequential and state-machine workflows. It provides runtime infrastructure, flexible flow control, long running and stateful work flows and runtime and design time transparency and auditing capabilities for compliance and record management. &lt;/p&gt; &lt;p&gt;Workflow Foundation allows you to define a workflow as a set of activities. Activities are the unit of execution and allow for easy re-use and composition. Basic activities are steps within a workflow while composite activities contain other activities. You can add and remove activities even when a workflow is already in progress allowing you significant flexibility in terms of change. Workflow Foundation provides a base activity library out-of-the-box and a framework for partners and customers to easily author custom activities.&lt;/p&gt; &lt;p&gt;In terms of authoring options, you can use XAML mark-up only, mark-up plus code or code-only. Visual Studio 2005 Designer for Workflow Foundation is available as a downloadable plug-in and provides a drag-and-drop design surface, intuitive graphical tools, integration with the Properties window, debugging and graphic Commenting capabilities.&lt;/p&gt; &lt;img style="width: 551px; height: 381px;" alt="" _href="img://image4.jpg" src="http://www.infoq.com/resource/articles/akif-dotnet-architect/en/resources/image4.jpg" /&gt; &lt;p&gt;A number of architects have asked me about the relationship between Workflow Foundation, BizTalk, Microsoft Office SharePoint Server 2007, (MOSS 2007) and Windows SharePoint Services (WSS).&lt;/p&gt; &lt;p&gt;Workflow Foundation, (WF), was developed by the same team at Microsoft that developed the BizTalk workflow engine and is intended to be utilized by BizTalk Server in future versions. WF provides the foundation for implementing workflow scenarios mostly within an application and between applications in certain cases. BizTalk allows you to automate your business processes, orchestrate processes comprising of systems implemented in different technologies through adapters and provide advance business activity monitoring capabilities.&lt;/p&gt; &lt;p&gt;In terms of MOSS 2007 and WSS, MOSS 2007 is built on top of WF and provides additional functionalities and features using WF for the base functionality. Windows SharePoint Services provides a subset of the functionality of MOSS 2007 as an add-in to Windows Server. Simply put, WSS provides simple document management capabilities and workflow.&lt;/p&gt; &lt;img style="width: 558px; height: 375px;" alt="" _href="img://image5.jpg" src="http://www.infoq.com/resource/articles/akif-dotnet-architect/en/resources/image5.jpg" /&gt; &lt;h2&gt;Windows Presentation Foundation (WPF)&lt;/h2&gt; &lt;p&gt;Windows Presentation Foundation attempts to bridge the gap between the immersive user experience typically found in the gaming and entertainment industry and the static and hard-to-use world of business. WPF uses XAML extensively to allow you to develop the next generation of interfaces without becoming a graphic designer yourself.&lt;/p&gt; &lt;p&gt;I would encourage you to see a demonstration of a WPF application to understand what I mean by the next-generation user interface. You can, for example, view fifteen of the most precious books present at the British Library (&lt;a href="http://www.bl.uk/ttp2/ttp1.html"&gt;http://www.bl.uk/ttp2/ttp1.html&lt;/a&gt; ) including Mozart and DaVanci hand-written notebooks. This reader is a WPF based application hosted in a Internet Explorer browser session and is referred to as an XBAP, the technology meant to replace ActiveX in the browser functionality-wise. The key differentiator for WPF is not the end product, a wonderfully rich interface, but actually how easy it is to develop and maintain the application code.&lt;/p&gt; &lt;p&gt;From an architectural perspective, WPF maintains a very clear separation between the graphic element and business logic. A designer will use the Expression product line and XAML to build the view, while the developer will use Visual Studio and write code using VB.NET or C#.&lt;/p&gt; Another technology that has received a lot of attention lately is WPF Everywhere, (WPF/E), which is now officially called SilverLight. Please note that SilverLight is not part of the NET 3.0 framework. SilverLight is a cross-browser, cross-platform plug-in with its own runtime for delivering the next generation of Microsoft .NET-based media experiences and rich interactive applications for the Web. You can find out more information about SilverLight and view the demonstrations at &lt;a href="http://www.microsoft.com/silverlight"&gt;http://www.microsoft.com/silverlight&lt;/a&gt;. &lt;h2&gt;Windows Card Spaces (WCS)&lt;/h2&gt; &lt;p&gt;In today's world, everyone carries a number of self asserted and third party issued identities. Examples of these identities include driving licences, credit card, cinema card and others. We have control over the information we use to prove our identity to the requesting party. Windows Card Spaces extends the same concept of user control to the digital world. WCS creates an identity meta-system that can significantly improve the way enterprises manage identities within their organization and between different organizations. To understand the potential, it has been praised by one of Microsoft's prominent critics as "one of the most significant contribution to computer security since cryptology.&lt;/p&gt; &lt;p&gt;In the digital world, identity can be expressed as subject (who), identity claims and security token (digital representation of subject and claims). WCS uses the concept of self-asserted and managed identities, a self asserted digital identity card could be used for signing up with a service like Hotmail whereas a managed identity could be a credit card issued by a bank. The following picture illustrates the protocol that is used to exchange information between the various entities. Please note that in this case the Identity provider could use Kerberos, X509 or a custom mechanism. Similarly the relaying party could use SAML or send the security token using HTTPS post.&lt;/p&gt; &lt;p&gt;WCS provides an overarching framework for various implementations of identity management technologies to work together. At Java One (which is the one of largest Java conferences in the world), Sun and Microsoft did a joint keynote demonstrating interoperability mechanisms based on WS-* standards. I have posted the link to the demonstration and the toolkit at my blog mentioned at the end of this article.&lt;/p&gt; &lt;p class="image-wide"&gt;&lt;img alt="" _href="img://image6.jpg" src="http://www.infoq.com/resource/articles/akif-dotnet-architect/en/resources/image6.jpg" /&gt;&lt;/p&gt; &lt;h2&gt;Conclusion&lt;/h2&gt; &lt;p&gt;The .NET 3.0 Framework opens up a new world of possibilities for both architects and developers. It is intended to make it significantly easier for you to develop, integrate and maintain application based systems. Microsoft plans to continue this same philosophy of reducing complexity and infrastructure plumbing while concurrently increasing interoperability and standards support for the future version of the .NET framework.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-5129567862865339752?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/5129567862865339752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=5129567862865339752' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/5129567862865339752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/5129567862865339752'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/07/introduction-to-net-30-for-architects.html' title='Introduction to .NET 3.0 for Architects'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-5735033320959897694</id><published>2007-07-04T14:29:00.000+05:30</published><updated>2007-07-04T14:33:31.107+05:30</updated><title type='text'>CLR Garbage Collector</title><content type='html'>Justin Smith presents the internals of the .NET Garbage Collector and how you should design your types to play nicely with it. Learn about heap allocations, the GC Algorithms, Multiprocessor considerations, and the IDisposable pattern.&lt;br /&gt;&lt;a href="http://www.infoq.com/presentations/justin-smith-clr-gc"&gt;Join the conference&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-5735033320959897694?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/5735033320959897694/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=5735033320959897694' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/5735033320959897694'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/5735033320959897694'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/07/clr-garbage-collector.html' title='CLR Garbage Collector'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-2407039442635498073</id><published>2007-06-15T14:39:00.000+05:30</published><updated>2008-11-13T14:10:45.872+05:30</updated><title type='text'>Silverlight Architecture - Part1</title><content type='html'>&lt;span style="font-size:85%;"&gt;Silverlight has few basic properties: &lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;It integrates with various browsers on Windows and on the Macintosh. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;It enables rendering of richer user experiences that are defined by XAML. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;It render media (music and video). &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;It enables programming that is consistent with the Web programming model. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;It is small. &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;Silverlight was designed to address these properties, &lt;/span&gt;&lt;a href="http://4.bp.blogspot.com/_c83J-PNKWTc/RnJYey8IzHI/AAAAAAAAAak/_-vQnxxE9Ik/s1600-h/silverlightarchitecture.gif"&gt;&lt;span style="font-size:85%;"&gt;&lt;img id="BLOGGER_PHOTO_ID_5076217016093297778" style="FLOAT: right; MARGIN: 0px 0px 10px 10px; CURSOR: hand" alt="" src="http://4.bp.blogspot.com/_c83J-PNKWTc/RnJYey8IzHI/AAAAAAAAAak/_-vQnxxE9Ik/s320/silverlightarchitecture.gif" border="0" /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;Lightweight browser plug-in&lt;/strong&gt;—Silverlight has Windows and Macintosh modules that are designed to enhance Internet Explorer (versions 6.0 and 7.0), Firefox 2.0, and Safari browsers. The December 2006 CTP for Windows is 1.1 MB in size. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;Native presentation runtime&lt;/strong&gt;— Software-based browser enhancement that allows rendering of XAML-based interactive 2-D graphics, text, and media, in addition to the browser native rendering of HTML. XAML can be used inline, in a file, or in a package. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;Interactive video and audio&lt;/strong&gt;—Cross-platform independent media runtime that can render Windows Media content (WMV and WMA) in addition to MP3 (will be available after the December 2006 CTP). Video and audio are handled as a media element in XAML, enabling flexibility in their presentation. Furthermore, the media support leverages the huge infrastructure and ecosystem around Windows Media, enabling cost-effective delivery of top-quality media. &lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;Programming layer&lt;/strong&gt;—In consistency with the Web architecture, Silverlight XAML is exposed using a DOM model to JavaScript. That way, AJAX programs can utilize the extended markup rendering capability using the same programming paradigms and practices (on the client and on the server). After the December 2006 CTP, we will also enable a managed code programming model using a subset of full CLR that will enhance the programmability side of the browsers to enable more performant and more scalable Web applications. &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-2407039442635498073?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/2407039442635498073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=2407039442635498073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/2407039442635498073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/2407039442635498073'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/06/silverlight-architecture-part1.html' title='Silverlight Architecture - Part1'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_c83J-PNKWTc/RnJYey8IzHI/AAAAAAAAAak/_-vQnxxE9Ik/s72-c/silverlightarchitecture.gif' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-1071890820491370403</id><published>2007-06-12T23:53:00.000+05:30</published><updated>2007-06-13T00:38:26.489+05:30</updated><title type='text'>Google's Application Fabric</title><content type='html'>&lt;font size="4"&gt;&lt;font size="3"&gt;&lt;font style="font-weight: bold;" size="3"&gt;Application Fabrics: An Overview&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/font&gt;&lt;div style="text-align: left;"&gt;Two major IT trends – commoditization of computing hardware and ubiquity of highperformance networking – have made a new kind of application infrastructure software possible: &lt;font style="font-style: italic;"&gt;application fabrics&lt;/font&gt;. Application fabrics deliver on the promise of “real-time” grid computing, virtualization and utility computing, and are applicable to the most demanding CPU- and data- intensive applications in the enterprise. An application fabric provides a software-based environment that simultaneously delivers scalability, dependability, manageability and affordability for time-critical applications.&lt;br /&gt;&lt;br /&gt;Compared to the traditional grid computing approach, application fabrics create a self-managing, self-healing application environment out of standards-based commodity hardware and operating systems, rather than relying on a set of separately-managed, heterogeneous resources to provide additional computing power. This difference is very important for several reasons. Most importantly, this architectural approach allows application fabrics to provide support for time-sensitive applications that are unable to withstand the latency and unpredictability associated with batch-oriented technologies like traditional grids. Further, this approach allows application fabrics to virtualize the commodity hardware nodes into a single system, enabling developers and administrators to view and manage the hardware as if it were a single computer. Finally, this architecture provides application-level fault-tolerance, rather than depending on the reliability of a collection of heterogeneous infrastructure resources under distributed control.&lt;br /&gt;&lt;font style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/font&gt;&lt;font style="font-weight: bold;"&gt;&lt;font size="3"&gt;Putting Application Fabrics to Use&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;At some point in the future, application fabrics will become a standard deployment option for all applications. At this point in the maturity of the market, application fabrics are being used most frequently to benefit time-critical analytics, high-performance computing and data-processing applications, deployed either as stand-alone applications or as Web services within an SOA environment. These applications can be characterized as CPU- and/or data-intensive in their efforts to provide timely business insights and capabilities that are essential to the ongoing operations of an enterprise.&lt;br /&gt;&lt;br /&gt;For time-critical applications that are CPU-intensive, application fabrics provide effortless scaling across a “fabric” of hundreds or even thousands of commoditygrade computers. At the scale often required for these applications, the automated management offered by application fabrics becomes a key consideration, greatly reducing application total cost-of-ownership (TCO).&lt;br /&gt;&lt;br /&gt;For time-critical applications that process high volumes of data, reliability is paramount Organizations cannot afford failure mid-way through a process or transaction, which might cause errors and inconsistencies throughout multiple systems. For these applications, application fabrics provide the reliability of expensive, high-end systems at the cost of commodity hardware.&lt;br /&gt;&lt;br /&gt;For both CPU- and data-intensive time-critical applications, the effortless scaling of application fabric environments enables organizations to bring online only the computing power they need today, with the knowledge they can easily add additional computers later, as needed.&lt;br /&gt;&lt;br /&gt;CPU/data-intensive time-critical applications may be deployed as Web services within an SOA environment, rather than as stand-alone applications. In services-oriented environments, business logic is not rigidly associated with a single application, but rather available as Web services to be accessed and assembled into a variety of composite applications, for a variety of audiences. Time-critical applications composed of a large number of services can become very brittle, since the failure of one basic service can cause a chain reaction that brings each of the composite applications that consume that service to a halt. Deploying an application fabric as a key component of a services-oriented environment secures the dependability of individual services and thus ensures the performance of time-critical applications that rely on those services, without the need for additional hardware or software infrastructure.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-weight: bold;" size="3"&gt;&lt;font&gt;Google Puts Its Application Fabric To Highly Productive Use&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;Google’s application fabric underlies its powerful core applications, including its search engine. For each search request, the search application queries a 40+ terabyte index of over 4 billion Web pages to produce search results, which are delivered to endusers often at sub-second rates. Google’s applications are run on 60,000+ famously inexpensive commodity computers running Linux, and its application fabric manages these tens of thousands of computers as a self-managing and self-healing network that is both extremely scalable and inexpensive considering its capability. The fabric facilitates bringing new machines on line to expand capacity and allows dead machines to be swapped-out at the system administrators’ convenience, all without interruption of service.&lt;br /&gt;&lt;br /&gt;The result of Google’s underlying application fabric is that the company’s executives can work to grow the business, enhance existing services and create new ones, all without concern for the ability of its applications and infrastructure to keep up. And not only can Google’s application fabric keep up, but it can do so with linear cost increases to add capacity, rather than periodic massive overhauls to re-architect for new requirements.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-weight: bold;" size="3"&gt;&lt;font&gt;Benefits of Application Fabric Software to Key Stakeholders&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;Overall, application fabrics benefit enterprises by enabling applications to be simultaneously scalable, dependable, manageable and affordable. These applications can create new capabilities and insights for the business, which drive greater business agility and competitive advantage.&lt;br /&gt;&lt;br /&gt;Specifically, application fabrics benefit numerous key stakeholders within an organization:&lt;br /&gt;&lt;font style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Application architects and developers&lt;/span&gt;&lt;/font&gt;: Application architects and developers are in the business of translating business requirements into technology-based solutions. Traditional application deployment approaches require architects to design to the limitations of the infrastructure. Application fabric software frees architects from having to trade-off among scalability, dependability, manageability and affordability, thus allowing them to focus on creating maximum business value. With application fabric software, developers are also freed from infrastructure limitations, in particular the need to worry about complicated distributed computing concepts Instead, developers can write code as if the applications were going to&lt;br /&gt;be deployed on a single computer.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-weight: bold; font-style: italic;"&gt;Systems administrators&lt;/font&gt;: Systems administrators are responsible for deploying and managing applications and their infrastructure, including adding capacity to the infrastructure as the demands on a given application grow. With application fabrics, administrators can treat a network of commodity machines as a virtualized single system, easing deployment and management challenges as all changes to any hardware, software, or applications running within the fabric happen dynamically. Further, application fabric software can detect when new “bare metal” has been added to the fabric’s network, automatically installing the appropriate operating system, fabric software and applications.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-weight: bold; font-style: italic;"&gt;Technology executives&lt;/font&gt;: IT and engineering executives are responsible for enabling competitive advantage through technology-related initiatives, while minimizing the cost of doing so. Application fabrics provide a dependable environment that IT executives can count on to make strategic applications scalable, dependable, manageable and affordable. As a result, technology executives can bring new capabilities and insights to market faster, driving forward the organization’s ability to outpace the competition. And because they run on commodity-grade hardware and industry-standard operating systems, application fabrics also minimize the cost of deploying and scaling these applications. Another large component of a technology executive’s job is to manage the talent within a technology organization. In the past, these executives were forced to deploy senior development staff to manually build scalability and reliability into application environments. With application fabric software, executives can rely on the fabric layer to provide these qualities, rather than expensive and hard-to-find development talent.&lt;br /&gt;&lt;br /&gt;&lt;font style="font-weight: bold; font-style: italic;"&gt;Business executives&lt;/font&gt;: Business executives are concerned with the overall success of the business, which requires the agility to stay ahead of the competition. Appistry EAF supports competitive agility by decoupling strategic applications from the limitations of their physical infrastructure. Confident that their fabricbased applications will keep pace, business executives are freed to imagine new capabilities and drive for new insights, thus improving decision-making, providing better value and service to consumers, operating more efficiently, and, ultimately, staying ahead of the competition.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-1071890820491370403?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/1071890820491370403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=1071890820491370403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1071890820491370403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1071890820491370403'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/06/googles-application-fabric.html' title='Google&apos;s Application Fabric'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-3773298504804050239</id><published>2007-06-12T23:40:00.000+05:30</published><updated>2007-06-15T15:08:07.941+05:30</updated><title type='text'>Interviews</title><content type='html'>&lt;span style="font-family:arial;font-size:12;"&gt;&lt;/span&gt;&lt;h1 style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12pt; MARGIN-BOTTOM: 5px; PADDING-BOTTOM: 0px; COLOR: black; LINE-HEIGHT: 10pt; PADDING-TOP: 0px; FONT-FAMILY: Arial"&gt;&lt;a style="COLOR: black; TEXT-DECORATION: none" href="http://cts.vresp.com/c/?InfoQ/1eb5d043b9/db853fd7a1/7dc2a9c5a7" target="_blank" rel="nofollow"&gt;Interview: Erik Saltwell on Expression Web&lt;/a&gt;&lt;/h1&gt;&lt;br /&gt;&lt;span style="font-family:arial;font-size:12;"&gt;&lt;/span&gt;&lt;h1 style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12pt; MARGIN-BOTTOM: 5px; PADDING-BOTTOM: 0px; COLOR: black; LINE-HEIGHT: 10pt; PADDING-TOP: 0px; FONT-FAMILY: Arial"&gt;&lt;a style="COLOR: black; TEXT-DECORATION: none" href="http://cts.vresp.com/c/?InfoQ/1eb5d043b9/db853fd7a1/f19ad8b402" target="_blank" rel="nofollow"&gt;Interview: Jezz Santos about Software Factories&lt;/a&gt;&lt;/h1&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-3773298504804050239?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/3773298504804050239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=3773298504804050239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/3773298504804050239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/3773298504804050239'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/06/inerviews.html' title='Interviews'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-1391409529019329457</id><published>2007-06-12T22:02:00.000+05:30</published><updated>2007-06-12T23:34:23.189+05:30</updated><title type='text'>Understanding .NET Code Access Security</title><content type='html'>&lt;font style="font-weight: bold;"&gt;My favorite Article on CodeProject by UB&lt;br /&gt;&lt;/font&gt;&lt;font style="font-weight: bold;" size="2"&gt;&lt;br /&gt;Other Suggested Readings-&lt;/font&gt;&lt;font size="2"&gt;&lt;br /&gt;&lt;/font&gt; &lt;ul&gt;&lt;li&gt;&lt;font id="intelliTXT1" size="2"&gt;&lt;a href="http://www.codeproject.com/gen/design/CASDesignPatterns.asp"&gt;Code Access Security Design Pattern&lt;/a&gt;&lt;/font&gt;&lt;/li&gt;&lt;font size="2"&gt;&lt;br /&gt;&lt;/font&gt;&lt;li&gt;&lt;font id="intelliTXT2" size="2"&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/HTCode_Acc.asp" target="_blank"&gt;Code Access Security in Practice&lt;/a&gt;&lt;/font&gt;&lt;/li&gt;&lt;font size="2"&gt;&lt;br /&gt;&lt;/font&gt;&lt;li&gt;&lt;font id="intelliTXT3" size="2"&gt;&lt;a href="http://www.codeproject.com/dotnet/UB_CAS_NET.asp#Functions%20of%20Code%20Access%20Security"&gt;Functions of Code Access Security&lt;/a&gt;&lt;/font&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;A full length article on .NET Code Access Security  by UB&lt;font id="intelliTXT"&gt;&lt;h2&gt;&lt;a name="Introduction"&gt;Introduction&lt;/a&gt;&lt;/h2&gt;  &lt;p&gt;.NET has two kinds of security:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;&lt;b&gt;Role Based Security&lt;/b&gt; (not being discussed in this article)  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Code Access Security&lt;/b&gt; &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;The Common Language Runtime (CLR) allows code to perform only those operations that the code has permission to perform. So CAS is the CLR's security system that enforces security policies by preventing unauthorized access to protected &lt;b&gt;resources&lt;/b&gt; and &lt;b&gt;operations&lt;/b&gt;. Using the Code Access Security, you can do the following:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;Restrict what your code can do&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Restrict which code can call your code&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Identify code&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;We'll be discussing about these things through out this article. Before that, you should get familiar with the following key elements of CAS.&lt;/p&gt; &lt;h2&gt;&lt;a name="Jargon"&gt;&lt;/a&gt;&lt;/h2&gt;  &lt;ul&gt;&lt;li&gt;&lt;b&gt;permissions&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;permission sets&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;code groups&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;evidence&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;policy&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt; &lt;h4&gt;Permissions&lt;/h4&gt; &lt;p&gt;Permissions represent access to a protected resource or the ability to perform a protected operation. The .NET Framework provides several permission classes, like &lt;code&gt;FileIOPermission&lt;/code&gt; (when working with files), &lt;code&gt;UIPermission&lt;/code&gt; (permission to use a user interface), &lt;code&gt;SecurityPermission&lt;/code&gt; (this is needed to execute the code and can be even used to bypass security) etc.&lt;br /&gt;&lt;/p&gt; &lt;h4&gt;Permission sets&lt;/h4&gt; &lt;p&gt;A permission set is a collection of permissions. You can put &lt;code&gt;FileIOPermission&lt;/code&gt; and &lt;code&gt;UIPermission&lt;/code&gt; into your own permission set and call it "&lt;code&gt;My_PermissionSet&lt;/code&gt;". A permission set can include any number of permissions. &lt;code&gt;FullTrust&lt;/code&gt;, &lt;code&gt;LocalIntranet&lt;/code&gt;, &lt;code&gt;Internet&lt;/code&gt;, &lt;code&gt;Execution&lt;/code&gt; and &lt;code&gt;Nothing&lt;/code&gt; are some of the built in permission sets in .NET Framework. &lt;code&gt;FullTrust&lt;/code&gt; has all the permissions in the world, while &lt;code&gt;Nothing&lt;/code&gt; has no permissions at all, not even the right to execute.&lt;/p&gt; &lt;h4&gt;Code groups&lt;/h4&gt; &lt;p&gt;Code group is a logical grouping of code that has a specified condition for membership. Code from &lt;i&gt;http://www.somewebsite.com/&lt;/i&gt; can belong to one code group, code containing a specific strong name can belong to another code group and code from a specific assembly can belong to another code group. There are built-in code groups like &lt;code&gt;My_Computer_Zone&lt;/code&gt;&lt;b&gt;, &lt;/b&gt;&lt;code&gt;LocalIntranet_Zone&lt;/code&gt;&lt;b&gt;, &lt;/b&gt;&lt;code&gt;Internet_Zone&lt;/code&gt; etc. Like permission sets, we can create code groups to meet our requirements based on the &lt;b&gt;evidence&lt;/b&gt; provided by .NET Framework. &lt;code&gt;Site&lt;/code&gt;, &lt;code&gt;Strong Name&lt;/code&gt;, &lt;code&gt;Zone&lt;/code&gt;, &lt;code&gt;URL&lt;/code&gt; are some of the types of evidence.&lt;/p&gt; &lt;h4&gt;&lt;a name="policy"&gt;Policy&lt;/a&gt;&lt;/h4&gt; &lt;p&gt;Security policy is the configurable set of rules that the CLR follows when determining the permissions to grant to code. There are four policy levels - &lt;code&gt;Enterprise&lt;/code&gt;, &lt;code&gt;Machine&lt;/code&gt;, &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Application Domain&lt;/code&gt;, each operating independently from each other. Each level has its own code groups and permission sets. They have the hierarchy given below.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/Policy.gif" border="0" height="222" width="553"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 1&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Okay, enough with the theory, it's time to put the theory into practice.&lt;/p&gt; &lt;h2&gt;&lt;a name="Quick Example"&gt;Quick Example&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Let's create a new Windows application. Add two buttons to the existing form. We are going to work with the file system, so add the &lt;code&gt;System.IO&lt;/code&gt; namespace.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.IO;&lt;/pre&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/Example1_1.gif" border="0" height="232" width="344"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 2&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Write the following code:&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; btnWrite_click(&lt;font class="cs-keyword"&gt;object&lt;/font&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;StreamWriter myFile = &lt;font class="cs-keyword"&gt;new&lt;/font&gt; StreamWriter(&lt;font class="cpp-string"&gt;"c:\\Security.txt"&lt;/font&gt;);&lt;br /&gt;myFile.WriteLine(&lt;font class="cpp-string"&gt;"Trust No One"&lt;/font&gt;);&lt;br /&gt;myFile.Close();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; btnRead_click(&lt;font class="cs-keyword"&gt;object&lt;/font&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;StreamReader myFile = &lt;font class="cs-keyword"&gt;new&lt;/font&gt; StreamReader(&lt;font class="cpp-string"&gt;"c:\\Security.txt"&lt;/font&gt;);&lt;br /&gt;MessageBox.Show(myFile.ReadLine())&lt;br /&gt;myFile.Close()&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;The version number should be intact all the time, for our example to work. Make sure that you set the version number to a fixed value, otherwise it will get incremented every time you compile the code. We're going to sign this assembly with a strong name which is used as evidence to identify our code. That's why you need to set the version number to a fixed value.&lt;/p&gt;&lt;pre lang="cs"&gt;[assembly: AssemblyVersion(&lt;font class="cpp-string"&gt;"1.0.0.0"&lt;/font&gt;)]&lt;/pre&gt; &lt;p&gt;That's it ... nothing fancy. This will write to a file named &lt;i&gt;Security.txt&lt;/i&gt; in &lt;i&gt;C:&lt;/i&gt; drive. Now run the code, it should create a file and write the line, everything should be fine ... unless of course you don't have a &lt;i&gt;C:&lt;/i&gt; drive. Now what we are going to do is put our assembly into a code group and set some permissions. Don't delete the &lt;i&gt;Security.txt&lt;/i&gt; file yet, we are going to need it later. Here we go.&lt;/p&gt; &lt;h3&gt;.NET Configuration Tool&lt;/h3&gt; &lt;p&gt;We can do this in two ways, from the &lt;b&gt;.NET Configuration Tool&lt;/b&gt; or from the command prompt using &lt;b&gt;caspol.exe&lt;/b&gt;. First we'll do this using the .NET Configuration Tool. Go to Control Panel --&gt; Administrative Tools --&gt; Microsoft .NET Framework Configuration. You can also type "&lt;b&gt;mscorcfg.msc&lt;/b&gt;" at the .NET command prompt. You can do cool things with this tool ... but right now we are only interested in setting code access security.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_1.gif" border="0" height="394" width="425"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 3&lt;/b&gt;&lt;/p&gt; &lt;h3&gt;Creating a new permission set&lt;/h3&gt; &lt;p&gt;Expand the &lt;b&gt;Runtime Security Policy&lt;/b&gt; node. You can see the security policy levels - &lt;code&gt;Enterprise&lt;/code&gt;, &lt;code&gt;Machine&lt;/code&gt; and &lt;code&gt;User&lt;/code&gt;. We are going to change the security settings in &lt;code&gt;Machine&lt;/code&gt; policy. First we are going to create our own custom permission set. Right click the &lt;b&gt;Permission Sets&lt;/b&gt; node and choose &lt;b&gt;New&lt;/b&gt;. Since I couldn't think of a catchy name, I'm going to name it &lt;code&gt;MyPermissionSet&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_2.gif" border="0" height="460" width="479"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 4&lt;/b&gt;&lt;/p&gt; &lt;p&gt;In the next screen, we can add permissions to our permission set. In the left panel, we can see all the permissions supported by the .NET Framework. Now get the properties of &lt;b&gt;File IO &lt;/b&gt;permission. Set the &lt;b&gt;File Path&lt;/b&gt; to &lt;i&gt;C:\&lt;/i&gt; and check &lt;b&gt;Read&lt;/b&gt; only, don't check others. So we didn't give write permission, we only gave read permission. Please note that there is another option saying "&lt;b&gt;Grant assemblies unrestricted access to the file system&lt;/b&gt;." If this is selected, anything can be done without any restrictions for that particular resource, in this case the file system.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_3.gif" border="0" height="285" width="550"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 5&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Now we have to add two more permissions - &lt;b&gt;Security&lt;/b&gt; and &lt;b&gt;User&lt;/b&gt; &lt;b&gt;Interface&lt;/b&gt;. Just add them and remember to set the "&lt;b&gt;Grant assemblies unrestricted access&lt;/b&gt;". I'll explain these properties soon. Without the &lt;b&gt;Security&lt;/b&gt; permission, we don't have the right to execute our code, and without the &lt;b&gt;User Interface&lt;/b&gt; permission, we won't be able to show a UI. If you're done adding these three permissions, you can see there is a new permission set created, named &lt;code&gt;MyPermissionSet&lt;/code&gt;.&lt;/p&gt; &lt;h3&gt;Creating a new code group&lt;/h3&gt; &lt;p&gt;Now we will create a code group and set some conditions, so our assembly will be a member of that code group. Notice that in the code groups node, &lt;b&gt;All_Code&lt;/b&gt; is the parent node. Right Click the &lt;b&gt;All_Code&lt;/b&gt; node and choose &lt;b&gt;New&lt;/b&gt;. You'll be presented with the &lt;b&gt;Create Code Group wizard&lt;/b&gt;. I'm going to name it &lt;code&gt;MyCodeGroup&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_4.gif" border="0" height="282" width="550"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 6&lt;/b&gt;&lt;/p&gt; &lt;p&gt;In the next screen, you have to provide a condition type for the code group. Now these are the &lt;b&gt;evidence&lt;/b&gt; that I mentioned earlier. For this example, we are going to use the &lt;b&gt;Strong Name &lt;/b&gt;condition type. First, sign your assembly with a strong name and build the project. Now press the &lt;b&gt;Import&lt;/b&gt; button and select your assembly. Public Key, Name and Version will be extracted from the assembly, so we don't have to worry about them. Now move on to the next screen. We have to specify a permission set for our code group. Since we have already created one - &lt;code&gt;MyPermissionSet&lt;/code&gt;, select it from the list box.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_5.gif" border="0" height="260" width="550"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 7&lt;/b&gt;&lt;/p&gt; &lt;h3&gt;&lt;a name="Exclusive and Level Final"&gt;Exclusive and LevelFinal&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;If you haven't messed around with the default .NET configuration security settings, your assembly already belongs to another built-in code group - &lt;code&gt;My_Computer_Zone&lt;/code&gt;. When permissions are calculated, if a particular assembly falls into more than one code group within the same policy level, the final permissions for that assembly will be the union of all the permissions in those code groups. I'll explain how to calculate permissions later, for the time being we only need to run our assembly only with our permission set and that is &lt;code&gt;MyPermissionSet&lt;/code&gt; associated with the &lt;code&gt;MyCodeGroup&lt;/code&gt;. So we have to set another property to do just that. Right click the newly created &lt;b&gt;MyCodeGroup&lt;/b&gt; node and select &lt;b&gt;Properties&lt;/b&gt;. Check the check box saying "&lt;b&gt;This policy level will only have the permissions from the permission set associated with this code group.&lt;/b&gt;" This is called the &lt;code&gt;Exclusive&lt;/code&gt; attribute. If this is checked then the run time will never grant more permissions than the permissions associated with this code group. The other option is called &lt;code&gt;LevelFinal&lt;/code&gt;. These two properties come into action when calculating permissions and they are explained below in detail.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_6.gif" border="0" height="443" width="403"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 8&lt;/b&gt;&lt;/p&gt; &lt;p&gt;I know we have set lots of properties, but it'll all make sense at the end (hopefully).&lt;/p&gt; &lt;p&gt;Okay .. it's time to run the code. What we have done so far is, we have put our code into a code group and given permissions only to read from &lt;i&gt;C:&lt;/i&gt; drive. Run the code and try both buttons. &lt;b&gt;Read&lt;/b&gt; should work fine, but when you press &lt;b&gt;Write,&lt;/b&gt; an exception will be thrown because we didn't set permission to write to &lt;i&gt;C:&lt;/i&gt; drive. Below is the error message that you get.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ErrorMessage_1.gif" border="0" height="189" width="444"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 9&lt;/b&gt;&lt;/p&gt; &lt;p&gt;So thanks to Code Access Security, this kind of restriction to a resource is possible. There's a whole lot more that you can do with Code Access Security, which we're going to discuss in the rest of this article.&lt;/p&gt; &lt;h2&gt;&lt;a name="Functions of Code Access Security"&gt;Functions of Code Access Security&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;According to the documentation, Code Access Security performs the following functions: (straight from the documentation)&lt;/p&gt; &lt;ul&gt;&lt;li&gt;Defines &lt;b&gt;permissions&lt;/b&gt; and &lt;b&gt;permission sets&lt;/b&gt; that represent the right to access various system resources.  &lt;/li&gt;&lt;li&gt;Enables administrators to configure &lt;b&gt;security policy&lt;/b&gt; by associating sets of permissions with groups of code (&lt;b&gt;code groups&lt;/b&gt;).  &lt;/li&gt;&lt;li&gt;Enables code to &lt;b&gt;request&lt;/b&gt; the &lt;b&gt;permissions it requires in order to run&lt;/b&gt;, as well as the &lt;b&gt;permissions that would be useful to have&lt;/b&gt;, and specifies which &lt;b&gt;permissions the code must never have&lt;/b&gt;.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Grants permissions&lt;/b&gt; to each assembly that is loaded, based on the permissions requested by the code and on the operations permitted by security policy. &lt;/li&gt;&lt;li&gt;Enables code to &lt;b&gt;demand&lt;/b&gt; that its callers have specific permissions. Enables code to demand that its callers possess a digital signature, thus allowing only callers from a particular organization or site to call the protected code. &lt;/li&gt;&lt;li&gt;&lt;b&gt;Enforces restrictions&lt;/b&gt; on code at run time by comparing the granted permissions of every caller on the call stack to the &lt;b&gt;permissions that callers must have.&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;We have already done the top two, and that is the administrative part. There's a separate namespace that we haven't looked at yet - &lt;code&gt;System.Security&lt;/code&gt;, which is dedicated to implementing security.&lt;/p&gt; &lt;h2&gt;&lt;a name="Security Namespace"&gt;Security Namespace&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;These are the main classes in &lt;code&gt;System.Security&lt;/code&gt; namespace:&lt;/p&gt; &lt;table id="AutoNumber1" border="1" height="27" width="76%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td height="8" width="32%"&gt;&lt;b&gt;Classes&lt;/b&gt;&lt;/td&gt; &lt;td height="8" width="68%"&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;CodeAccessPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Defines the underlying structure of all code access permissions.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;PermissionSet&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Represents a collection that can contain many different types of permissions.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;SecurityException&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;The exception that is thrown when a security error is detected.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;These are the main classes in &lt;code&gt;System.Security.Permissions&lt;/code&gt; namespace:&lt;/p&gt; &lt;table id="AutoNumber1" border="1" height="16" width="76%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td height="8" width="32%"&gt;&lt;b&gt;Classes&lt;/b&gt;&lt;/td&gt; &lt;td height="8" width="68%"&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;EnvironmentPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Controls access to system and user environment variables.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;FileDialogPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Controls the ability to access files or folders through a file dialog.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;FileIOPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Controls the ability to access files and folders.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;IsolatedStorageFilePermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Specifies the allowed usage of a private virtual file system.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;IsolatedStoragePermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Represents access to generic isolated storage capabilities.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;ReflectionPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Controls access to metadata through the &lt;code&gt;System.Reflection&lt;/code&gt; APIs.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;RegistryPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Controls the ability to access registry variables.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;SecurityPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Describes a set of security permissions applied to code.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td height="1" width="32%"&gt;&lt;code&gt;UIPermission&lt;/code&gt;&lt;/td&gt; &lt;td height="1" width="68%"&gt;Controls the permissions related to user interfaces and the clipboard.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;You can find more permission classes in other namespaces. For example, &lt;code&gt;SocketPermission&lt;/code&gt; and &lt;code&gt;WebPermission&lt;/code&gt; in &lt;code&gt;System.Net&lt;/code&gt; namespace, &lt;code&gt;SqlClientPermission&lt;/code&gt; in &lt;code&gt;System.Data.SqlClient&lt;/code&gt; namespace, &lt;code&gt;PerformanceCounterPermission&lt;/code&gt; in &lt;code&gt;System.Diagnostics&lt;/code&gt; namespace etc. All these classes represent a protected resource.&lt;/p&gt; &lt;p&gt;Next, we'll see how we can use these classes.&lt;/p&gt; &lt;h2&gt;&lt;a name="Declarative vs Imperative"&gt;Declarative vs. Imperative&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;You can use two different kinds of syntax when coding, declarative and imperative.&lt;/p&gt; &lt;h4&gt;Declarative syntax&lt;/h4&gt; &lt;p&gt;Declarative syntax uses attributes to mark the method, class or the assembly with the necessary security information. So when compiled, these are placed in the metadata section of the assembly.&lt;/p&gt;&lt;pre lang="cs"&gt;[FileIOPermission(SecurityAction.Demand, Unrestricted=&lt;font class="cs-keyword"&gt;true&lt;/font&gt;)]&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; calss MyClass&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; MyClass() {...}   &lt;font class="cs-comment"&gt;// all these methods&lt;/font&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; MyMethod_A() {...} &lt;font class="cs-comment"&gt;// demands unrestricted access to &lt;/font&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; MyMethod_B() {...} &lt;font class="cs-comment"&gt;// the file system&lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;h4&gt;Imperative syntax&lt;/h4&gt; &lt;p&gt;Imperative syntax uses runtime method calls to create new instances of security classes.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; calss MyClass&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; MyClass() { }&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; Method_A()&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do Something&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;FileIOPermission myPerm =&lt;br /&gt;&lt;font class="cs-keyword"&gt;new&lt;/font&gt; FileIOPermission(PermissionState.Unrestricted);&lt;br /&gt;myPerm.Demand();&lt;br /&gt;&lt;font class="cs-comment"&gt;// rest of the code won't get executed if this failed&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do Something&lt;/font&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// No demands&lt;/font&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; Method_B()&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do Something&lt;/font&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;The main difference between these two is, declarative calls are evaluated at compile time while imperative calls are evaluated at runtime. Please note that compile time means during JIT compilation (IL to native).&lt;/p&gt; &lt;p&gt;There are several actions that can be taken against permissions.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/diagram1.jpg" height="279" width="300"&gt;&lt;/p&gt; &lt;p&gt;First, let's see how we can use the declarative syntax. Take the &lt;code&gt;UIPermission&lt;/code&gt; class. Declarative syntax means using attributes. So we are actually using the &lt;code&gt;UIPermissionAttribute&lt;/code&gt; class. When you refer to the MSDN documentation, you can see these public properties:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;code&gt;Action&lt;/code&gt; - one of the values in &lt;code&gt;SecurityAction&lt;/code&gt; &lt;code lang="cs"&gt;&lt;font class="cs-keyword"&gt;enum&lt;/font&gt;&lt;/code&gt; (common)  &lt;/li&gt;&lt;li&gt;&lt;code&gt;Unrestricted&lt;/code&gt; - unrestricted access to the resource (common)  &lt;/li&gt;&lt;li&gt;&lt;code&gt;Clipboard&lt;/code&gt; - type of access to the clipboard, one of the values in &lt;code&gt;UIPermissionClipboard&lt;/code&gt; &lt;code lang="cs"&gt;&lt;font class="cs-keyword"&gt;enum&lt;/font&gt;&lt;/code&gt; (&lt;code&gt;UIPermission&lt;/code&gt; specific)  &lt;/li&gt;&lt;li&gt;&lt;code&gt;Window&lt;/code&gt; - type of access to the window, one of the values in &lt;code&gt;UIPermissionWindow&lt;/code&gt; &lt;code lang="cs"&gt;&lt;font class="cs-keyword"&gt;enum&lt;/font&gt;&lt;/code&gt; (&lt;code&gt;UIPermission&lt;/code&gt; specific). &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;code&gt;Action&lt;/code&gt; and &lt;code&gt;Unrestricted&lt;/code&gt; properties are common to all permission classes. &lt;code&gt;Clipboard&lt;/code&gt; and &lt;code&gt;Window&lt;/code&gt; properties are specific to &lt;code&gt;UIPermission&lt;/code&gt; class. You have to provide the action that you are taking and the other properties that are specific to the permission class you are using. So in this case, you can write like the following:&lt;/p&gt;&lt;pre lang="cs"&gt;[UIPermission(SecurityAction.Demand,&lt;br /&gt;Clipboard=UIPermissionClipboard.AllClipboard)]&lt;/pre&gt; &lt;p&gt;or with both &lt;code&gt;Clipboard&lt;/code&gt; and &lt;code&gt;Window&lt;/code&gt; properties:&lt;/p&gt;&lt;pre lang="cs"&gt;[UIPermission(SecurityAction.Demand,&lt;br /&gt;Clipboard=UIPermissionClipboard.AllClipboard,&lt;br /&gt;Window=UIPermissionWindow.AllWindows)]&lt;/pre&gt; &lt;p&gt;If you want to declare a permission with unrestricted access, you can do it as the following:&lt;/p&gt;&lt;pre lang="cs"&gt;[UIPermission(SecurityAction.Demand, Unrestricted=&lt;font class="cs-keyword"&gt;true&lt;/font&gt;)]&lt;/pre&gt; &lt;p&gt;When using imperative syntax, you can use the constructor to pass the values and later call the appropriate action. We'll take the &lt;code&gt;RegistryPermission&lt;/code&gt; class.&lt;/p&gt;&lt;pre lang="cs"&gt;RegistryPermission myRegPerm =&lt;br /&gt;&lt;font class="cs-keyword"&gt;new&lt;/font&gt; RegistryPermission(RegistryPermissionAccess.AllAccess,&lt;br /&gt;&lt;font class="cpp-string"&gt;"HKEY_LOCAL_MACHINE\\Software"&lt;/font&gt;);&lt;br /&gt;myRegPerm.Demand();&lt;/pre&gt; &lt;p&gt;If you want unrestricted access to the resource, you can use &lt;code&gt;PermissionState&lt;/code&gt; &lt;code lang="cs"&gt;&lt;font class="cs-keyword"&gt;enum&lt;/font&gt;&lt;/code&gt; in the following way:&lt;/p&gt;&lt;pre lang="cs"&gt;RegistryPermission myRegPerm = &lt;font class="cs-keyword"&gt;new&lt;/font&gt;&lt;br /&gt;RegistryPermission(PermissionState.Unrestricted);&lt;br /&gt;myRegPerm.Demand();&lt;/pre&gt; &lt;p&gt;This is all you need to know to use any permission class in the .NET Framework. Now, we'll discuss about the actions in detail.&lt;/p&gt; &lt;h2&gt;&lt;a name="Security Demands"&gt;Security Demands&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Demands are used to ensure that every caller who calls your code (directly or indirectly) has been granted the demanded permission. This is accomplished by performing a stack walk. What .. a cat walk? No, that's what your girl friend does. I mean a stack walk. When demanded for a permission, the runtime's security system walks the call stack, comparing the granted permissions of each caller to the permission being demanded. If any caller in the call stack is found without the demanded permission then a &lt;code&gt;SecurityException&lt;/code&gt; is thrown. Please look at the following figure which is taken from the MSDN documentation.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/StackWalk.GIF" height="206" width="506"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 10&lt;/b&gt;  &lt;/p&gt;&lt;p&gt;Different assemblies as well as different methods in the same assembly are checked by the stack walk.&lt;/p&gt; &lt;p&gt;Now back to demands. These are the three types of demands.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;Demand&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Link Demand&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Inheritance Demand&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Demand&lt;/h3&gt; &lt;p&gt;Try this sample coding. We didn't use security namespaces before, but we are going to use them now.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.Security;&lt;br /&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.Security.Permissions;&lt;/pre&gt; &lt;p&gt;Add another button to the existing form.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; btnFileRead_Click(&lt;font class="cs-keyword"&gt;object&lt;/font&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;try&lt;/font&gt;&lt;br /&gt;{&lt;br /&gt;InitUI(&lt;font class="cs-literal"&gt;1&lt;/font&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;font class="cs-keyword"&gt;catch&lt;/font&gt; (SecurityException err)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show(err.Message,&lt;font class="cpp-string"&gt;"Security Error"&lt;/font&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;font class="cs-keyword"&gt;catch&lt;/font&gt; (Exception err)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show(err.Message,&lt;font class="cpp-string"&gt;"Error"&lt;/font&gt;);&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;&lt;code&gt;InitUI&lt;/code&gt; just calls the &lt;code&gt;ShowUI&lt;/code&gt; function. Note that it has been denied permission to read the &lt;i&gt;C:&lt;/i&gt; drive.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-comment"&gt;// Access is denied for this function to read from C: drive&lt;/font&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// Note: Using declrative syntax&lt;/font&gt;&lt;br /&gt;[FileIOPermission(SecurityAction.Deny,Read=&lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;)]&lt;br /&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; InitUI(&lt;font class="cs-keyword"&gt;int&lt;/font&gt; uino)&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do some initializations&lt;/font&gt;&lt;br /&gt;ShowUI(uino);    &lt;font class="cs-comment"&gt;// call ShowUI&lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;&lt;code&gt;ShowUI&lt;/code&gt; function takes &lt;code&gt;uino&lt;/code&gt; in and shows the appropriate UI.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; ShowUI(&lt;font class="cs-keyword"&gt;int&lt;/font&gt; uino)&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;switch&lt;/font&gt; (uino)&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;case&lt;/font&gt; &lt;font class="cs-literal"&gt;1&lt;/font&gt;: &lt;font class="cs-comment"&gt;// That's our FileRead UI&lt;/font&gt;&lt;br /&gt; ShowFileReadUI();&lt;br /&gt; &lt;font class="cs-keyword"&gt;break&lt;/font&gt;;&lt;br /&gt;&lt;font class="cs-keyword"&gt;case&lt;/font&gt; &lt;font class="cs-literal"&gt;2&lt;/font&gt;:&lt;br /&gt; &lt;font class="cs-comment"&gt;// Show someother UI&lt;/font&gt;&lt;br /&gt; &lt;font class="cs-keyword"&gt;break&lt;/font&gt;; &lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;&lt;code&gt;ShowFileReadUI&lt;/code&gt; shows the UI related to reading files.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; ShowFileReadUI()&lt;br /&gt;{&lt;br /&gt;MessageBox.Show(&lt;font class="cpp-string"&gt;"Before calling demand"&lt;/font&gt;);&lt;br /&gt;FileIOPermission myPerm = &lt;font class="cs-keyword"&gt;new&lt;/font&gt;&lt;br /&gt;FileIOPermission(FileIOPermissionAccess.Read, &lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;);&lt;br /&gt;myPerm.Demand();&lt;br /&gt;&lt;font class="cs-comment"&gt;// All callers must have read permission to C: drive&lt;/font&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// Note: Using imperative syntax&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// code to show UI&lt;/font&gt;&lt;br /&gt;MessageBox.Show(&lt;font class="cpp-string"&gt;"Showing FileRead UI"&lt;/font&gt;);&lt;br /&gt;&lt;font class="cs-comment"&gt;// This is excuted if only the Demand is successful.&lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;I know that this is a silly example, but it's enough to do the job.&lt;/p&gt; &lt;p&gt;Now run the code. You should get the &lt;b&gt;"Before calling demand"&lt;/b&gt; message, and right after that the custom error message - &lt;b&gt;"Security Error"&lt;/b&gt;. What went wrong? Look at the following figure:&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/StackWalk_2.GIF" height="271" width="414"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 11&lt;/b&gt;&lt;/p&gt; &lt;p&gt;We have denied read permission for the &lt;code&gt;InitUI&lt;/code&gt; method. So when &lt;code&gt;ShowFileReadUI&lt;/code&gt; demands read permission to &lt;i&gt;C:&lt;/i&gt; drive, it causes a stack walk and finds out that not every caller is granted the demanded permission and throws an exception. Just comment out the &lt;code&gt;Deny&lt;/code&gt; statement in &lt;code&gt;InitUI&lt;/code&gt; method, then this should be working fine because all the callers have the demanded permission.&lt;/p&gt; &lt;p&gt;Note that according to the documentation, most classes in .NET Framework already have demands associated with them. For example, take the &lt;code&gt;StreamReader&lt;/code&gt; class. &lt;code&gt;StreamReader&lt;/code&gt; automatically demands &lt;code&gt;FileIOPermission&lt;/code&gt;. So placing another demand just before it causes an unnecessary stack walk.&lt;/p&gt; &lt;h3&gt;Link Demand&lt;/h3&gt; &lt;p&gt;A link demand only checks the immediate caller (direct caller) of your code. That means it doesn't perform a stack walk. Linking occurs when your code is bound to a type reference, including function pointer references and method calls. A link demand can only be applied declaratively.&lt;/p&gt;&lt;pre lang="cs"&gt;[FileIOPermission(SecurityAction.LinkDemand,Read=&lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;)]&lt;br /&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; MyMethod()&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do Something &lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;h3&gt;Inheritance Demand&lt;/h3&gt; &lt;p&gt;Inheritance demands can be applied to classes or methods. If it is applied to a class, then all the classes that derive from this class must have the specified permission.&lt;/p&gt;&lt;pre lang="cs"&gt;[SecurityPermission(SecurityAction.InheritanceDemand)]&lt;br /&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;class&lt;/font&gt; MyClass()&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// what ever&lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;If it is applied to a method, then all the classes that derive from this class must have the specified permission to override that method.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;class&lt;/font&gt; MyClass()&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; &lt;font class="cs-keyword"&gt;class&lt;/font&gt; MyClass() {}&lt;br /&gt;&lt;br /&gt;[SecurityPermission(SecurityAction.InheritanceDemand)]&lt;br /&gt;&lt;font class="cs-keyword"&gt;public&lt;/font&gt; &lt;font class="cs-keyword"&gt;virtual&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; MyMethod()&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do something&lt;/font&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;Like link demands, inheritance demands are also applied using declarative syntax only.&lt;/p&gt; &lt;h2&gt;&lt;a name="Requesting Permissions"&gt;Requesting Permissions&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Imagine a situation like this. You have given a nice form to the user with 20+ fields to enter and at the end, all the information would be saved to a text file. The user fills all the necessary fields and when he tries to save, he'll get this nice message saying it doesn't have the necessary permission to create a text file! Of course you can try to calm him down explaining all this happened because of a thing called stack walk .. caused by a demand .. and if you are really lucky you can even get away by blaming Microsoft (believe me ... sometimes it works!).&lt;/p&gt; &lt;p&gt;Wouldn't it be easier if you can request the permissions prior to loading the assembly? Yes you can. There are three ways to do that in Code Access Security.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;RequestMinimum&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;RequestOptional&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;RequestRefuse&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Note that these can only be applied using declarative syntax in the assembly level, and not to methods or classes. The best thing in requesting permissions is that the administrator can view the requested permissions after the assembly has been deployed, using the &lt;i&gt;permview.exe&lt;/i&gt; (Permission View Tool), so what ever the permissions needed can be granted.&lt;/p&gt; &lt;h3&gt;RequestMinimum&lt;/h3&gt; &lt;p&gt;You can use &lt;code&gt;RequestMinimum&lt;/code&gt; to specify the permissions your code &lt;b&gt;must&lt;/b&gt; have in order to run. The code will be only allowed to run if all the required permissions are granted by the security policy. In the following code fragment, a request has been made for permissions to write to a key in the registry. If this is not granted by the security policy, the assembly won't even get loaded. As mentioned above, this kind of request can only be made in the assembly level, declaratively.&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System;&lt;br /&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.Windows.Forms;&lt;br /&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.IO;&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.Security;&lt;br /&gt;&lt;font class="cs-keyword"&gt;using&lt;/font&gt; System.Security.Permissions;&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// placed in assembly level&lt;/font&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// using declarative syntax&lt;/font&gt;&lt;br /&gt;[assembly:RegistryPermission(SecurityAction.RequestMinimum,&lt;br /&gt;Write=&lt;font class="cpp-string"&gt;"HKEY_LOCAL_MACHINE\\Software"&lt;/font&gt;)]&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;namespace&lt;/font&gt; SecurityApp&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// Rest of the implementation&lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;h3&gt;RequestOptional&lt;/h3&gt; &lt;p&gt;Using &lt;code&gt;RequestOptional&lt;/code&gt;, you can specify the permissions your code can use, but &lt;b&gt;not required&lt;/b&gt; in order to run. If somehow your code has not been granted the optional permissions, then you must handle any exceptions that is thrown while code segments that need these optional permissions are being executed. There are certain things to keep in mind when working with &lt;code&gt;RequestOptional&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;If you use &lt;code&gt;RequestOptional&lt;/code&gt; with &lt;code&gt;RequestMinimum&lt;/code&gt;, no other permissions will be granted except these two, if allowed by the security policy. Even if the security policy allows additional permissions to your assembly, they won't be granted. Look at this code segment:&lt;/p&gt;&lt;pre lang="cs"&gt;[assembly:FileIOPermission(SecurityAction.RequestMinimum, Read=&lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;)]&lt;br /&gt;[assembly:FileIOPermission(SecurityAction.RequestOptional, Write=&lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;)]&lt;/pre&gt; &lt;p&gt;The only permissions that this assembly will have are read and write permissions to the file system. What if it needs to show a UI? Then the assembly still gets loaded but an exception will be thrown when the line that shows the UI is executing, because even though the security policy allows &lt;code&gt;UIPermission&lt;/code&gt;, it is not granted to this assembly.&lt;/p&gt; &lt;p&gt;Note that, like &lt;code&gt;RequestMinimum&lt;/code&gt;, &lt;code&gt;RequestOptional&lt;/code&gt; doesn't prevent the assembly from being loaded, but throws an exception at run time if the optional permission has not been granted.&lt;/p&gt; &lt;h3&gt;RequestRefuse&lt;/h3&gt; &lt;p&gt;You can use &lt;code&gt;RequestRefuse&lt;/code&gt; to specify the permissions that you want to ensure will &lt;b&gt;never be granted &lt;/b&gt;to your code, even if they are granted by the security policy. If your code only wants to read files, then refusing write permission would ensure that your code cannot be misused by a malicious attack or a bug to alter files.&lt;/p&gt;&lt;pre lang="cs"&gt;[assembly:FileIOPermission(SecurityAction.RequestRefuse, Write=&lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;)]&lt;/pre&gt; &lt;h2&gt;&lt;a name="Overriding Security"&gt;Overriding Security&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Sometimes you need to override certain security checks. You can do this by altering the behavior of a permission stack walk using these three methods. They are referred to as &lt;i&gt;&lt;b&gt;stack walk modifiers&lt;/b&gt;&lt;/i&gt;.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;Assert&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Deny&lt;/b&gt;  &lt;/li&gt;&lt;li&gt;&lt;b&gt;PermitOnly&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Assert&lt;/h3&gt; &lt;p&gt;You can call the &lt;code&gt;Assert&lt;/code&gt; method to stop the stack walk from going beyond the current stack frame. So the callers above the method that has used &lt;code&gt;Assert&lt;/code&gt; are not checked. If you can trust the upstream callers, then using &lt;code&gt;Assert&lt;/code&gt; would do no harm. You can use the previous example to test this. Modify the code in &lt;code&gt;ShowUI&lt;/code&gt; method, just add the two new lines shown below:&lt;/p&gt;&lt;pre lang="cs"&gt;&lt;font class="cs-keyword"&gt;private&lt;/font&gt; &lt;font class="cs-keyword"&gt;void&lt;/font&gt; ShowUI(&lt;font class="cs-keyword"&gt;int&lt;/font&gt; uino)&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-comment"&gt;// using imperative syntax to create a instance of FileIOPermission&lt;/font&gt;&lt;br /&gt;FileIOPermission myPerm = &lt;font class="cs-keyword"&gt;new&lt;/font&gt;&lt;br /&gt;FileIOPermission(FileIOPermissionAccess.Read, &lt;font class="cpp-string"&gt;"C:\\"&lt;/font&gt;);&lt;br /&gt;myPerm.Assert();    &lt;font class="cs-comment"&gt;// don't check above stack frames.&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-keyword"&gt;switch&lt;/font&gt; (uino)&lt;br /&gt;{&lt;br /&gt;&lt;font class="cs-keyword"&gt;case&lt;/font&gt; &lt;font class="cs-literal"&gt;1&lt;/font&gt;: &lt;font class="cs-comment"&gt;// That's our FileRead UI&lt;/font&gt;&lt;br /&gt; ShowFileReadUI();&lt;br /&gt; &lt;font class="cs-keyword"&gt;break&lt;/font&gt;;&lt;br /&gt;&lt;font class="cs-keyword"&gt;case&lt;/font&gt; &lt;font class="cs-literal"&gt;2&lt;/font&gt;:&lt;br /&gt; &lt;font class="cs-comment"&gt;// Show someother UI&lt;/font&gt;&lt;br /&gt; &lt;font class="cs-keyword"&gt;break&lt;/font&gt;; &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;CodeAccessPermission.RevertAssert();    &lt;font class="cs-comment"&gt;// cancel assert&lt;/font&gt;&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;Make sure that the &lt;code&gt;Deny&lt;/code&gt; statement is still there in &lt;code&gt;InitUI&lt;/code&gt; method. Now run the code. It should be working fine without giving any exceptions. Look at the following figure:&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/StackWalk_3.GIF" height="271" width="331"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 12&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Even though &lt;code&gt;InitUI&lt;/code&gt; doesn't have the demanded permission, it is never checked because the stack walk stops from &lt;code&gt;ShowUI&lt;/code&gt;. Look at the last line. &lt;code&gt;RevertAssert&lt;/code&gt; is a static method of &lt;code&gt;CodeAccessPermission&lt;/code&gt;. It is used after an &lt;code&gt;Assert&lt;/code&gt; to cancel the &lt;code&gt;Assert&lt;/code&gt; statement. So if the code below &lt;code&gt;RevertAssert&lt;/code&gt; is accessing some protected resources, then a normal stack walk would be performed and all callers would be checked. If there's no &lt;code&gt;Assert&lt;/code&gt; for the current stack frame, then &lt;code&gt;RevertAssert&lt;/code&gt; has no effect. It is a good practice to place the &lt;code&gt;RevertAssert&lt;/code&gt; in a &lt;code lang="cs"&gt;&lt;font class="cs-keyword"&gt;finally&lt;/font&gt;&lt;/code&gt; block, so it will always get called.&lt;/p&gt; &lt;p&gt;Note that to use &lt;code&gt;Assert&lt;/code&gt;, the &lt;code&gt;Assertion&lt;/code&gt; flag of the &lt;code&gt;SecurityPermission&lt;/code&gt; should be set.&lt;/p&gt; &lt;p&gt;&lt;b&gt;Warning from Microsoft!&lt;/b&gt;: If asserts are not handled carefully it may lead into luring attacks where malicious code can call our code through trusted code.&lt;/p&gt; &lt;h3&gt;Deny&lt;/h3&gt; &lt;p&gt;We have used this method already in the previous example. The following code sample shows how to deny permission to connect to a restricted website using imperative syntax:&lt;/p&gt;&lt;pre lang="cs"&gt;WebPermission myWebPermission =&lt;br /&gt;&lt;font class="cs-keyword"&gt;new&lt;/font&gt; WebPermission(NetworkAccess.Connect,&lt;br /&gt;&lt;font class="cpp-string"&gt;"http://www.somewebsite.com"&lt;/font&gt;);&lt;br /&gt;myWebPermission.Deny();&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do some work&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;CodeAccessPermission.RevertDeny(); &lt;font class="cs-comment"&gt;// cancel Deny&lt;/font&gt;&lt;/pre&gt; &lt;p&gt;&lt;code&gt;RevertDeny&lt;/code&gt; is used to remove a previous &lt;code&gt;Deny&lt;/code&gt; statement from the current stack frame.&lt;/p&gt; &lt;h3&gt;PermitOnly&lt;/h3&gt; &lt;p&gt;You can use &lt;code&gt;PermitOnly&lt;/code&gt; in some situations when needed to restrict permissions granted by security policy. The following code fragment shows how to use it imperatively. When &lt;code&gt;PermitOnly&lt;/code&gt; is used, it means only the resources you specify can be accessed.&lt;/p&gt;&lt;pre lang="cs"&gt;WebPermission myWebPermission =&lt;br /&gt;&lt;font class="cs-keyword"&gt;new&lt;/font&gt; WebPermission(NetworkAccess.Connect,&lt;br /&gt;&lt;font class="cpp-string"&gt;"http://www.somewebsite.com"&lt;/font&gt;);&lt;br /&gt;myWebPermission.PermitOnly();&lt;br /&gt;&lt;br /&gt;&lt;font class="cs-comment"&gt;// Do some work&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;CodeAccessPermission.PermitOnly(); &lt;font class="cs-comment"&gt;// cancel PermitOnly&lt;/font&gt;&lt;/pre&gt; &lt;p&gt;You can use &lt;code&gt;PermitOnly&lt;/code&gt; instead of &lt;code&gt;Deny&lt;/code&gt; when it is more convenient to describe resources that can be accessed instead of resources that cannot be accessed.&lt;/p&gt; &lt;h2&gt;&lt;a name="Calculating Permissions"&gt;Calculating Permissions&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;In the first example, we configured the machine policy level to set permissions for our code. Now we'll see how those permissions are calculated and granted by the runtime when your code belongs to more than one code group in the same policy level or in different policy levels.&lt;/p&gt; &lt;p&gt;The CLR computes the allowed permission set for an assembly in the following way:&lt;/p&gt; &lt;ol&gt;&lt;li&gt;Starting from the &lt;b&gt;All_Code &lt;/b&gt;code group, all the child groups are searched to determine which groups the code belongs to, using identity information provided by the &lt;b&gt;evidence&lt;/b&gt;. (If the parent group doesn't match, then that group's child groups are not checked.)  &lt;/li&gt;&lt;li&gt;When all matches are identified for a particular policy level, the &lt;b&gt;permissions associated with those groups&lt;/b&gt; are combined in an additive manner (&lt;b&gt;union&lt;/b&gt;).  &lt;/li&gt;&lt;li&gt;This is repeated for each policy level and &lt;b&gt;permissions associated with each policy level are intersected&lt;/b&gt; with each other. &lt;/li&gt;&lt;/ol&gt; &lt;p&gt;So all the permissions associated with matching code groups in one policy level are added together (&lt;b&gt;union&lt;/b&gt;) and the result for each policy level is &lt;b&gt;intersected &lt;/b&gt;with one another. An intersection is used to ensure that policy lower down in the hierarchy cannot add permissions that were not granted by a higher level.&lt;/p&gt; &lt;p&gt;Look at the following figure taken from a MSDN article, to get a better understanding:&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/Grant.gif" height="201" width="241"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 13&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Have a quick look at the &lt;b&gt;All_Code&lt;/b&gt; code group's associated permission set in &lt;code&gt;Machine&lt;/code&gt; policy level. Hope it makes sense by now.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/All_Code.gif" border="0" height="443" width="403"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 14&lt;/b&gt;&lt;/p&gt; &lt;p&gt;The runtime computes the allowed permission set differently if the &lt;code&gt;Exclusive&lt;/code&gt; or &lt;code&gt;LevelFinal&lt;/code&gt; attribute is applied to the code group. If you are not suffering from short term memory loss, you should remember that we set the &lt;code&gt;Exclusive&lt;/code&gt; attribute for our code group - &lt;code&gt;MyCodeGroup&lt;/code&gt; in the earlier &lt;a href="http://www.codeproject.com/dotnet/UB_CAS_NET.asp#Exclusive%20and%20Level%20Final"&gt;example&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Here's what happens if these attributes are set.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;code&gt;Exclusive&lt;/code&gt;&lt;b&gt; -&lt;/b&gt; The permissions with the code group marked as &lt;code&gt;Exclusive&lt;/code&gt; are taken as the only permissions for that policy level. So permissions associated with other code groups are not considered when computing permissions. &lt;/li&gt;&lt;li&gt;&lt;code&gt;LevelFinal&lt;/code&gt;&lt;b&gt; -&lt;/b&gt; &lt;a href="http://www.codeproject.com/dotnet/UB_CAS_NET.asp#policy"&gt;Policy levels&lt;/a&gt; (except the application domain level) below the one containing this code group are not considered when checking code group membership and granting permissions. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Now you should have a clear understanding why we set the &lt;code&gt;Exclusive&lt;/code&gt; attribute earlier.&lt;/p&gt; &lt;h2&gt;&lt;a name="Nice Features in .NET Configuration Tool"&gt;Nice Features in .NET Configuration Tool&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;There are some nice features in &lt;b&gt;.NET Configuration Tool&lt;/b&gt;. Just right click the &lt;b&gt;Runtime Security Policy&lt;/b&gt; node and you'll see what I'm talking about.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/ConfigTool_7.GIF" border="0" height="302" width="434"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 15&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Among other options there are two important ones.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;Evaluate Assembly&lt;/b&gt; - This can be used to find out which code group(s) a particular assembly belongs to, or which permissions it has.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;Create Deployment Package&lt;/b&gt; - This wizard will create a policy deployment package. Just choose the policy level and this wizard will wrap it into a Windows Installer Package (.msi file), so what ever the code groups and permissions in your development PC can be quickly transferred to any other machine without any headache. &lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;&lt;a name="Tools"&gt;Tools&lt;/a&gt;&lt;/h2&gt; &lt;h3&gt;Permissions View Tool - permview.exe&lt;/h3&gt; &lt;p&gt;The Permissions View tool is used to view the minimal, optional, and refused permission sets requested by an assembly. Optionally, you can use &lt;i&gt;permview.exe&lt;/i&gt; to view all declarative security used by an assembly. Please refer to the MSDN documentation for additional information.&lt;/p&gt; &lt;p&gt;Examples:&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;i&gt;permview SecurityApp.exe&lt;/i&gt; - Displays the permissions requested by the assembly &lt;i&gt;SecurityApp.exe&lt;/i&gt;. &lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;Code Access Security Policy Tool - caspol.exe&lt;/h3&gt; &lt;p&gt;The Code Access Security Policy tool enables users and administrators to modify security policy for the machine policy level, the user policy level and the enterprise policy level. Please refer to the MSDN documentation for additional information.&lt;/p&gt; &lt;p&gt;Examples:&lt;/p&gt; &lt;p&gt;Here's the output when you run "&lt;b&gt;caspol -listgroups&lt;/b&gt;", this will list the code groups that belong to the default policy level - Machine level.&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.codeproject.com/dotnet/UB_CAS_NET/Cmd.GIF" border="0" height="365" width="550"&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;Figure 16&lt;/b&gt;&lt;/p&gt; &lt;p&gt;Note that label "&lt;b&gt;1.&lt;/b&gt;" is for &lt;b&gt;All_Code&lt;/b&gt; node because it is the parent node. It's child nodes are labeled as "&lt;b&gt;1.x&lt;/b&gt;", and their child nodes are labeled as "&lt;b&gt;1.x.x&lt;/b&gt;", get the picture?&lt;/p&gt; &lt;ul&gt;&lt;li&gt;&lt;b&gt;caspol -listgroups&lt;/b&gt; - Displays the code groups  &lt;/li&gt;&lt;li&gt;&lt;b&gt;caspol -machine -addgroup 1. -zone Internet Execution&lt;/b&gt; - Adds a child code group to the root of the machine policy code group hierarchy. The new code group is a member of the &lt;b&gt;Internet&lt;/b&gt; zone and is associated with the &lt;b&gt;Execution&lt;/b&gt; permission set.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;caspol -user -chggroup 1.2. Execution&lt;/b&gt; - Changes the permission set in the user policy of the code group labeled 1.2. to the &lt;b&gt;Execution&lt;/b&gt; permission set.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;caspol -security on&lt;/b&gt; - Turns code access security on.  &lt;/li&gt;&lt;li&gt;&lt;b&gt;caspol -security off&lt;/b&gt; - Turns code access security off. &lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;&lt;a name="Summary"&gt;Summary&lt;/a&gt;&lt;/h2&gt; &lt;ul&gt;&lt;li&gt;Using .NET Code Access Security, you can restrict what your code can do, restrict which code can call your code and identify code. &lt;/li&gt;&lt;li&gt;There are four policy levels - &lt;code&gt;Enterprise&lt;/code&gt;, &lt;code&gt;Machine&lt;/code&gt;, &lt;code&gt;User&lt;/code&gt; and &lt;code&gt;Application Domain&lt;/code&gt; which contains code groups with associated permissions.  &lt;/li&gt;&lt;li&gt;Can use declarative syntax or imperative syntax.  &lt;/li&gt;&lt;li&gt;Demands can be used to ensure that every caller has the demanded permission.  &lt;/li&gt;&lt;li&gt;Requests can be used to request (or refuse) permissions in the grant time.  &lt;/li&gt;&lt;li&gt;Granted permissions can be overridden. &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;That's it.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;I suggest that you go through the whole article one more time, just to make sure you didn't miss anything. If it's still not clear, don't worry, it's not your fault, it's my fault. :)&lt;/p&gt; &lt;p&gt;Happy Coding !!!&lt;/p&gt;&lt;/font&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-1391409529019329457?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/1391409529019329457/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=1391409529019329457' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1391409529019329457'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/1391409529019329457'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/06/understanding-net-code-access-security.html' title='Understanding .NET Code Access Security'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-8954493460669894635</id><published>2007-01-07T11:57:00.000+05:30</published><updated>2007-01-07T11:59:58.062+05:30</updated><title type='text'>Walkthrough Crystal Report</title><content type='html'>&lt;strong&gt;How To: Create a Crystal Report from ADO.NET Dataset using Visual Basic .NET&lt;br /&gt;Introduction:&lt;br /&gt;&lt;/strong&gt;Crystal Report of Visual Studio .NET is the standard reporting tool for Visual Studio .NET. You can host reports on web and windows platform and can publish reports as Report Web services on the web server. It is based on framework of Crystal Report 8.0 and uses open and flexible architecture, with standards like XML, to allow porting reports over the web. Using crystal report expert you can choose report layouts, display charts, calculate summaries, subtotals as grouped data as well as conditionally format text and rotate text objects.&lt;br /&gt;Although Crystal Reports for Visual Studio .NET supports variety of data source like ADO recordset, CDO recordset, DAO recordset, MS Excel workbook, this walkthrough endeavor to explain How to report off ADO.NET DataSet using Visual Basic .NET.&lt;br /&gt;As you all know DataSet is the core component of distributed application and is explicitly designed for data access independent of any data source. Dataset can be created from variety of sources. Whatever the source is, before reporting off ADO.NET DataSet you must perform the following task:&lt;br /&gt;Ø       Generate an object for the DataSet.&lt;br /&gt;Ø       Connect report to DataSet Object.&lt;br /&gt;Ø       Push data into DataSet Object.&lt;br /&gt;Ø       Bind report to Windows Forms Viewer to display report with actual data at runtime.&lt;br /&gt;Requirements:&lt;br /&gt;ü       Visual Studio .NET 2002&lt;br /&gt;ü       .NET Framework 1.0&lt;br /&gt;ü       SQL Server 2000 with Northwind database&lt;br /&gt;&lt;br /&gt;Generating an Object for the DataSet&lt;br /&gt;Object for ADO.NET is a collection of dataset classes created in memory.&lt;br /&gt;To create a dataset object from Northwind database in SQL Server, using ADO.NET DataSet Designer.&lt;br /&gt;In the Solution Explorer, right-click the project name, point to Add, and click Add New Item.&lt;br /&gt;In the Categories area of the Add New Item dialog box, expand the folder and select Data.&lt;br /&gt;In the Templates area, select Dataset.&lt;br /&gt;Accept the default name Dataset1.xsd.&lt;br /&gt;This creates a new schema file that will be used to generate a strongly typed dataset. The schema file will be displayed in ADO.NET Dataset designer.&lt;br /&gt;In the Solutions Explorer, click on Dataset1.xsd file, if now already the active view.&lt;br /&gt;From the Server Explore, on the right connect to SQL Server and drill down to Northwind Database.&lt;br /&gt;Highlight the Table Customers (or stored procedure if desired) and drag and drop it on the Interface of Dataset1.xsd. Dataset1.xsd should now be displayed in the Dataset tab as under&lt;br /&gt;This creates a dataset object and contains only a description of the database based on the schema in Dataset1.xsd. It does not contain the actual data.  &lt;br /&gt;&lt;br /&gt;&lt;a name="crtskconnectingtoanado.netdatasetobject"&gt;&lt;/a&gt;Connecting Report to an ADO.NET Dataset Object&lt;br /&gt;From ADO.NET Dataset Object you can add tables to Crystal Report using Database Expert in Crystal Report Designer.&lt;br /&gt;To create a new report and connect it to Dataset object which contains description for Customers table in Northwind database&lt;br /&gt;In the Visual Studio .NET Solution Explorer, right-click your project to display the shortcut menu.&lt;br /&gt;Point to Add and click Add New Item.&lt;br /&gt;In the Add New Item dialog box, select Crystal Report from the Templates area. Click Open.&lt;br /&gt;Crystal Report Gallery will be displayed, as shown below&lt;br /&gt;You can choose from any of the options provided in Crystal Report Gallery. But for the purpose of this walkthrough choose As a Blank Report and click OK.&lt;br /&gt;On File menu, click Save to save the report.&lt;br /&gt;Right click in the Report Designer, point to Database, and click Add/Remove Database.&lt;br /&gt;You’ll be presented with Database Expert wizard.&lt;br /&gt;In the Database Expert wizard, expand the Project Data folder, expand the ADO.NET Datasets folder and select the dataset object as shown below&lt;br /&gt;If you now drill down Database Fields node, in the Field Explorer, you can view Customers table and all its fields&lt;br /&gt;Drag and drop the fields onto the report and format them as required.&lt;br /&gt;Pushing data into DataSet object and binding report to Windows Forms Viewer&lt;br /&gt;In order to display actual data in the report, you should fill the dataset object with the data before you bind the report to Windows Forms Viewer. You should do this in the corresponding source file for Windows Form.&lt;br /&gt;Drag and drop CrystalReportViewer control on Form1 and set the DisplayGroupTree property to False, as shown below&lt;br /&gt;Accept the default name as CrystalReportViewer1.&lt;br /&gt;Open Form1 code editor and add the following code on Load event of Form1.&lt;br /&gt;Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load&lt;br /&gt;        Dim rpt As New CrystalReport1() 'The report you created.&lt;br /&gt;        Dim myConnection As SqlConnection&lt;br /&gt;        Dim MyCommand As New SqlCommand()&lt;br /&gt;        Dim myDA As New SqlDataAdapter()&lt;br /&gt;        Dim myDS As New Dataset1() 'The DataSet you created.&lt;br /&gt;&lt;br /&gt;        Try&lt;br /&gt;&lt;br /&gt;            myConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" &amp; _&lt;br /&gt;                                             "Initial Catalog=northwind;")&lt;br /&gt;            MyCommand.Connection = myConnection&lt;br /&gt;            MyCommand.CommandText = "SELECT * FROM Customers"&lt;br /&gt;            MyCommand.CommandType = CommandType.Text&lt;br /&gt;            myDA.SelectCommand = MyCommand&lt;br /&gt;&lt;br /&gt;            myDA.Fill(myDS, "Customers")&lt;br /&gt;            rpt.SetDataSource(myDS)&lt;br /&gt;            CrystalReportViewer1.ReportSource = rpt&lt;br /&gt;&lt;br /&gt;        Catch Excep As Exception&lt;br /&gt;            MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)&lt;br /&gt;        End Try&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Troubleshooting&lt;br /&gt;Add reference to SqlClient namespace. Imports System.Data.SqlClient&lt;br /&gt;Check connection to your server.&lt;br /&gt;References&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlmn/html/crconincorporatingreportsintoapplications.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/crystlmn/html/crconincorporatingreportsintoapplications.asp&lt;/a&gt;&lt;br /&gt;Happy programming!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-8954493460669894635?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/8954493460669894635/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=8954493460669894635' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/8954493460669894635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/8954493460669894635'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/01/walkthrough-crystal-report.html' title='Walkthrough Crystal Report'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4351333993867117809.post-69856975086190121</id><published>2007-01-07T11:47:00.000+05:30</published><updated>2007-01-07T11:53:04.195+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='important-links'/><title type='text'>Web Technology links</title><content type='html'>http://support.businessobjects.com/communityCS/TechnicalPapers/cr10_UserGde_en.zip.asp&lt;br /&gt;http://www.codeproject.com/aspnet/NonTypedCrystalReport.asp&lt;br /&gt;&lt;br /&gt;http://www.codeproject.com/aspnet/crystal_report.asp?df=100&amp;forumid=14950&amp;exp=0&amp;select=906105&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;RegularExpressions&lt;/strong&gt;&lt;br /&gt;http://www.4guysfromrolla.com/webtech/RegularExpressions.shtml&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Passing Parameters from One Page to Another&lt;/strong&gt; &lt;br /&gt;http://aspnet.4guysfromrolla.com/articles/020205-1.aspx&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;AJAX&lt;/strong&gt;&lt;br /&gt;http://www.w3schools.com/ajax/default.asp&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4351333993867117809-69856975086190121?l=nkp-servitium.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nkp-servitium.blogspot.com/feeds/69856975086190121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4351333993867117809&amp;postID=69856975086190121' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/69856975086190121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4351333993867117809/posts/default/69856975086190121'/><link rel='alternate' type='text/html' href='http://nkp-servitium.blogspot.com/2007/01/web-technology-links.html' title='Web Technology links'/><author><name>New Reader</name><uri>http://www.blogger.com/profile/03124895393639952070</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://bp2.blogger.com/_c83J-PNKWTc/R2Yf8OTy5II/AAAAAAAAAbY/RZK35iFkea4/S220/19022007172.jpg'/></author><thr:total>0</thr:total></entry></feed>
