<?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-8280997523505047385</id><updated>2011-11-27T15:58:58.368-08:00</updated><category term='Beware from Adulteration'/><title type='text'>________________MayankNagar</title><subtitle type='html'>Just do it !</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-5628097645873395577</id><published>2009-07-13T05:38:00.000-07:00</published><updated>2009-07-13T05:39:41.819-07:00</updated><title type='text'>Silverligth 2 Code Samples</title><content type='html'>&lt;iframe scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:240px;height:66px;margin:3px;padding:0;border:1px solid #dde5e9;background-color:#ffffff;" src="http://cid-5a66c3bd6973893f.skydrive.live.com/embedrowdetail.aspx/Code/Pro%20Silverlight%202%20in%20C%7C3.zip"&gt;&lt;/iframe&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-5628097645873395577?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/5628097645873395577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=5628097645873395577' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/5628097645873395577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/5628097645873395577'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/07/silverligth-2-code-samples.html' title='Silverligth 2 Code Samples'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-427728088159877987</id><published>2009-07-07T04:08:00.000-07:00</published><updated>2009-07-07T04:13:29.532-07:00</updated><title type='text'>HttpWebRequest &amp; WebRequest in WebServices</title><content type='html'>protected void btnWebRequest_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;//string xmlfile;&lt;br /&gt;//xmlfile = Request.Params["xmlfile"];&lt;br /&gt;//if (xmlfile == null)&lt;br /&gt;// xmlfile = "uddi.xml";&lt;br /&gt;//HttpSOAPRequest(xmlfile, null);&lt;br /&gt;//string xmlfile = "uddi.xml";&lt;br /&gt;string xmlfile = "myRequest.xml";&lt;br /&gt;&lt;br /&gt;HttpSOAPRequest(xmlfile, null);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void HttpSOAPRequest(String xmlfile, string proxy)&lt;br /&gt;{&lt;br /&gt;XmlDocument doc = new XmlDocument();&lt;br /&gt;doc.Load(@"D:\Applications\FridViewManipulation\" + xmlfile);&lt;br /&gt;// HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://uddi.microsoft.com/inquire");&lt;br /&gt;HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:1709/FridViewManipulation/WebService.asmx");&lt;br /&gt;if (proxy != null) req.Proxy = new WebProxy(proxy, true);&lt;br /&gt;// if SOAPAction header is required, add it here...&lt;br /&gt;//req.Headers.Add("SOAPAction", "\"\"");&lt;br /&gt;req.Headers.Add("SOAPAction", "http://tempuri.org/Identify");&lt;br /&gt;req.ContentType = "text/xml;charset=\"utf-8\"";&lt;br /&gt;req.Accept = "text/xml";&lt;br /&gt;req.Method = "POST";&lt;br /&gt;Stream stm = req.GetRequestStream();&lt;br /&gt;doc.Save(stm);&lt;br /&gt;stm.Close();&lt;br /&gt;WebResponse resp = req.GetResponse();&lt;br /&gt;stm = resp.GetResponseStream();&lt;br /&gt;StreamReader r = new StreamReader(stm);&lt;br /&gt;// process SOAP return doc here. For now, we'll just send the XML out to the browser ...&lt;br /&gt;// Response.Write(r.ReadToEnd());&lt;br /&gt;dvResponse.InnerHtml = r.ReadToEnd();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;myRequest.xml&lt;/u&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;?xml:namespace prefix = soap /&gt;&lt;soap:envelope xsi="http://www.w3.org/2001/XMLSchema-instance" xsd="http://www.w3.org/2001/XMLSchema" soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;br /&gt;&lt;soap:body&gt;&lt;br /&gt;&lt;?XML:NAMESPACE PREFIX = [default] http://tempuri.org/ NS = "http://tempuri.org/" /&gt;&lt;identify xmlns="http://tempuri.org/"&gt;&lt;br /&gt;&lt;name&gt;Mayank&lt;/name&gt;&lt;br /&gt;&lt;/identify&gt;&lt;br /&gt;&lt;/soap:body&gt;&lt;br /&gt;&lt;/soap:envelope&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-427728088159877987?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/427728088159877987/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=427728088159877987' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/427728088159877987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/427728088159877987'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/07/httpwebrequest-webrequest-in.html' title='HttpWebRequest &amp; WebRequest in WebServices'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-305584857998367901</id><published>2009-06-16T04:57:00.000-07:00</published><updated>2009-06-16T05:00:39.338-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Beware from Adulteration'/><title type='text'>Test to Find Adulteration in Milk, Ghee etc.</title><content type='html'>Important Tests&lt;br /&gt;========================&lt;br /&gt;Test for detection of urea in Milk&lt;br /&gt;&lt;br /&gt;1. Urea is generally added in the preparation of synthetic milk to raise the SNF value. &lt;br /&gt;&lt;br /&gt;Five ml of milk is mixed well with 5 ml paradimethyl amino benzaldehyde (16%). If the solution turns yellow in colour, then the given sample of milk is added with urea.&lt;br /&gt;&lt;br /&gt;2. Take 5 ml of milk in a test tube and add 0.2 ml of urease (20 mg / ml). Shake well at room temperature and then add 0.1 ml of bromothymol blue solution (0.5%). Appearance of blue colour after 10-15 min indicates the adulteration milk with urea.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test for detection of starch&lt;br /&gt;&lt;br /&gt;Addition of starch also increases the SNF content of milk. Apart from the starch, wheat flour, arrowroot, rice flour are also added. &lt;br /&gt;&lt;br /&gt;How to detect?&lt;br /&gt;&lt;br /&gt;Take 3 ml milk in a test tube and boil it thoroughly. Then milk is cooled to room temperature and added with 2 to 3 drops of 1% iodine solution. Change of colour to blue indicates that the milk is adulterated with starch.&lt;br /&gt;&lt;br /&gt;Test for detection of formalin&lt;br /&gt;&lt;br /&gt;Formalin (40%) is poisonous though it can preserve milk for a long time.&lt;br /&gt;How to detect?&lt;br /&gt;&lt;br /&gt;Take 10 ml of milk in test tube and 5 ml of conc. sulphuric acid is added on the sides of the test tube with out shaking. If a violet or blue ring appears at the intersection of the two layers, then it shows the presence of formalin.&lt;br /&gt;&lt;br /&gt;Detection of Neutralizers in milk&lt;br /&gt;&lt;br /&gt;1) Rosalic acid test (Soda Test)&lt;br /&gt;&lt;br /&gt;In milk neutralizers like hydrated lime, sodium hydroxide, sodium carbonate or sodium bicarbonate are added which are generally prohibited. &lt;br /&gt;&lt;br /&gt;How to detect?&lt;br /&gt;&lt;br /&gt;Take 5 ml of milk in a test tube and add 5 ml alcohol followed by 4-5 drops of rosalic acid. If the colour of milk changes to pinkish red, then it is inferred that the milk is adulterated with sodium carbonate / sodium bicarbonate and hence unfit for human consumption. &lt;br /&gt;&lt;br /&gt;This test will be effective only if the neutralizers are present in milk. If the added neutralizers are nullified by the developed acidity, then this test will be negative. In that case, the alkaline condition of the milk for the presence of soda ash has to be estimated.&lt;br /&gt;&lt;br /&gt;How to proceed?&lt;br /&gt;&lt;br /&gt;2) Take 20 ml of milk in a silica crucible and then the water is evaporated and the contents are burnt in a muffle furnace. The ash is dispersed in 10 ml distilled water and it is titrated against decinormal (N/10) hydrochloric acid using phenolphthalein as an indicator. If the titre value exceeds 1.2 ml, then it is construed that the milk is adulterated with neutralizers. &lt;br /&gt;&lt;br /&gt;==========================================================================================&lt;br /&gt;&lt;br /&gt;Tests to detect adulteration in ghee&lt;br /&gt;&lt;br /&gt;1. Butyrorefractometer reading&lt;br /&gt;&lt;br /&gt;Properly filtered ghee whose temperature is around 40°C is taken; 2-3 drops of it are poured in to the butyrorefractometer by the side of the glass rod. Now the reading is noted by the scale placed above the meter. Care has to be exercised to maintain the temperature of water that is flowing over the thermometer to be at 40°C. If the temperature deviates, then the results obtained may not be accurate.      &lt;br /&gt;&lt;br /&gt;2. Baudoin Test (Detection of adulteration of ghee with vanaspathi)&lt;br /&gt;&lt;br /&gt;As per the prevention of food adulteration act, it has been made mandatory to add 5% sesame oil to vanaspathi in order to detect the presence of vanaspathi in ghee through Baudoin test. The principle behind the test is development of permanent crimson red colour with furfural in the presence of concentrated hydrochloric acid in ghee adulterated with vanaspathi.&lt;br /&gt;&lt;br /&gt;How to detect?&lt;br /&gt;&lt;br /&gt;Take 5 g of molten filtered ghee in a test tube and add 5 ml of concentrated hydrochloric acid and 0.1 ml furfural solution in alcohol (2%) and mix the contents thoroughly and it is allowed to remain undisturbed for 10 min. Development of crimson red colour shows that the ghee is adulterated with vanaspathi. &lt;br /&gt;&lt;br /&gt;3. Detection of mineral oil in ghee&lt;br /&gt;&lt;br /&gt;About 2 g of ghee is saponified with 25 ml of 50% alcoholic potassium hydroxide for one hour. Then the saponified content is transferred to a beaker containing 100 ml of water. Development of turbidity indicates the adulteration of mineral oil in ghee.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-305584857998367901?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/305584857998367901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=305584857998367901' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/305584857998367901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/305584857998367901'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/06/test-to-find-adulteration-in-milk-ghee.html' title='Test to Find Adulteration in Milk, Ghee etc.'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-447962084096814648</id><published>2009-05-15T05:10:00.000-07:00</published><updated>2009-05-15T05:29:12.975-07:00</updated><title type='text'>Endless Race to get Everything for Nothing !</title><content type='html'>Once I have read from some book that "Don't desire, desires are like fires"&lt;br /&gt;These are not just words but they have a hidden message inside them.&lt;br /&gt;As fire burns something whatever it takes, similarly Desire burns our conscience, consciousness, truthfulness, loyalty, morality, peace of mind... and the list is endless... it completely overcome our freedom of life and we became slaves, who works on the order of their master (will), and we works like machines.&lt;br /&gt;And above all we forgot the goal of our life i.e. to achieve a state where we can  live  full consciousness.&lt;br /&gt;&lt;br /&gt;....To be Continued....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-447962084096814648?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/447962084096814648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=447962084096814648' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/447962084096814648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/447962084096814648'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/05/endless-race-to-get-everything-for.html' title='Endless Race to get Everything for Nothing !'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-2222205267266815605</id><published>2009-04-03T05:17:00.001-07:00</published><updated>2009-04-03T05:31:29.596-07:00</updated><title type='text'>Job Loss ? 5 ways to recession proof your job.</title><content type='html'>1. Save Money:&lt;br /&gt;It is the only and the best way to survive in worst time like this, so try to save your money and make 20% investment in short term investments so that in need you can liquidate you money quickly and rest 80% in long term investment be careful while investing because invest the big chunk in government sponsered schemes only eg. fixed diposits, mutual funds etc. otherwise in times like this value of you money will be much less then you have invested.&lt;br /&gt;&lt;br /&gt;2. Break your credit card into multiple pieces, throw away your credit card in to dust bin and call your bank account customer care executive to close account, becouse credit card could make our life worst due to compoudedness of its interest.&lt;br /&gt;3.Get away from Loans.&lt;br /&gt;4. Buy all goods you use at a time for 1 month or year so that you can get discount.&lt;br /&gt;5. Keep contant track and look at your budget.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-2222205267266815605?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/2222205267266815605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=2222205267266815605' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/2222205267266815605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/2222205267266815605'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/04/job-loss-5-ways-to-recession-proof-your.html' title='Job Loss ? 5 ways to recession proof your job.'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-2308993456061006916</id><published>2009-01-18T21:20:00.001-08:00</published><updated>2009-01-18T21:23:05.616-08:00</updated><title type='text'>Encrypting and Decrypting connection strings in web.config</title><content type='html'>&lt;table class="BlogBorderGreen" cellpadding="0" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;table class="BlogsHeader" cellpadding="3" cellspacing="0" width="100%"&gt;&lt;tbody&gt;&lt;tr&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;table style="width: 146px; height: 4px;" cellpadding="3" cellspacing="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="1"&gt; &lt;table style="width: 36px; height: 18px;" bgcolor="aliceblue" border="0" cellpadding="0" cellspacing="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td class="NormalText" align="left" width="25%"&gt; &lt;/td&gt;  &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt; &lt;table cellpadding="3" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td class="NormalText"&gt; &lt;div id="div2"&gt;&lt;span id="ctl00_ContentPlaceHolder1_BlogDetail1_LabelBlogDetail"&gt; &lt;p&gt;In an ASP.NET website or web application, connection string for connection to  a database server are stored in web.config file. It becomes easy to manage and  access the connection strings from a central file accessible to all ASP.NET  pages. But the security and privacy of the connection strings are higly  important. It is a good idea to protect the connection strings in web.config by  encrypting them. ASP.NET gives a built in way to do this. We can use  RSAProtectedConfigurationProvider to encrypt the connection strings using User  Level Key and Machine Level Key. User Level Key is used when you are running  your application on a shared server and Machine Level Key is used when you are  running your application on dedicated server. In this article we will see how to  encrypt using Machine Level Key. In the web.config following is the section  having all connection string: &lt;/p&gt; &lt;p&gt;&lt;connectionstrings&gt;&lt;/p&gt; &lt;p&gt;&lt;add connectionstring="Initial Catalog=myDB; Data source=(loca);Integrated  security=SSPI;" name="conString1"&gt;&lt;/p&gt; &lt;p&gt;&lt;/connectionstrings&gt;&lt;/p&gt; &lt;p&gt;After storing all connection strings, go to the Visual Studio 2005 Command  Prompt.&lt;br /&gt;(Start-&gt;Programs-&gt;Microsoft Visual Studio 2005-&gt;Visual  Studio 2005 Tools-&gt;Command Prompt) &lt;/p&gt; &lt;p&gt;There write this command on command prompt: &lt;/p&gt; &lt;p&gt;aspnet_regiis -pef "connectionStrings" "c:\myProjects\website1" &lt;/p&gt; &lt;p&gt;Where the "c:\myProjects\website1" is the physical path of your website.  Review the web.config after this. You will find it encrypted. &lt;/p&gt; &lt;p&gt;Later on you can access this connection string as normal way in your pages:  &lt;/p&gt; &lt;p&gt;[VB.NET]&lt;br /&gt;ConfigurationManager.ConnectionStrings("conString1").ConnectionString  &lt;/p&gt; &lt;p&gt;[C#.NET]&lt;br /&gt;ConfigurationManager.ConnectionStrings["conString1"].ConnectionString  &lt;/p&gt; &lt;p&gt;To revert the web.config connection strings back to plain text: &lt;/p&gt; &lt;p&gt;aspnet_regiis -pdf "connectionStrings" "c:\myProjects\website1"  &lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-2308993456061006916?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/2308993456061006916/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=2308993456061006916' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/2308993456061006916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/2308993456061006916'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/01/encrypting-and-decrypting-connection.html' title='Encrypting and Decrypting connection strings in web.config'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-6750479991753837418</id><published>2009-01-18T20:15:00.000-08:00</published><updated>2009-01-18T20:16:05.224-08:00</updated><title type='text'>Microsoft Silverlight 2</title><content type='html'>&lt;span id="ctl00_ContentPlaceHolder1_BlogDetail1_LabelBlogDetail"&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; text-align: center;" align="left"&gt;&lt;b style=""&gt;&lt;span style="font-size: 14pt; font-family: 'Times New Roman','serif';"&gt;&lt;span style="font-size:100%;color:#ff0000;"&gt;From Microsoft website available to  public&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; text-align: center;" align="left"&gt;&lt;b style=""&gt;&lt;span style="font-size: 14pt; font-family: 'Times New Roman','serif';"&gt; &lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; text-align: center;" align="center"&gt;&lt;b style=""&gt;&lt;span style="font-size: 14pt; font-family: 'Times New Roman','serif';"&gt;Microsoft  Silverlight 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal; text-align: center;" align="center"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Fact  Sheet&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpMiddle" style="line-height: normal; text-align: center;" align="center"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;October  2008&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpMiddle" style="line-height: normal;"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;A New Way to See  the Web&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpMiddle" style="line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Over the past  year Microsoft Silverlight has led the way for developers and designers to  create compelling media experiences and rich Internet applications (RIAs) on the  Web via an easy-to-use, quickly installed browser plug-in. With the release of  &lt;span style="color: black;"&gt;Silverlight 2, Microsoft Corp. is delivering a wide  range of new platform features and tooling options that enable designers and  developers to better collaborate while creating more accessible, more  discoverable and more secure end-user experiences.&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpMiddle" style="line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpMiddle" style="line-height: normal;"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Silverlight  Momentum&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 10pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; color: black; font-family: 'Times New Roman','serif';"&gt;Silverlight  is&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;  one of the fastest-growing browser plug-ins in history, both in terms of  customer adoption and consumer installations. In 2008, Silverlight powered the  2008 Beijing Olympic Games (&lt;/span&gt;&lt;a href="http://www.microsoft.com/presspass/presskits/ms-olympics/default.mspx"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;span style="color:#0000ff;"&gt;http://www.microsoft.com/presspass/presskits/ms-olympics/default.mspx&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;) and the  Democratic National Convention (&lt;/span&gt;&lt;a href="http://www.demconvention.com/"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;span style="color:#0000ff;"&gt;http://www.demconvention.com&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;). In addition,  companies such as CBS College Sports Network, Blockbuster Inc., AOL LLC, Hard  Rock Cafe International Inc., HSN Inc. and Toyota Motor Corp. are using  Silverlight to provide a unique and dynamic Web experience for their customers.  Silverlight has also been widely adopted throughout the developer and designer  community by means of the Silverlight Partner Initiative. &lt;span style=""&gt;With more than 150 companies in the program  — 120 of which have joined in the past year — it is a vibrant ecosystem of  agency, solution provider, content delivery network, independent software vendor  and independent hardware vendor partners, which are delivering some of the most  innovative Silverlight experiences on the Web today. Finally, consumer  installations of the Silverlight plug-in are growing rapidly, with penetration  in some countries approaching 50 percent.&lt;/span&gt;&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Openness and  Interoperability Support&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Proving its  commitment to openness and its support for interoperability, Microsoft is  funding a project to integrate advanced Silverlight development capabilities  into the open-source Eclipse integrated development environment (IDE), will  publish the Silverlight Extensible Application Markup Language (XAML) Vocabulary  Specification, and will make the Silverlight Control Pack available as open  source software.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;“We &lt;span style=""&gt;have been&lt;/span&gt;&lt;span style="color: rgb(99, 36, 35);"&gt;  &lt;/span&gt;very pleased to have a project proposed to create Eclipse tools for  Microsoft Silverlight,” said Mike Milinkovich, executive director of the Eclipse  Foundation. “This proposed project will provide Eclipse developers with the  ability to leverage Silverlight and Java Web Services when developing rich  Internet applications. Having a strong endorsement from Microsoft for this  project is a clear sign of their support for Eclipse and open source  communities.”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraphCxSpFirst" style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;The Eclipse  Tools for Microsoft Silverlight Project&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; will integrate  advanced Silverlight development capabilities into the Eclipse IDE and Eclipse  Rich Client Platform. Developed by France-based IT solution provider Soyatec,  the project is funded by Microsoft.&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Increased  interoperability.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; Eclipse will  contain functionality that will help Java developers build Silverlight  applications that work better with Java Web Services using representational  state transfer (REST), Simple Object Access Protocol (SOAP), JavaScript Object  Notation (JSON) and other standards.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Silverlight  Project System and Silverlight Compiler.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;  Eclipse will contain both an advanced project system for creating Silverlight  applications and media experiences and a compiler for packaging Silverlight  applications for deployment.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;XAML  editor and preview with code hinting and code completion.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;  Eclipse will contain an advanced, standards-compliant XAML editor with code  hinting and code completion, which helps detect and correct coding  errors.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Full  compatibility with Microsoft’s development and design tools.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;  The XAML and Silverlight projects created by Eclipse will be fully supported by  both Microsoft Visual Studio and Microsoft Expression Studio  tools.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Results.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; See the picture  below for a glimpse of a Silverlight application being created in  Eclipse.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Availability.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; A preview of  the bits was posted today at &lt;/span&gt;&lt;a href="http://www.eclipse4sl.org/"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;http://www.eclipse4sl.org&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; under the  Eclipse Public License Version 1.0. Customers can use the SourceForge project  site to submit bugs and feedback or contribute to the project. The release  candidate is scheduled to be available free for download by spring  2009.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Road  map.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; Although the  first version of the Eclipse Tools for Microsoft Silverlight will be optimized  for the Windows version of Eclipse, the project plans to offer full support for  the Mac and Linux versions of Eclipse in a later release.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;By publishing  the&lt;b style=""&gt; Silverlight XAML Vocabulary  Specification&lt;/b&gt; under the Open Specification Promise, Microsoft will better  enable ISVs to read and write XAML for use in Silverlight projects in other  design and development software applications, thus accelerating the creation of  a robust authoring and server ecosystem for Silverlight. This documentation  release complements Microsoft’s existing published specifications of the XAML  object mapping rules and XAML vocabulary for Windows Presentation Foundation  (WPF).&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;By making the &lt;b style=""&gt;Silverlight Control Pack&lt;/b&gt; available as  open-source software, which is built on CodePlex and released under the Open  Source Initiative-approved Microsoft Public License (MS-PL), Microsoft is  helping developers easily customize and ship their own expanded controls,  augmenting the powerful built-in control set that already ships in  Silverlight.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Featured  controls in the Control Pack.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; DockPanel,  WrapPanel, ViewBox, Label, HeaderedContentControl, Expander, TreeView,  NumericUpDown, AutoComplete and Accordion are available.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Advanced  skinning support.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; The Silverlight  Control Pack will provide additional control skins and templates to customize  the look and feel of both the core Silverlight and Control Pack  controls.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Learning  opportunity.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; Developers can  learn how to create their own advanced Silverlight controls by using  high-quality Microsoft source code as a starting point.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style="font-size: 12pt; color: black; font-family: 'Times New Roman','serif';"&gt;Growing  tooling support from partner ecosystem.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; color: black; font-family: 'Times New Roman','serif';"&gt;  &lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Tool support for  building Silverlight-enabled applications continues to grow, with partners such  as Captaris Inc., Telerik Inc., ComponentOne LLC, Infragistics, Software FX  Inc., Intersoft Solutions Corp., Developer Express Inc., K2, Gizmox and  RemObjects Software LLC providing products ranging from forms layout and rich  interactive components to workflow, programming languages and business  intelligence.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal" style="margin: 6pt 0in 0pt 0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;“Microsoft is  thrilled to see the momentum building around tooling support from our partners,”  said Scott Guthrie, corporate vice president of the .NET Developer Division at  Microsoft. “The breadth of these partner offerings enables Silverlight  developers to build evermore sophisticated and capable applications, further  broadening the appeal of Silverlight for use in a wide range of  scenarios.”&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNoSpacing" style="margin: 0in 0in 0pt 0.5in;"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpFirst" style="line-height: normal;"&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;New Features in  Silverlight 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt; &lt;p class="MsoNormalCxSpLast" style="margin: auto auto 0pt; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Highlights of  new features of Silverlight — which are fully supported by Expression Blend 2  SP1 and Microsoft Visual Studio 2008 SP1 — include these:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Expanded .NET  Framework language support.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; Unlike other  runtimes, Silverlight 2 supports a variety of programming languages, including  Visual Basic, C#, Managed JavaScript, IronPython and IronRuby, making it easier  for developers already familiar with one of these languages to repurpose their  existing skills.&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Cutting-edge RIA  development.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; With  Silverlight 2, developers do not have to pay the “productivity tax” of  converting their existing code to JavaScript to run inside the client. With  support for languages such as Ruby and Python, Silverlight 2 enables developers  to be on the cutting edge of RIA development, creating Asynchronous Ruby and XML  (ARAX) and Asynchronous Python and XML (APAX)  applications.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;A rich base  class library.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; A compatible  subset of the full .NET Framework gives developers the most comprehensive RIA  runtime on the Web today, with unparalleled data access capabilities, local data  caching and local data storage, superior input-output (IO) performance, and  better threading. By leveraging the rich base class library of the .NET  Framework, developers can minimize the amount of additional code they have to  write for their projects.&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Building better  AJAX applications.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; Silverlight 2  includes APIs that enable the creation of better asynchronous JavaScript and XML  (AJAX) applications, with improved HTML DOM/JavaScript integration with .NET  code and with better data access through Language-Integrated Query (LINQ) and  LINQ to XML library support.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Powerful  built-in rich controls&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; allow  developers and designers to quickly build applications through a rich set of  built-in controls such as DataGrid, ListBox, Slider, ScrollViewer and Calendar.  With the rich controls built into Silverlight 2, developers don’t have to start  from scratch when building the controls for their rich Internet  applications.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Advanced styling  and templating support&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; gives designers  and developers complete control over the look and feel of an application&lt;b style=""&gt; &lt;/b&gt;to ensure the custom brand experience  for their rich Internet application meets their exacting  requirements.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Rich UI Library.  &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Silverlight 2’s  UI Library&lt;span class="MsoCommentReference"&gt;&lt;span style=""&gt;, &lt;/span&gt;&lt;/span&gt;a  compatible subset of the WPF user interface framework featured&lt;b style=""&gt; &lt;/b&gt;in the full .NET Framework, makes  building rich Web applications easier. The powerful graphics and animation  engine enables developers to reuse skills, code and content to build rich  applications for the browser that can be rapidly ported to the desktop and  devices.&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Better support  for higher-level UI capabilities. &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;The UI Framework  in Silverlight contains support for higher-level UI capabilities such as layout  management, data-binding, styles and template skinning.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Comprehensive  networking support &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;enables  Silverlight users to leverage the power of the .NET Framework’s Windows  Communication Foundation and directly access resources on the Web by supporting  cross-domain network access.&lt;b style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 12pt; font-family: 'Courier New';"&gt;&lt;span style=""&gt;­&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Out-of-the-box  support&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt; for calling  REST, WS*/SOAP, POX, RSS and standard HTTP services enables users to create Web  2.0-style applications that easily integrate with existing heterogeneous  back-end systems.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';" lang="EN-NZ"&gt;Advanced  content protection features, now including Silverlight digital rights management  (DRM), Powered by PlayReady.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';" lang="EN-NZ"&gt;  Silverlight DRM builds on Microsoft’s extensive expertise in developing DRM  technologies, delivering robust protection for key Silverlight scenarios  including live streaming, on-demand streaming and progressive downloads for  connected experiences.&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Improved server  scalability and expanded advertiser support. &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;The combination  of Silverlight 2 and Windows Server 2008 offers streaming video professionals  industry-leading scalability and cutting-edge progressive download features. In  addition, Silverlight offers superior search engine optimization capabilities  and advanced in-stream advertising support through companies such as DoubleClick  Inc. and EyeWonder Inc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoListParagraph" style="margin: 6pt 0in 0pt 0.25in; text-indent: -0.25in; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: Symbol;"&gt;&lt;span style=""&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;          &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=""&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;Unparalleled  interactivity with high-resolution content through Deep Zoom  technology.&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;  &lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman','serif';"&gt;The  new Deep Zoom technology in Silverlight allows users to see images on the Web as  never before. The smooth, in-place zooming and panning that Deep Zoom allows is  a true advancement and raises the bar on what image viewing should be. It is  also now possible through this feature to make super-high-resolution images  easily consumable on the Web. Even better, Deep Zoom is designed in a way that  will reduce Web hosting and bandwidth costs by sending to the browser exactly  the right size and resolution image for the current display  area.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-6750479991753837418?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/6750479991753837418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=6750479991753837418' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/6750479991753837418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/6750479991753837418'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/01/microsoft-silverlight-2.html' title='Microsoft Silverlight 2'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-2026606399667039329</id><published>2009-01-18T20:05:00.001-08:00</published><updated>2009-01-18T20:07:11.634-08:00</updated><title type='text'>Truncate and Delete</title><content type='html'>Delete table is a logged operation, so the deletion of each row gets logged in  the transaction log, which makes it slow.&lt;br /&gt;&lt;br /&gt;Truncate table also deletes all  the rows in a table, but it won't log the deletion of each row, instead it logs  the de-allocation of the data pages of the table, which makes it faster. Of  course, truncate table cannot be rolled back.&lt;br /&gt;&lt;br /&gt;Truncate table is  functionally identical to delete statement with no where clause both remove all  rows in the table. But truncate table is faster and uses fewer system and  transaction log resources than delete.&lt;br /&gt;&lt;br /&gt;Truncate table removes all rows  from a table, but the table structure and its columns, constraints, indexes etc.  remains as it is.&lt;br /&gt;&lt;br /&gt;In truncate table the counter used by an identity  column for new rows is reset to the seed for the column.&lt;br /&gt;&lt;br /&gt;If you want to  retain the identity counter, use delete statement instead.&lt;br /&gt;&lt;br /&gt;If you want to  remove table definition and its data, use the drop table statement.&lt;br /&gt;&lt;br /&gt;You  cannot use truncate table on a table referenced by a foreign key constraint;  instead, use delete statement without a where clause. Because truncate table is  not logged, it cannot activate a trigger.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-2026606399667039329?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/2026606399667039329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=2026606399667039329' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/2026606399667039329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/2026606399667039329'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2009/01/truncate-and-delete.html' title='Truncate and Delete'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-5095303321522425561</id><published>2008-08-10T01:15:00.000-07:00</published><updated>2008-08-10T01:25:27.352-07:00</updated><title type='text'>New DataSet Features in ADO.NET 2.0</title><content type='html'>&lt;b style="color: rgb(153, 51, 0); font-weight: bold; font-family: verdana;"&gt;Summary: &lt;/b&gt;&lt;span style="color: rgb(153, 51, 0); font-weight: bold; font-family: verdana;"&gt;Learn about the new ADO.NET 2.0 features in the DataSet .NET Framework class and the classes that are closely related to it. These changes include both functional and performance enhancements to the DataSet, DataTable, and DataView classes.&lt;/span&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;!--[if !supportEmptyParas]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Download the &lt;a href="http://download.microsoft.com/download/a/1/4/a1412c5e-5977-4a95-a177-b9abb39330cd/DataSetSamples.EXE"&gt;DataSetSamples.exe sample code&lt;/a&gt; associated with the article.&lt;/p&gt;  &lt;h4 style="font-family: times new roman;"&gt;Contents&lt;/h4&gt;  &lt;p style="font-family: times new roman;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/#datasetenhancem_topic1"&gt;Introduction&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/#datasetenhancem_topic2"&gt;Raw Performance&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/#datasetenhancem_topic3"&gt;The DataTable – More Independent Than Before&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/#datasetenhancem_topic4"&gt;Stream to Cache, Cache to Stream&lt;/a&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/#datasetenhancem_topic5"&gt;Conclusion&lt;/a&gt;&lt;/p&gt;  &lt;h2 style="color: rgb(51, 153, 153); font-family: times new roman;"&gt;Introduction&lt;/h2&gt;  &lt;p style="font-family: times new roman;"&gt;In the upcoming release of ADO.NET, ADO.NET 2.0, there are many new and improved features that affect many different .NET Framework classes and application development scenarios. This article discusses on the changes and enhancement to the core disconnected mode ADO.NET Framework classes—the &lt;b&gt;DataSet&lt;/b&gt; and associated classes such as &lt;b&gt;DataSet&lt;/b&gt;, &lt;b&gt;DataTable&lt;/b&gt;, and&lt;b&gt; DataView&lt;/b&gt;.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;This article is actually the first of two articles on the &lt;b&gt;DataSet&lt;/b&gt; and associated classes in ADO.NET 2.0. Here we will focus on the classes in the .NET Framework. In the subsequent article, we will focus on developing with these and related classes from within the Visual Studio 2005 development environment. Visual Studio 2005 offers several designers and tools that offer tremendous flexibility and productivity for developing the data-centric aspects of your application. As a result, each article will have a different "feel". This article is mainly an overview of new functionality, accompanied by explanations and code samples. In the next article, the focus is more on the development process, as we see how to develop a working application.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;As I mentioned above, this article only covers a small slice of the new features of ADO.NET 2.0. An overview of some of the other features can be found in &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/ado2featurematrix.asp"&gt;ADO.NET 2.0 Feature Matrix&lt;/a&gt;. More in depth information on some of the topics mentioned there can be found these articles: &lt;/p&gt;  &lt;ul style="font-family: times new roman;" type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms379553.aspx"&gt;Asynchronous      Command Execution in ADO.NET 2.0&lt;/a&gt; &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms379620.aspx"&gt;Generic      Coding with the ADO.NET 2.0 Base Classes and Factories&lt;/a&gt; &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms379543.aspx"&gt;Schemas in      ADO.NET 2.0&lt;/a&gt; &lt;/li&gt;&lt;/ul&gt;  &lt;p style="font-family: times new roman;"&gt;Unless noted otherwise, the contents of this article are based on the Beta 1 release of Visual Studio 2005. The code samples use the Northwind database that comes as a sample database with SQL Server 2000.&lt;/p&gt;  &lt;h2 style="color: rgb(51, 153, 153); font-family: times new roman;"&gt;Raw Performance&lt;/h2&gt;  &lt;p style="font-family: times new roman;"&gt;Software developers are always concerned with performance. Sometimes they get over-concerned and make their code jump through hoops to just trim a little execution time, in places where it ultimately isn't significant—but that is a subject for another article. When it comes to ADO.NET 1.x &lt;b&gt;DataSets&lt;/b&gt;, particularly those containing a large amount of data, the performance concerns expressed by developers are indeed justified. Large &lt;b&gt;DataSets&lt;/b&gt; are slow—in two different contexts. The first time the sluggish performance is felt is when loading a &lt;b&gt;DataSet&lt;/b&gt; (actually, a &lt;b&gt;DataTable&lt;/b&gt;) with a large number of rows. As the number of rows in a &lt;b&gt;DataTable&lt;/b&gt; increases, the time to load a new row increases almost proportionally to the number of rows in the &lt;b&gt;DataTable&lt;/b&gt;. The other time the performance hit is felt is when serializing and remoting a large &lt;b&gt;DataSet&lt;/b&gt;. A key feature of the &lt;b&gt;DataSet&lt;/b&gt; is the fact that it automatically knows how to serialize itself, especially when we want to pass it between application tiers. However, a close look reveals that this serialization is quite verbose, consuming much memory and network bandwidth. Both of these performance bottlenecks are addressed in ADO.NET 2.0.&lt;/p&gt;  &lt;h3 style="font-family: times new roman;"&gt;New Indexing Engine&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;The indexing engine for the &lt;b&gt;DataTable&lt;/b&gt; has been completely rewritten in ADO.NET 2.0 and scales much better for large datasets. This results in faster basic inserts, updates, and deletes, and therefore faster &lt;b&gt;Fill&lt;/b&gt; and &lt;b&gt;Merge&lt;/b&gt; operations. While benchmarks and quantifying performance gains is always an application-specific and often risky affair, these improvements clearly provide more than an order of magnitude improvement in loading a DataTable with a million rows. But don't take my word for it, check it out yourself, with the following simple example. Add the following code as the click event handler for a button on a Windows form:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl06');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="_x0000_i1025" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl06');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;Private Sub LoadButton_Click(ByVal sender As System.Object, &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;ByVal e As System.EventArgs) Handles LoadButton.Click&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim ds As New DataSet&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim time1 As New Date&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim i As Integer&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim dr As DataRow&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ds.Tables.Add("BigTable")&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ds.Tables(0).Columns.Add("ID", Type.GetType("System.Int32"))&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ds.Tables(0).Columns("ID").Unique = True&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ds.Tables(0).Columns.Add("Value", Type.GetType("System.Int32"))&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' Show status label&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;WaitLabel.Visible = True&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Me.Cursor = Cursors.WaitCursor&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Me.Refresh()&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' catch start time&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;time1 = DateTime.Now()&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' Yes, we are loading a million rows to a DataTable!&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;span style=""&gt;     &lt;/span&gt;'&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' If you compile/run this with ADO.NET 1.1, you have time &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' to make and enjoy a fresh pot of coffee...&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim rand As New Random&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim value As Integer&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;For i = 1 To 1000000&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;Try&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;value = rand.Next&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;dr = ds.Tables(0).NewRow()&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;dr("ID") = value&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;dr("Value") = value&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;ds.Tables(0).Rows.Add(dr)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;Catch ex As Exception&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;' if there are any duplicate values, an exception&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;' will be thrown since the ID column was specified&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;' to be unique&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;End Try&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Next&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' reset cursor and label&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;WaitLabel.Visible = False&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Me.Cursor = Me.DefaultCursor&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;' Show elapsed time, in seconds&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;MessageBox.Show("Elapsed Time: " &amp;amp; _&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;DateDiff(DateInterval.Second, time1, DateTime.Now))&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' verify number of rows in the table&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' This number will probably be less that the number&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' of loop iterations, since if the same random number&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' comes up, it will/can not be added to the table&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;MessageBox.Show("count = " &amp;amp; ds.Tables(0).Rows.Count)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;End Sub&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;When I ran this code in my environment with ADO.NET 1.1 and Visual Studio 2003, the execution time was about 30 minutes. With ADO.NET 2.0 and Visual Studio 2005, I had an execution time of approximately 40-50 &lt;i&gt;seconds&lt;/i&gt;! When I lowered the number of rows to only half a million, the 1.1 version took about 45 seconds and the 2.0 version took about 20 seconds. Your numbers will vary, but I think the point is clear.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;In fact, this example is a very simple one, since it contains only one index, for the unique column. However, as the number of indices on the specified &lt;b&gt;DataTable&lt;/b&gt; increases, such as by adding additional &lt;b&gt;DataView&lt;/b&gt;s, &lt;b&gt;UniqueKey&lt;/b&gt;s and &lt;b&gt;ForeignKey&lt;/b&gt;s, the performance difference will be that much greater.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin-right: 0.5in; margin-left: 0.5in; font-family: times new roman;"&gt;&lt;b&gt;Note&lt;/b&gt;   The reason the ID value in the sample code is being generated by a random number generator rather than just using the loop counter as the ID, is in order to better represent the real-world scenario. In real applications, accessing the elements of a DataTable for Inserts, Updates, and Deletes is rarely done sequentially. For each operation, the row specified by the unique key must first be located. When inserting and deleting rows, the table's indices must be updated. If we were to just load a million rows with sequentially key values into an empty table, the results would be extremely fast, but misleading.&lt;/p&gt;  &lt;h3 style="color: rgb(51, 153, 153); font-family: times new roman;"&gt;Binary Serialization Option&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;The major performance improvement in loading a &lt;b&gt;DataTable&lt;/b&gt; with a lot of data did not require us to make any change at all to our existing ADO.NET 1.x code. In order to benefit from improved performance when serializing the &lt;b&gt;DataSet&lt;/b&gt;, we need to work a bit harder—we need to add a single line of code to set the new &lt;b&gt;RemotingFormat&lt;/b&gt; property.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;In ADO.NET 1.x, the DataSet serializes as XML, even when using the binary formatter. In ADO.NET 2.0, in addition to this behavior, we can also specify true binary serialization, by setting the &lt;b&gt;RemotingFormat &lt;/b&gt;property&lt;b&gt; &lt;/b&gt;to &lt;b&gt;SerializationFormat.Binary &lt;/b&gt;rather than (the default) &lt;b&gt;SerializationFormat.XML&lt;/b&gt;. Let us take a look at the different outputs resulting from these two different options.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;In order to maintain backwards compatibility (about which the ADO.NET team was always concerned), the default value of XML serialization will give us the same behavior as in ADO.NET 1.x. The results of this serialization can be seen by running this code:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl07');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1026" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl07');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;Private Sub XMLButton_Click(ByVal sender As System.Object, &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;ByVal e As System.EventArgs) Handles XMLButton.Click&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim ds As New DataSet&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim da As New SqlDataAdapter("select * from [order details]", _&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt; GetConnectionString())&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;da.Fill(ds)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim bf As New BinaryFormatter&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim fs As New FileStream("..\xml.txt", FileMode.CreateNew)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;bf.Serialize(fs, ds)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;End Sub&lt;/pre&gt;&lt;br /&gt;&lt;pre style="font-family: times new roman;"&gt;Private Function GetConnectionString() As String&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' To avoid hard-coding the connection string in your code, &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' use the application settings&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Return MySettings.Value.NorthwindConnection&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;End Function&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;Note that this code is explicitly using the &lt;b&gt;BinaryFormatter&lt;/b&gt; class, yet the output in file xml.txt, shown in &lt;b&gt;Figure 1&lt;/b&gt;, is clearly XML. Also, in this case, the size of the file is 388 KB. &lt;/p&gt;  &lt;p style="font-family: times new roman;" class="fig"&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Let us now change the serialization format to binary by adding the line &lt;/p&gt;&lt;br /&gt;&lt;pre style="font-family: times new roman;"&gt;ds.RemotingFormat = SerializationFormat.Binary&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;and save the data to a different file by modifying the filename in the &lt;b&gt;FileStream&lt;/b&gt; constructor so that the code now looks like this:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl10');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1030" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl10');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;Private Sub BinaryButton_Click(ByVal sender As System.Object, &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;ByVal e As System.EventArgs) Handles BinaryButton.Click&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim ds As New DataSet&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim da As New SqlDataAdapter("select * from [order details]", _&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;GetConnectionString())&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;da.Fill(ds)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim bf As New BinaryFormatter&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim fs As New FileStream("..\binary.txt", FileMode.CreateNew)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;ds.RemotingFormat = SerializationFormat.Binary&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;bf.Serialize(fs, ds)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;End Sub&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;The output in file binary.txt is shown in Figure 2. Here we see that it is now in fact binary data, pretty unintelligible to the human reader. Moreover, the size of this file is only 59 KB—again, an order of magnitude reduction in the amount of data that needs to be transferred and the CPU, memory, and bandwidth resources required to process it. It should be pointed out that this improvement is relevant when using remoting and not when using Web Services, since Web Services by definition must be passing XML. This means that you will only be able to take advantage of this enhancement when both sides of the communication are .NET-based and not when communicating to non-.NET platforms.&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="fig"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1031" type="#_x0000_t75" alt="" style="'width:24pt;height:24pt'/"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;More in-depth details about &lt;b&gt;DataSet&lt;/b&gt; serialization process can be found in &lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/10/CuttingEdge/"&gt;Binary Serialization of DataSets&lt;/a&gt;. &lt;/p&gt;  &lt;h2 style="color: rgb(153, 0, 0); font-family: times new roman;"&gt;The DataTable – More Independent Than Before&lt;/h2&gt;  &lt;p style="font-family: times new roman;"&gt;When discussing ADO.NET 1.x and its object model for disconnected data access, the central object was the &lt;b&gt;DataSet&lt;/b&gt;. Sure it contained other objects, such the &lt;b&gt;DataTable&lt;/b&gt;, &lt;b&gt;DataRelation&lt;/b&gt;, &lt;b&gt;DataRow&lt;/b&gt;, etc., but the attention generally started and revolved around the &lt;b&gt;DataSet&lt;/b&gt;. It is true that most .NET developers were aware and leveraged the fact that the &lt;b&gt;DataTable&lt;/b&gt; was quite useful on its own, without being encapsulated inside a &lt;b&gt;DataSet&lt;/b&gt;. However, there were some scenarios where we couldn't do what we wanted to do with a &lt;b&gt;DataTable&lt;/b&gt; unless we first took it and forced it into a &lt;b&gt;DataSet&lt;/b&gt;. The most glaring and often painful example of this is to read and write (load and save) XML data in to and out of the &lt;b&gt;DataTable&lt;/b&gt;. In ADO.NET 1.x, we must first add the &lt;b&gt;DataTable&lt;/b&gt; to &lt;b&gt;DataSet&lt;/b&gt;, just so we could read or write XML, since the methods to do so are only available on the &lt;b&gt;DataSet&lt;/b&gt;!&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;One of the objectives of ADO.NET 2.0 was to make the standalone &lt;b&gt;DataTable&lt;/b&gt; class far more functional and useful than it is in ADO.NET 1.x. The &lt;b&gt;DataTable&lt;/b&gt; now supports the basic methods for XML, just as the &lt;b&gt;DataSet &lt;/b&gt;does. This includes the following methods: &lt;/p&gt;  &lt;ul style="font-family: times new roman;" type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;ReadXML&lt;/b&gt; &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;ReadXMLSchema&lt;/b&gt; &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;WriteXML&lt;/b&gt; &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;WriteXMLSchema&lt;/b&gt; &lt;/li&gt;&lt;/ul&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;DataTable&lt;/b&gt; is independently serializable and can be used in both web service and remoting scenarios. In addition to now supporting the &lt;b&gt;Merge&lt;/b&gt; method, the stand-alone &lt;b&gt;DataTable&lt;/b&gt; also supports new ADO.NET 2.0 features added to the &lt;b&gt;DataSet:&lt;/b&gt; &lt;/p&gt;  &lt;ul style="font-family: times new roman;" type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;RemotingFormat&lt;/b&gt;      property (discussed previously) &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;Load&lt;/b&gt; method (discussed      later in this article) &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;GetDataReader&lt;/b&gt; method      (discussed later in this article) &lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal" style="margin-right: 0.5in; margin-left: 0.5in; font-family: times new roman;"&gt;&lt;b&gt;Note   &lt;/b&gt;On the topic of XML, it is worth noting that in ADO.NET 2.0 there is much enhanced XML support—what Microsoft likes to call greater "XML Fidelity". This takes the form of support for the SQL Server 2005 XML data type, extended XSD schema support, an improved XSD schema inference engine, and the elimination of two often troublesome limitations: (i) The DataSet and DataTable classes can now handle multiple in-line schemas and (ii) The DataSet now fully supports namespaces, so that a DataSet can contain multiple DataTables with the same name, but from different namespaces, i.e., tables with the same unqualified names, but with different qualified names. Also, a child table with the same name and namespace that is included in multiple relations can be nested in multiple parent tables.&lt;/p&gt;  &lt;h2 style="color: rgb(102, 204, 204); font-family: times new roman;"&gt;Stream to Cache, Cache to Stream&lt;/h2&gt;  &lt;p style="font-family: times new roman;"&gt;Another one of the main enhancements for the &lt;b&gt;DataSet&lt;/b&gt; and &lt;b&gt;DataTable classes in &lt;/b&gt;ADO.NET 2.0 is the availability of mechanisms to consume a &lt;b&gt;DataReader&lt;/b&gt; (loading data into &lt;b&gt;DataTable&lt;/b&gt;s) and to expose a &lt;b&gt;DataReader&lt;/b&gt; over the contents of &lt;b&gt;DataTable&lt;/b&gt;s. &lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Sometimes we have/receive our data in the form of a &lt;b&gt;DataReader&lt;/b&gt;, but really want to have it in the form of a cached &lt;b&gt;DataTable&lt;/b&gt;.&lt;b&gt; &lt;/b&gt;The new &lt;b&gt;Load&lt;/b&gt; method allows us to take an existing &lt;b&gt;DataReader&lt;/b&gt; and use it to fill a &lt;b&gt;DataTable&lt;/b&gt; with its contents.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Sometimes we have/receive our data in a cached form (&lt;b&gt;DataTable&lt;/b&gt;) and need to access it via a &lt;b&gt;DataReader &lt;/b&gt;type interface. The new &lt;b&gt;GetTableReader&lt;/b&gt; method allows us to take an existing &lt;b&gt;DataTable&lt;/b&gt; and access it with a &lt;b&gt;DataReader&lt;/b&gt; interface and semantics.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;In the following sections, we'll take a look at these new methods.&lt;/p&gt;  &lt;h3 style="color: rgb(0, 204, 204); font-family: times new roman;"&gt;The Load Method – Basic Use&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;Load&lt;/b&gt; method is a new method that has been added to the &lt;b&gt;DataSet&lt;/b&gt; and the &lt;b&gt;DataTable&lt;/b&gt; in ADO.NET 2.0. It loads a &lt;b&gt;DataTable&lt;/b&gt; with the contents of a &lt;b&gt;DataReader&lt;/b&gt; object. It can actually load multiple tables at one time, if the &lt;b&gt;DataReader&lt;/b&gt; contains multiple resultsets.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;The basic use of the Load method is quite straightforward:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl12');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1032" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl12');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image008.gif" shapes="_x0000_i1032" border="0" height="9" width="9" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;&lt;code&gt;MyDataTable.Load (MyDataReader)&lt;o:p&gt;&lt;/o:p&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;A more complete illustration of its use is shown in this sample code:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl13');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1033" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl13');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image009.gif" shapes="_x0000_i1033" border="0" height="9" width="9" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt; &lt;/span&gt;Private Sub LoadButton_Click(ByVal sender As System.Object, &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;ByVal e As System.EventArgs) Handles LoadButton.Click&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Try&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;span style=""&gt;          &lt;/span&gt;Using connection As New SqlConnection(GetConnectionString())&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;Using command As New SqlCommand("SELECT * from customers", connection)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                    &lt;/span&gt;connection.Open()&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                    &lt;/span&gt;Using dr As SqlDataReader = command.ExecuteReader()&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;'Fill table with data from DataReader&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;Dim dt As New DataTable&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;dt.Load(dr, LoadOption.OverwriteRow)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;' Display the data&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                        &lt;/span&gt;DataGridView1.DataSource = dt&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                    &lt;/span&gt;End Using&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;                &lt;/span&gt;End Using&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;End Using&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Catch ex As SqlException&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;MessageBox.Show(ex.Message)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Catch ex As InvalidOperationException&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;MessageBox.Show(ex.Message)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Catch ex As Exception&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;' You might want to pass these errors&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;' back out to the caller.&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;            &lt;/span&gt;MessageBox.Show(ex.Message)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;End Try&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;End Sub&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;The code above initializes connection and command objects and then executes the &lt;b&gt;ExecuteReader&lt;/b&gt; method to fetch the data from the database. The results of the query are provided as a &lt;b&gt;DataReader&lt;/b&gt;, which is then passed to the &lt;b&gt;Load&lt;/b&gt; method of the &lt;b&gt;DataTable&lt;/b&gt; to fill it with the returned data. Once the &lt;b&gt;DataTable&lt;/b&gt; is filled with the data, it can be bound and displayed in the &lt;b&gt;DataGridView&lt;/b&gt;. The significance of the &lt;b&gt;OverwriteRow&lt;/b&gt; load option for the (optional) &lt;b&gt;LoadOption&lt;/b&gt; parameter will be explained in the next section.&lt;/p&gt;  &lt;h3 style="color: rgb(102, 204, 204); font-family: times new roman;"&gt;The Load Method – Why am I loading this data?&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;If all you are doing with your &lt;b&gt;DataSet&lt;/b&gt;/&lt;b&gt;DataTable&lt;/b&gt; and &lt;b&gt;DataAdapter&lt;/b&gt; is filling the &lt;b&gt;DataSet&lt;/b&gt; with data from the data source, modifying that data, and then at some later point pushing it back into the data source, that things general move pretty smoothly. A first complication occurs if you are utilizing optimistic concurrency and a concurrency violation is detected (someone else already changed one of the rows you are trying to change). In this case what you normally need to do to resolve the conflict is to resynchronize the &lt;b&gt;DataSet&lt;/b&gt; with the data source, so that the original values for the rows match the current database values. This can be accomplished by merging a DataTable with the new values into the original table (in ADO.NET 1.x, the merge method is only available on the &lt;b&gt;DataSet&lt;/b&gt;):&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl14');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1034" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl14');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image010.gif" shapes="_x0000_i1034" border="0" height="9" width="9" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;OriginalTable.Merge(NewTable, True)&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;By matching rows with the same primary key, records in the new table are merged with the records in the original table. Of key significance here is the second parameter, &lt;b&gt;PreserveChanges&lt;/b&gt;. This specifies that the merge operation should only update the original values for each row, and not affect the current values for the row. This allows the developer to subsequently execute a &lt;b&gt;DataAdapter.Update&lt;/b&gt; that will now succeed in updating the data source with the changes (current values), since the original values now match the current data source values. If &lt;b&gt;PreserveChanges&lt;/b&gt; is left at its default value of false, the merge would override both the original and current values of the rows in the original &lt;b&gt;DataTable&lt;/b&gt; and all of the changes that were made would be lost.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;However, sometimes we want to update data in the data source, where the new values don't come from programmatically modifying the values. Perhaps we obtain updated values from another database or from an XML source. In this scenario, we want to update the current values of the rows in the &lt;b&gt;DataTable&lt;/b&gt;, but not affect the original values for those rows. There is no easy way to do this in ADO.NET 1.x. It is for this reason that the ADO.NET 2.0 &lt;b&gt;Load&lt;/b&gt; method accepts a parameter &lt;b&gt;LoadOption&lt;/b&gt; that indicates how to combine the new incoming rows with the same (primary key) rows already in the &lt;b&gt;DataTable&lt;/b&gt;. &lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;LoadOption &lt;/b&gt;allows us to explicitly specify what our intention is when loading the data (synchronization or aggregation) and how we therefore want to merge the new and existing rows. Figure 3&lt;b&gt; &lt;/b&gt;outlines the various scenarios:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="fig"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1035" type="#_x0000_t75" alt="" style="'width:24pt;height:24pt'/"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image011.gif" shapes="_x0000_i1035" border="0" height="32" width="32" /&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Where: &lt;/p&gt;  &lt;ul style="font-family: times new roman;" type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;Primary Data Source&lt;/b&gt;—&lt;b&gt;DataTable/DataSet&lt;/b&gt;      synchronizes/updates with only one Primary Data Source. It will track      changes to allow for synchronization with primary data sources. &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;Secondary Data Source&lt;/b&gt;—&lt;b&gt;DataTable/DataSet&lt;/b&gt;      accepts incremental data feeds from one or more Secondary Data Sources. It      is not responsible for tracking changes for the purpose of synchronization      with secondary data sources. &lt;/li&gt;&lt;/ul&gt;  &lt;p style="font-family: times new roman;"&gt;The three cases shown in Figure 3 can be summarized as follows: &lt;/p&gt;  &lt;ul style="font-family: times new roman;" type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;Case 1&lt;/b&gt;—&lt;b&gt;Initialize      DataTable(s) from Primary Data Source.&lt;/b&gt; The user wants to initialize an      empty DataTable (original values and current values) with values from      primary data source and then later, after changes have been made to this      data, propagate the changes back to the primary data source. &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;Case 2&lt;/b&gt;—&lt;b&gt;Preserve      Changes and Re-Sync from Primary Data Source.&lt;/b&gt; The user wants to take      the modified DataTable and re-synchronize its contents (original values      only) with the primary data source while maintaining the changes made      (current values) &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;Case 3&lt;/b&gt;—&lt;b&gt;Aggregate      incremental data feeds from one or more Secondary Data Sources.&lt;/b&gt; The      user wants to accept changes (current values) from one or more secondary      data sources and then propagate these changes back to the primary data      source. &lt;/li&gt;&lt;/ul&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;LoadOption&lt;/b&gt; enumeration has three values that respectively represent these three scenarios: &lt;/p&gt;  &lt;ul style="font-family: times new roman;" type="disc"&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;OverwriteRow&lt;/b&gt;—Update      the current and original versions of the row with the value of the      incoming row. &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;PreserveCurrentValues&lt;u&gt;      (default)&lt;/u&gt;&lt;/b&gt;—Update original version of the row with the value of the      incoming row. &lt;/li&gt;&lt;li class="MsoNormal" style=""&gt;&lt;b&gt;UpdateCurrentValues&lt;/b&gt;—Update      the current version of the row with the value of the incoming row. &lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal" style="margin-right: 0.5in; margin-left: 0.5in; font-family: times new roman;"&gt;&lt;b&gt;Note   &lt;/b&gt;These names will probably change post-Beta 1.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Table 1 below summarizes the load semantics. If the incoming row and existing row agree on primary key values, then the row is processed using its existing &lt;b&gt;DataRowState&lt;/b&gt;, else use 'Not Present' section (the last row in the table).&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="label"&gt;&lt;b&gt;Table 1. Summary of Load Semantics&lt;/b&gt;&lt;/p&gt;  &lt;table style="font-family: times new roman;" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Existing DataRow   State&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 26%;" valign="top" width="26%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;UpdateCurrentValues   &lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;OverwriteRow &lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 31%;" valign="top" width="31%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;PreserveCurrentValues   (Default)&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Added&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 26%;" valign="top" width="26%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = - --&lt;/p&gt;   &lt;p&gt;State = &lt;added&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 31%;" valign="top" width="31%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;existing&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Modified&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 26%;" valign="top" width="26%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;existing&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 31%;" valign="top" width="31%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;existing&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p style="text-align: center;" align="center"&gt;&lt;b&gt;Deleted&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 26%;" valign="top" width="26%"&gt;   &lt;p class="MsoNormal"&gt;(&lt;i&gt;Undo Delete) and&lt;/i&gt; &lt;/p&gt;   &lt;p&gt;Current = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;Original = &lt;existing&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;&lt;i&gt;(Undo Delete) and &lt;/i&gt;&lt;/p&gt;   &lt;p&gt;Current = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 31%;" valign="top" width="31%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;existing&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;deleted&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Unchanged&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 26%;" valign="top" width="26%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;existing&gt;&lt;/p&gt;   &lt;p&gt;If new value same as existing value then &lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt; &lt;/p&gt;   &lt;p&gt;Else&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p&gt;Current = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 31%;" valign="top" width="31%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Not Present&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 26%;" valign="top" width="26%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = ---&lt;/p&gt;   &lt;p&gt;State = &lt;&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 31%;" valign="top" width="31%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;incoming&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;incoming&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;h3 style="font-family: times new roman;"&gt;Example&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;In order to illustrate the behavior specified in Table 1, I offer a simple example. &lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Assume that both the existing DataRow and incoming row have 2 columns with matching names. The first column is the primary key and the second column contains a numeric value. The tables below show the contents of the second column in the data rows. &lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Table 2 represents the contents of a row in all 4 states before invoking Load. The incoming row's second column value is 3. Table 3 shows its contents after load. &lt;/p&gt;  &lt;p style="font-family: times new roman;" class="label"&gt;&lt;b&gt;Table 2. Row State Before Load&lt;/b&gt;&lt;/p&gt;  &lt;table style="font-family: times new roman;" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 23%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Existing Row   State&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 14%;" valign="top" width="14%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Version&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Added&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Modified&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 14%;" valign="top" width="14%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Deleted&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 19%;" valign="top" width="19%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Unchanged&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 23%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 14%;" valign="top" width="14%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Current&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal"&gt;2&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal"&gt;2&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 14%;" valign="top" width="14%"&gt;   &lt;p class="MsoNormal"&gt;-&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 19%;" valign="top" width="19%"&gt;   &lt;p class="MsoNormal"&gt;4&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 23%;" valign="top" width="23%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 14%;" valign="top" width="14%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Original&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal"&gt;-&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal"&gt;4&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 14%;" valign="top" width="14%"&gt;   &lt;p class="MsoNormal"&gt;4&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 19%;" valign="top" width="19%"&gt;   &lt;p class="MsoNormal"&gt;4&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p style="font-family: times new roman;" class="label"&gt;&lt;b&gt;Incoming Row&lt;/b&gt;&lt;/p&gt;  &lt;table style="font-family: times new roman;" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 100%;" valign="top" width="100%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Incoming Row&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 100%;" valign="top" width="100%"&gt;   &lt;p class="MsoNormal"&gt;3&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p style="font-family: times new roman;" class="label"&gt;&lt;b&gt;Table 3. Row State After Load&lt;/b&gt;&lt;/p&gt;  &lt;table style="font-family: times new roman;" border="0" cellpadding="0"&gt;  &lt;tbody&gt;&lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;UpdateCurrentValues&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 27%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;OverwriteRow &lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 30%;" valign="top" width="30%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;PreserveCurrentValues&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p style="text-align: center;" align="center"&gt;&lt;b&gt;Added&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = ---&lt;/p&gt;   &lt;p&gt;State = &lt;added&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 27%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 30%;" valign="top" width="30%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;2&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;changed&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p style="text-align: center;" align="center"&gt;&lt;b&gt;Modified&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p&gt;Current = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;Original = &lt;4&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 27%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 30%;" valign="top" width="30%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;2&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;changed&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p style="text-align: center;" align="center"&gt;&lt;b&gt;Deleted&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;4&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 27%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 30%;" valign="top" width="30%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;2&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;deleted&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Unchanged&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;4&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;modified&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 27%;" valign="top" width="27%"&gt;   &lt;p&gt;Current = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 30%;" valign="top" width="30%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr&gt;   &lt;td style="padding: 0.75pt; width: 15%;" valign="top" width="15%"&gt;   &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;Not Present&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 28%;" valign="top" width="28%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = ---&lt;/p&gt;   &lt;p&gt;State = &lt;added&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 27%;" valign="top" width="27%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 30%;" valign="top" width="30%"&gt;   &lt;p class="MsoNormal"&gt;Current = &lt;3&gt; &lt;/p&gt;   &lt;p&gt;Original = &lt;3&gt;&lt;/p&gt;   &lt;p&gt;State = &lt;unchanged&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style="margin-right: 0.5in; margin-left: 0.5in; font-family: times new roman;"&gt;&lt;b&gt;Note   &lt;/b&gt;You can see the beginnings of this concept already in ADO.NET 1.x. The default behavior of the DataAdapter's &lt;b&gt;Fill&lt;/b&gt; method when loading data into a DataTable is to mark all the rows as Unchanged (This can be overridden by setting the &lt;b&gt;AcceptChangesOnFill&lt;/b&gt; property to False). However, when using ReadXML to load data into a DataSet, the rows are marked as Added. The rationale for this (which was implemented based on customer feedback) is that this would allow loading new data from an XML source into a DataSet and then using the associated DataAdapter to update the primary data source. If the rows were marked as Unchanged when loaded from ReadXML, &lt;b&gt;the DataAdapter.Update&lt;/b&gt; would not detect and changes and would not execute any commands against the data source.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;In order to provide similar functionality, the &lt;b&gt;FillLoadOptions&lt;/b&gt; property has been added to the &lt;b&gt;DataAdapter&lt;/b&gt; in order to offer the same semantics and behavior as the &lt;b&gt;Load&lt;/b&gt; method described here, while still preserving the same (by default) existing behavior of the &lt;b&gt;Fill&lt;/b&gt; method.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Another feature (which doesn't exist) that developers always ask about in ADO.NET 1.x, is the ability to manually modify the state of &lt;b&gt;DataRow&lt;/b&gt;. While the options offered by the &lt;b&gt;Load&lt;/b&gt; method may address most scenarios, you may still want to have finer-grained control over the row state—you may have a need to modify the state of individual rows. To that end, ADO.NET 2.0 introduces two new methods on the &lt;b&gt;DataRow&lt;/b&gt; class: &lt;b&gt;SetAdded&lt;/b&gt; and &lt;b&gt;SetModified&lt;/b&gt;. Before you ask about setting the state to &lt;b&gt;Deleted&lt;/b&gt;, or &lt;b&gt;Unchanged&lt;/b&gt;, let me remind you that with version 1.x we already have the &lt;b&gt;Delete&lt;/b&gt; and &lt;b&gt;AcceptChanges&lt;/b&gt;/&lt;b&gt;RejectChanges&lt;/b&gt; methods to accomplish this.&lt;/p&gt;  &lt;h3 style="color: rgb(102, 204, 204); font-family: times new roman;"&gt;The GetTableReader Method&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;GetTableReader&lt;/b&gt; method is a new method that has been added to the &lt;b&gt;DataSet&lt;/b&gt; and the &lt;b&gt;DataTable&lt;/b&gt; in ADO.NET 2.0. It returns the contents of a &lt;b&gt;DataTable&lt;/b&gt; as a &lt;b&gt;DataTableReader&lt;/b&gt; (derived from DBDataReader) object. If it is invoked on a DataSet that contains multiple tables, the &lt;b&gt;DataReader&lt;/b&gt; will contain multiple resultsets.&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl15');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1036" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl15');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image012.gif" shapes="_x0000_i1036" border="0" height="9" width="9" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;The use of the &lt;b&gt;GetTableReader&lt;/b&gt; method is quite straight-forward:&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;code&gt;Dim dtr As DataTableReader = ds.Tables(0).GetDataReader&lt;/code&gt;&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;DataTableReader&lt;/b&gt; works pretty much like the other data readers you have worked with, such as the &lt;b&gt;SqlDataReader &lt;/b&gt;or&lt;b&gt; OleDbDataReader&lt;/b&gt;. The difference is, however, that rather than streaming data from a live database connection, the &lt;b&gt;DataTableReader&lt;/b&gt; provides iteration over the rows of a disconnected &lt;b&gt;DataTable&lt;/b&gt;. &lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;The &lt;b&gt;DataTableReader&lt;/b&gt; provides a smart, stable iterator. The cached data may be modified while the &lt;b&gt;DataTableReader&lt;/b&gt; is active and the reader will automatically maintain its position&lt;b&gt; &lt;/b&gt;appropriately even if one or more rows are deleted or inserted while iterating.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;A &lt;b&gt;DataTableReader&lt;/b&gt; that is created by calling &lt;b&gt;GetDataReader &lt;/b&gt;on a &lt;b&gt;DataTable&lt;/b&gt; contains one result set with the same data as the &lt;b&gt;DataTable&lt;/b&gt; from which it was created. The result set contains only the current column values for each &lt;b&gt;DataRow&lt;/b&gt; and rows that are marked for deletion are skipped. A &lt;b&gt;DataTableReader&lt;/b&gt; that is created by calling &lt;b&gt;GetDataReader &lt;/b&gt;on a &lt;b&gt;DataSet&lt;/b&gt; that contains more than one table will contain multiple result sets. The result sets will be in the same sequence as the &lt;b&gt;DataTable&lt;/b&gt; objects in the &lt;b&gt;DataSet&lt;/b&gt; object's &lt;b&gt;DataTableCollection&lt;/b&gt;.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;In addition to the features outlined above, another great use of the &lt;b&gt;GetDataReader&lt;/b&gt; method is to quickly copy data from one &lt;b&gt;DataTable&lt;/b&gt; to another:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl16');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1037" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl16');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image013.gif" shapes="_x0000_i1037" border="0" height="9" width="9" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;Dim dt2 as new DataTable&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;dt2.Load(ds.Tables(0).GetDataReader)&lt;/pre&gt;  &lt;h3 style="color: rgb(51, 153, 153); font-family: times new roman;"&gt;The DataView.ToTable Method&lt;/h3&gt;  &lt;p style="font-family: times new roman;"&gt;Another new method that is somewhat related to the previous ones (in that it provides a new &lt;b&gt;DataTable&lt;/b&gt; cache of existing data) and is worth mentioning is the &lt;b&gt;ToTable&lt;/b&gt; method of the &lt;b&gt;DataView&lt;/b&gt; class. As a reminder, the DataView class provides a logical view of the rows in a &lt;b&gt;DataTable&lt;/b&gt;. This view may be filtered by row, row state, and sorted. However, in ADO.NET 1.1, there is no easy way to save or pass on the rows of the view, since the &lt;b&gt;DataView&lt;/b&gt; does not have its own copy of the rows—it simply accesses the rows of the underlying &lt;b&gt;DataTable&lt;/b&gt; as prescribed by the filter and sort parameters. The &lt;b&gt;DataView&lt;/b&gt;'s &lt;b&gt;ToTable&lt;/b&gt; method returns an actual &lt;b&gt;DataTable&lt;/b&gt; object that is populated with rows of the exposed by the current view.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Overloaded versions of the &lt;b&gt;ToTable&lt;/b&gt; method offer the option of specifying the list of columns to be included in the created table. The generated table will contain the listed columns in the specified sequence, which may differ from the original table/view. This ability to limit the number of columns in a view is a feature that is missing in ADO.NET 1.x and has frustrated many a .NET programmer. You can also specify the name of the created table and whether it should contain all or only distinct rows.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;Here is some sample code that shows how to use the &lt;b&gt;ToTable&lt;/b&gt; method:&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="MsoNormal"&gt;&lt;a href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl17');"&gt;&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1038" type="#_x0000_t75" alt="" href="javascript:CopyCode('ctl00_rs1_mainContentContainer_ctl17');" style="'width:6.75pt;" button="t"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image014.gif" shapes="_x0000_i1038" border="0" height="9" width="9" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;  &lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;span style=""&gt; &lt;/span&gt;Private Sub ToTableButton_Click(ByVal sender As System.Object, &lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;ByVal e As System.EventArgs) Handles ToTableButton.Click&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;' Show only 2 columns in second grid&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim columns As String() = {"CustomerID", "ContactName"}&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;Dim dt As DataTable = _&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;ds.Tables("customers").DefaultView.ToTable( _&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;"SmallCustomers", False, columns)&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;        &lt;/span&gt;DataGridView2.DataSource = dt&lt;/pre&gt;&lt;pre style="font-family: times new roman;"&gt;&lt;span style=""&gt;    &lt;/span&gt;End Sub&lt;/pre&gt;  &lt;p style="font-family: times new roman;"&gt;Assuming that the contents of the "customers" table in the &lt;b&gt;DataSet&lt;/b&gt; ds are displayed in a first grid, this routine displays the newly created &lt;b&gt;DataTable&lt;/b&gt; that contains only those rows exposed by the &lt;b&gt;DefaultView&lt;/b&gt; (as specified by its filter parameters). The rows in the new table contain only two of the columns of the original &lt;b&gt;DataTable&lt;/b&gt; and &lt;b&gt;DataView&lt;/b&gt;. An example of this can be seen in Figure 4.&lt;/p&gt;  &lt;p style="font-family: times new roman;" class="fig"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1039" type="#_x0000_t75" alt="" style="'width:24pt;height:24pt'/"&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;br /&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;h2 style="color: rgb(102, 204, 204); font-family: times new roman;"&gt;Conclusion&lt;/h2&gt;  &lt;p style="font-family: times new roman;"&gt;The ADO.Net 2.0 version of the &lt;b&gt;DataSet&lt;/b&gt; (and &lt;b&gt;DataTable&lt;/b&gt;) introduces numerous new features and enhancements to existing features. The main features, discussed in the article, include significantly improved performance due to a new index engine and the binary serialization format option, extensive capabilities available to a stand-alone &lt;b&gt;DataTable&lt;/b&gt;, and mechanisms for exposing cached data as a stream (&lt;b&gt;DataReader&lt;/b&gt;) and loading stream data into a &lt;b&gt;DataTable&lt;/b&gt; cache. ADO.NET 2.0 also offers greater control over the state of rows in a &lt;b&gt;DataTable&lt;/b&gt;, in order to better address more real-world scenarios.&lt;/p&gt;  &lt;p style="font-family: times new roman;"&gt;&lt;b&gt;Thanks &lt;/b&gt;to Mayank nagar, Kawarjit S. Bedi, Pablo Castro, Alan Griver, Steve Lasker, and Paul Yuknewicz of Microsoft for their help in preparing this article.&lt;/p&gt;&lt;p style="font-family: times new roman;" class="MsoNormal"&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-5095303321522425561?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/5095303321522425561/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=5095303321522425561' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/5095303321522425561'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/5095303321522425561'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2008/08/new-dataset-features-in-adonet-20.html' title='New DataSet Features in ADO.NET 2.0'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8280997523505047385.post-6619034074620137552</id><published>2008-08-08T09:05:00.001-07:00</published><updated>2008-08-08T09:08:58.066-07:00</updated><title type='text'>CODE ACCESS SECURITY</title><content type='html'>&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;    &lt;h2&gt;Contents&lt;/h2&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Introduction"&gt;Introduction&lt;/a&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Jargon"&gt;Jargon&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Quick%20Example"&gt;Quick Example&lt;/a&gt;      &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Functions%20of%20Code%20Access%20Security"&gt;Functions      of Code Access Security&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Security%20Namespace"&gt;Security      Namespace&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Declarative%20vs%20Imperative"&gt;Declarative      vs. Imperative&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Security%20Demands"&gt;Security      Demands&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Requesting%20Permissions"&gt;Requesting      Permissions&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Overriding%20Security"&gt;Overriding      Security&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Calculating%20Permissions"&gt;Calculating      Permissions&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Tools"&gt;Tools&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#Summary"&gt;Summary&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;&lt;a href="http://www.codeproject.com/KB/security/#History"&gt;History&lt;/a&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;h2&gt;Introduction&lt;/h2&gt;  &lt;p&gt;Over the past years, I've learned many things from CodeProject ... and now I'm giving back to the CodeProject. Since I didn't find any articles on Code Access Security, here's my one. Enjoy!&lt;/p&gt;  &lt;p&gt;I'm not going to bore you with theory, but before we wet our feet, there are some concepts, keywords that you should learn. .NET has two kinds of security:&lt;/p&gt;  &lt;ol start="1" type="1"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Role Based Security&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; (not being discussed in this      article) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Code Access Security&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Restrict what your code can      do&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Restrict which code can call      your code&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Identify code&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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 jargon.&lt;/p&gt;  &lt;h2&gt;Jargon&lt;/h2&gt;  &lt;p&gt;Code access security consists of the following elements:&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;permissions&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;permission sets&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;code groups&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;evidence&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;policy&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FileIOPermission&lt;/span&gt;&lt;/code&gt; (when working with files), &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt; (permission to use a user interface), &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SecurityPermission&lt;/span&gt;&lt;/code&gt; (this is needed to execute the code and can be even used to bypass security) etc. I won't list all the permission classes here, they are listed below.&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FileIOPermission&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt; into your own permission set and call it "&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;My_PermissionSet&lt;/span&gt;&lt;/code&gt;". A permission set can include any number of permissions. &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FullTrust&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;LocalIntranet&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Internet&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Execution&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Nothing&lt;/span&gt;&lt;/code&gt; are some of the built in permission sets in .NET Framework. &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FullTrust&lt;/span&gt;&lt;/code&gt; has all the permissions in the world, while &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Nothing&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;My_Computer_Zone&lt;/span&gt;&lt;/code&gt;&lt;b&gt;, &lt;/b&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;LocalIntranet_Zone&lt;/span&gt;&lt;/code&gt;&lt;b&gt;, &lt;/b&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Internet_Zone&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Site&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Strong Name&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Zone&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;URL&lt;/span&gt;&lt;/code&gt; are some of the types of evidence.&lt;/p&gt;  &lt;h4&gt;Policy&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Enterprise&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Machine&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;User&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Application Domain&lt;/span&gt;&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;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="_x0000_i1025" type="#_x0000_t75" alt="" style="'width:414.75pt;"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image001.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/Policy.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image001.gif" shapes="_x0000_i1025" border="0" height="222" width="553" /&gt;&lt;!--[endif]--&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;Quick Example&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.IO&lt;/span&gt;&lt;/code&gt; namespace.&lt;/p&gt;  &lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.IO;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1026" type="#_x0000_t75" alt="" style="'width:258pt;height:174pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image002.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/Example1_1.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image002.gif" shapes="_x0000_i1026" border="0" height="232" width="344" /&gt;&lt;!--[endif]--&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&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; btnWrite_click(&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; sender, System.EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{ &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;StreamWriter myFile = &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; StreamWriter(&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"c:\\Security.txt"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;myFile.WriteLine(&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"Trust No One"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;myFile.Close();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; btnRead_click(&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; sender, System.EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{ &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;StreamReader myFile = &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; StreamReader(&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"c:\\Security.txt"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;MessageBox.Show(myFile.ReadLine())&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;myFile.Close()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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&gt;&lt;span style="color: black;" lang="CS"&gt;[assembly: AssemblyVersion(&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"1.0.0.0"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1027" type="#_x0000_t75" alt="" style="'width:318.75pt;height:295.5pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image003.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_1.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image003.gif" shapes="_x0000_i1027" border="0" height="394" width="425" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Enterprise&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Machine&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;User&lt;/span&gt;&lt;/code&gt;. We are going to change the security settings in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Machine&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyPermissionSet&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;  &lt;p&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1028" type="#_x0000_t75" alt="" style="'width:359.25pt;height:345pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image004.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_2.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image004.gif" shapes="_x0000_i1028" border="0" height="460" width="479" /&gt;&lt;!--[endif]--&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1029" type="#_x0000_t75" alt="" style="'width:412.5pt;height:213.75pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image005.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_3.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image005.gif" shapes="_x0000_i1029" border="0" height="285" width="550" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyPermissionSet&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyCodeGroup&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;  &lt;p&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1030" type="#_x0000_t75" alt="" style="'width:412.5pt;height:211.5pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image006.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_4.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image006.gif" shapes="_x0000_i1030" border="0" height="282" width="550" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyPermissionSet&lt;/span&gt;&lt;/code&gt;, select it from the list box.&lt;/p&gt;  &lt;p&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1031" type="#_x0000_t75" alt="" style="'width:412.5pt;height:195pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image007.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_5.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image007.gif" shapes="_x0000_i1031" border="0" height="260" width="550" /&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Figure 7&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Exclusive and LevelFinal&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;My_Computer_Zone&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyPermissionSet&lt;/span&gt;&lt;/code&gt; associated with the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyCodeGroup&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Exclusive&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;LevelFinal&lt;/span&gt;&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1032" type="#_x0000_t75" alt="" style="'width:302.25pt;height:332.25pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image008.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_6.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image008.gif" shapes="_x0000_i1032" border="0" height="443" width="403" /&gt;&lt;!--[endif]--&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1033" type="#_x0000_t75" alt="" style="'width:333pt;height:141.75pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image009.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ErrorMessage_1.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image009.gif" shapes="_x0000_i1033" border="0" height="189" width="444" /&gt;&lt;!--[endif]--&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;Functions of Code Access Security&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Grants permissions&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; to each assembly that is      loaded, based on the permissions requested by the code and on the      operations permitted by security policy. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Enforces restrictions&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Security&lt;/span&gt;&lt;/code&gt;, which is dedicated to implementing security.&lt;/p&gt;  &lt;h2&gt;Security Namespace&lt;/h2&gt;  &lt;p&gt;These are the main classes in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Security&lt;/span&gt;&lt;/code&gt; namespace:&lt;/p&gt;  &lt;table style="width: 76%;" border="1" cellpadding="0" width="76%"&gt;  &lt;tbody&gt;&lt;tr style="height: 6pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 6pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Classes&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 6pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Description&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;CodeAccessPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Defines the underlying structure of   all code access permissions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;PermissionSet&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Represents a collection that can   contain many different types of permissions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SecurityException&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;The exception that is thrown when a   security error is detected.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;These are the main classes in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Security.Permissions&lt;/span&gt;&lt;/code&gt; namespace:&lt;/p&gt;  &lt;table style="width: 76%;" border="1" cellpadding="0" width="76%"&gt;  &lt;tbody&gt;&lt;tr style="height: 6pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 6pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Classes&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 6pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Description&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;EnvironmentPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Controls access to system and user   environment variables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FileDialogPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Controls the ability to access files   or folders through a file dialog.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FileIOPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Controls the ability to access files   and folders.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;IsolatedStorageFilePermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Specifies the allowed usage of a   private virtual file system.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;IsolatedStoragePermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Represents access to generic isolated   storage capabilities.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ReflectionPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Controls access to metadata through   the &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Reflection&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt; APIs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RegistryPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Controls the ability to access   registry variables.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SecurityPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Describes a set of security   permissions applied to code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style="height: 0.75pt;"&gt;   &lt;td style="padding: 0.75pt; width: 32%; height: 0.75pt;" width="32%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt; width: 68%; height: 0.75pt;" width="68%"&gt;   &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;Controls the permissions related to   user interfaces and the clipboard.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SocketPermission&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;WebPermission&lt;/span&gt;&lt;/code&gt; in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Net&lt;/span&gt;&lt;/code&gt; namespace, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SqlClientPermission&lt;/span&gt;&lt;/code&gt; in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Data.SqlClient&lt;/span&gt;&lt;/code&gt; namespace, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;PerformanceCounterPermission&lt;/span&gt;&lt;/code&gt; in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;System.Diagnostics&lt;/span&gt;&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;Declarative vs. Imperative&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&gt;&lt;span style="color: black;" lang="CS"&gt;[FileIOPermission(SecurityAction.Demand, Unrestricted=true)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; calss MyClass &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyClass() {...}&lt;span style=""&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// all these methods&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyMethod_A() {...} &lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// demands unrestricted access to &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyMethod_B() {...} &lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// the file system&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; calss MyClass &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyClass() { }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; Method_A() &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Do Something&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;FileIOPermission myPerm = &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;          &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; FileIOPermission(PermissionState.Unrestricted);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;span style=""&gt;      &lt;/span&gt;myPerm.Demand(); &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// rest of the code won't get executed if this failed&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Do Something&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// No demands&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; Method_B()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Do Something&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1034" type="#_x0000_t75" alt="" style="'width:225pt;height:209.25pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image010.jpg" href="http://www.codeproject.com/KB/security/UB_CAS_NET/diagram1.jpg"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image010.jpg" shapes="_x0000_i1034" border="0" height="279" width="300" /&gt;&lt;!--[endif]--&gt;&lt;/p&gt;  &lt;p&gt;First, let's see how we can use the declarative syntax. Take the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt; class. Declarative syntax means using attributes. So we are actually using the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermissionAttribute&lt;/span&gt;&lt;/code&gt; class. When you refer to the MSDN documentation, you can see these public properties:&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Action&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - one of the values in &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SecurityAction&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;" lang="CS"&gt;enum&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;      (common) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Unrestricted&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - unrestricted access to the      resource (common) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Clipboard&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - type of access to the      clipboard, one of the values in &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermissionClipboard&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;" lang="CS"&gt;enum&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;      (&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; specific) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Window&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - type of access to the      window, one of the values in &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermissionWindow&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;" lang="CS"&gt;enum&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;      (&lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; specific). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Action&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Unrestricted&lt;/span&gt;&lt;/code&gt; properties are common to all permission classes. &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Clipboard&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Window&lt;/span&gt;&lt;/code&gt; properties are specific to &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&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&gt;&lt;span style="color: black;" lang="CS"&gt;[UIPermission(SecurityAction.Demand,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;Clipboard=UIPermissionClipboard.AllClipboard)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;or with both &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Clipboard&lt;/span&gt;&lt;/code&gt; and &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Window&lt;/span&gt;&lt;/code&gt; properties:&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;[UIPermission(SecurityAction.Demand,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;Clipboard=UIPermissionClipboard.AllClipboard, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;Window=UIPermissionWindow.AllWindows)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&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&gt;&lt;span style="color: black;" lang="CS"&gt;[UIPermission(SecurityAction.Demand, Unrestricted=true)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RegistryPermission&lt;/span&gt;&lt;/code&gt; class.&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;RegistryPermission myRegPerm = &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; RegistryPermission(RegistryPermissionAccess.AllAccess,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"HKEY_LOCAL_MACHINE\\Software"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;myRegPerm.Demand();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;If you want unrestricted access to the resource, you can use &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;PermissionState&lt;/span&gt;&lt;/code&gt; &lt;span class="code-keyword1"&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;" lang="CS"&gt;enum&lt;/span&gt;&lt;/span&gt; in the following way:&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;RegistryPermission myRegPerm = &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;  &lt;/span&gt;RegistryPermission(PermissionState.Unrestricted);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;myRegPerm.Demand();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&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;Security Demands&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SecurityException&lt;/span&gt;&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1035" type="#_x0000_t75" alt="" style="'width:379.5pt;height:154.5pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image011.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/StackWalk.GIF"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image011.gif" shapes="_x0000_i1035" border="0" height="206" width="506" /&gt;&lt;!--[endif]--&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Demand&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Link Demand&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Inheritance Demand&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.Security;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.Security.Permissions;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;Add another button to the existing form.&lt;/p&gt;  &lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; btnFileRead_Click(&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; sender, System.EventArgs e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;try&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;InitUI(&lt;/span&gt;&lt;span class="code-digit1"&gt;&lt;span style="" lang="CS"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;); &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; (SecurityException err)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;MessageBox.Show(err.Message,&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"Security Error"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;catch&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; (Exception err)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;MessageBox.Show(err.Message,&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"Error"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;InitUI&lt;/span&gt;&lt;/code&gt; just calls the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ShowUI&lt;/span&gt;&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&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Access is denied for this function to read from C: drive&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Note: Using declrative syntax&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;[FileIOPermission(SecurityAction.Deny,Read=&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"C:\\")]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;private void InitUI(int uino)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;// Do some initializations&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;ShowUI(uino);&lt;span style=""&gt;    &lt;/span&gt;// call ShowUI&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ShowUI&lt;/span&gt;&lt;/code&gt; function takes &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;uino&lt;/span&gt;&lt;/code&gt; in and shows the appropriate UI.&lt;/p&gt;  &lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; ShowUI(&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; uino)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;switch&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; (uino)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;case&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-digit1"&gt;&lt;span style="" lang="CS"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;: &lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// That's our FileRead UI&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;ShowFileReadUI();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;break&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;case&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-digit1"&gt;&lt;span style="" lang="CS"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Show someother UI&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;break&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;;&lt;span style=""&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ShowFileReadUI&lt;/span&gt;&lt;/code&gt; shows the UI related to reading files.&lt;/p&gt;  &lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; ShowFileReadUI()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;MessageBox.Show(&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"Before calling demand"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;FileIOPermission myPerm = &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;FileIOPermission(FileIOPermissionAccess.Read, &lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"C:\\");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;myPerm.Demand();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;       &lt;/span&gt;// All callers must have read permission to C: drive&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;// Note: Using imperative syntax&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;// code to show UI&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;MessageBox.Show("&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;Showing FileRead UI&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;// This is excuted if only the Demand is successful.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1036" type="#_x0000_t75" alt="" style="'width:310.5pt;height:203.25pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image012.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/StackWalk_2.GIF"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image012.gif" shapes="_x0000_i1036" border="0" height="271" width="414" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;InitUI&lt;/span&gt;&lt;/code&gt; method. So when &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ShowFileReadUI&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Deny&lt;/span&gt;&lt;/code&gt; statement in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;InitUI&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;StreamReader&lt;/span&gt;&lt;/code&gt; class. &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;StreamReader&lt;/span&gt;&lt;/code&gt; automatically demands &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;FileIOPermission&lt;/span&gt;&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&gt;&lt;span style="color: black;" lang="CS"&gt;[FileIOPermission(SecurityAction.LinkDemand,Read=&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"C:\\")]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;private void MyMethod()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;// Do Something &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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&gt;&lt;span style="color: black;" lang="CS"&gt;[SecurityPermission(SecurityAction.InheritanceDemand)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyClass()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// what ever&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyClass()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyClass() {}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;[SecurityPermission(SecurityAction.InheritanceDemand)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;virtual&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; MyMethod()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Do something&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;Requesting Permissions&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;RequestMinimum&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;RequestOptional&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;RequestRefuse&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestMinimum&lt;/span&gt;&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&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.Windows.Forms;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.IO;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.Security;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; System.Security.Permissions;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// placed in assembly level&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// using declarative syntax&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;[assembly:RegistryPermission(SecurityAction.RequestMinimum, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;         &lt;/span&gt;Write=&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"HKEY_LOCAL_MACHINE\\Software"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;)]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; SecurityApp&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Rest of the implementation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;h3&gt;RequestOptional&lt;/h3&gt;  &lt;p&gt;Using &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestOptional&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestOptional&lt;/span&gt;&lt;/code&gt;.&lt;/p&gt;  &lt;p&gt;If you use &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestOptional&lt;/span&gt;&lt;/code&gt; with &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestMinimum&lt;/span&gt;&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&gt;&lt;span style="color: black;" lang="CS"&gt;[assembly:FileIOPermission(SecurityAction.RequestMinimum, Read=&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"C:\\")]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;[assembly:FileIOPermission(SecurityAction.RequestOptional, Write="&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;C:\\&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;")]&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;UIPermission&lt;/span&gt;&lt;/code&gt;, it is not granted to this assembly.&lt;/p&gt;  &lt;p&gt;Note that, like &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestMinimum&lt;/span&gt;&lt;/code&gt;, &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestOptional&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RequestRefuse&lt;/span&gt;&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&gt;&lt;span style="color: black;" lang="CS"&gt;[assembly:FileIOPermission(SecurityAction.RequestRefuse, Write=&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"C:\\")]&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;h2&gt;Overriding Security&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;b&gt;&lt;i&gt;stack walk modifiers&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Assert&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Deny&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;PermitOnly&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;h3&gt;Assert&lt;/h3&gt;  &lt;p&gt;You can call the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&lt;/code&gt; are not checked. If you can trust the upstream callers, then using &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&lt;/code&gt; would do no harm. You can use the previous example to test this. Modify the code in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ShowUI&lt;/span&gt;&lt;/code&gt; method, just add the two new lines shown below:&lt;/p&gt;  &lt;pre&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; ShowUI(&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; uino)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// using imperative syntax to create a instance of FileIOPermission&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;FileIOPermission myPerm = &lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;      &lt;/span&gt;FileIOPermission(FileIOPermissionAccess.Read, &lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"C:\\");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;myPerm.Assert();&lt;span style=""&gt;    &lt;/span&gt;// don't check above stack frames.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;switch (uino)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;case 1: // That's our FileRead UI&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;ShowFileReadUI();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;case 2:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;// Show someother UI&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;            &lt;/span&gt;break;&lt;span style=""&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;&lt;span style=""&gt;    &lt;/span&gt;CodeAccessPermission.RevertAssert();&lt;span style=""&gt;    &lt;/span&gt;// cancel assert&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;Make sure that the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Deny&lt;/span&gt;&lt;/code&gt; statement is still there in &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;InitUI&lt;/span&gt;&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1037" type="#_x0000_t75" alt="" style="'width:248.25pt;height:203.25pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image013.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/StackWalk_3.GIF"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image013.gif" shapes="_x0000_i1037" border="0" height="271" width="331" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;InitUI&lt;/span&gt;&lt;/code&gt; doesn't have the demanded permission, it is never checked because the stack walk stops from &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;ShowUI&lt;/span&gt;&lt;/code&gt;. Look at the last line. &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RevertAssert&lt;/span&gt;&lt;/code&gt; is a static method of &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;CodeAccessPermission&lt;/span&gt;&lt;/code&gt;. It is used after an &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&lt;/code&gt; to cancel the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&lt;/code&gt; statement. So if the code below &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RevertAssert&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&lt;/code&gt; for the current stack frame, then &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RevertAssert&lt;/span&gt;&lt;/code&gt; has no effect. It is a good practice to place the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RevertAssert&lt;/span&gt;&lt;/code&gt; in a &lt;span class="code-keyword1"&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;" lang="CS"&gt;finally&lt;/span&gt;&lt;/span&gt; block, so it will always get called.&lt;/p&gt;  &lt;p&gt;Note that to use &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assert&lt;/span&gt;&lt;/code&gt;, the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Assertion&lt;/span&gt;&lt;/code&gt; flag of the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;SecurityPermission&lt;/span&gt;&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&gt;&lt;span style="color: black;" lang="CS"&gt;WebPermission myWebPermission = &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; WebPermission(NetworkAccess.Connect, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;span style=""&gt;       &lt;/span&gt;&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"http://www.somewebsite.com"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;myWebPermission.Deny();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Do some work&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;CodeAccessPermission.RevertDeny(); &lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// cancel Deny&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;RevertDeny&lt;/span&gt;&lt;/code&gt; is used to remove a previous &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Deny&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;PermitOnly&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;PermitOnly&lt;/span&gt;&lt;/code&gt; is used, it means only the resources you specify can be accessed.&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;WebPermission myWebPermission = &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="code-keyword1"&gt;&lt;span style="" lang="CS"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt; WebPermission(NetworkAccess.Connect, &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span class="code-string1"&gt;&lt;span style="" lang="CS"&gt;"http://www.somewebsite.com"&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;myWebPermission.PermitOnly();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// Do some work&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;!--[if !supportEmptyParas]--&gt; &lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color: black;" lang="CS"&gt;CodeAccessPermission.PermitOnly(); &lt;/span&gt;&lt;span class="code-comment1"&gt;&lt;span style="" lang="CS"&gt;// cancel PermitOnly&lt;/span&gt;&lt;/span&gt;&lt;span style="color: black;" lang="CS"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;  &lt;p&gt;You can use &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;PermitOnly&lt;/span&gt;&lt;/code&gt; instead of &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Deny&lt;/span&gt;&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;Calculating Permissions&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 start="1" type="1"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1038" type="#_x0000_t75" alt="" style="'width:180.75pt;height:150.75pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image014.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/Grant.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image014.gif" shapes="_x0000_i1038" border="0" height="201" width="241" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Machine&lt;/span&gt;&lt;/code&gt; policy level. Hope it makes sense by now.&lt;/p&gt;  &lt;p&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1039" type="#_x0000_t75" alt="" style="'width:302.25pt;height:332.25pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image015.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/All_Code.gif"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image015.gif" shapes="_x0000_i1039" border="0" height="443" width="403" /&gt;&lt;!--[endif]--&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Exclusive&lt;/span&gt;&lt;/code&gt; or &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;LevelFinal&lt;/span&gt;&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;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Exclusive&lt;/span&gt;&lt;/code&gt; attribute for our code group - &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;MyCodeGroup&lt;/span&gt;&lt;/code&gt; in the earlier &lt;a href="http://www.codeproject.com/KB/security/#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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Exclusive&lt;/span&gt;&lt;/code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; -&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; The permissions with the      code group marked as &lt;/span&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Exclusive&lt;/span&gt;&lt;/code&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;LevelFinal&lt;/span&gt;&lt;/code&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; -&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; &lt;a href="http://www.codeproject.com/KB/security/#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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;Now you should have a clear understanding why we set the &lt;code&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Courier New&amp;quot;;"&gt;Exclusive&lt;/span&gt;&lt;/code&gt; attribute earlier.&lt;/p&gt;  &lt;h2&gt;Nice Features in .NET Configuration Tool&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1040" type="#_x0000_t75" alt="" style="'width:325.5pt;height:226.5pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image016.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/ConfigTool_7.GIF"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image016.gif" shapes="_x0000_i1040" border="0" height="302" width="434" /&gt;&lt;!--[endif]--&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Evaluate Assembly&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - This can be used to find      out which code group(s) a particular assembly belongs to, or which      permissions it has. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;Create Deployment Package&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;h2&gt;Tools&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;i&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;permview SecurityApp.exe&lt;/span&gt;&lt;/i&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - Displays the permissions      requested by the assembly &lt;i&gt;SecurityApp.exe&lt;/i&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&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;!--[if gte vml 1]&gt;&lt;v:shape id="_x0000_i1041" type="#_x0000_t75" alt="" style="'width:412.5pt;height:273.75pt'"&gt;  &lt;v:imagedata src="file:///C:/DOCUME~1/mayank/LOCALS~1/Temp/msoclip1/01/clip_image017.gif" href="http://www.codeproject.com/KB/security/UB_CAS_NET/Cmd.GIF"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/mayank/LOCALS%7E1/Temp/msoclip1/01/clip_image017.gif" shapes="_x0000_i1041" border="0" height="365" width="550" /&gt;&lt;!--[endif]--&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 type="disc"&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;caspol -listgroups&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - Displays the code groups &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;caspol -machine -addgroup 1.      -zone Internet Execution&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;caspol -user -chggroup 1.2.      Execution&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&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;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="color: black;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt;caspol -security on&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana;"&gt; - Turns code access security      on. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt;caspol -security off&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: black;"&gt; - Turns code access security off. &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8280997523505047385-6619034074620137552?l=mayanknagar.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mayanknagar.blogspot.com/feeds/6619034074620137552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8280997523505047385&amp;postID=6619034074620137552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/6619034074620137552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8280997523505047385/posts/default/6619034074620137552'/><link rel='alternate' type='text/html' href='http://mayanknagar.blogspot.com/2008/08/code-access-security.html' title='CODE ACCESS SECURITY'/><author><name>mayank nagar</name><uri>http://www.blogger.com/profile/05941327743220090036</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/-ZrUpViz65V8/Tdi4eLiUyOI/AAAAAAAAACM/rUiF460W814/s220/Photo0252.jpg'/></author><thr:total>0</thr:total></entry></feed>
