<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-1850047779793623762</atom:id><lastBuildDate>Thu, 28 Jul 2011 21:00:22 +0000</lastBuildDate><title>DotNetIdeas</title><description>.NET Framework/Compact Framework and SharePoint Programming Tips and Tricks</description><link>http://dotnetideasblog.blogspot.com/</link><managingEditor>noreply@blogger.com (DotNetIdeas)</managingEditor><generator>Blogger</generator><openSearch:totalResults>50</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-792165452202514980</guid><pubDate>Fri, 13 Aug 2010 21:45:00 +0000</pubDate><atom:updated>2010-08-13T14:45:27.756-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Avoid Polluting SharePoint farm</title><description>&lt;p&gt;A developer can easily pollute a SharePoint farm by exposing components to unintended audience as the following.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In MOSS, you cannot target a feature to a specific site, site collection or web application. A deployed feature is visible to SharePoint administrators everywhere in the SharePoint Farm even though the feature should be used in a very specific context.&lt;/li&gt;    &lt;li&gt;Deploying a Dll to GAC makes the Dll fully trusted and accessible to the entire server. Any code running on the server may use the Dll.&lt;/li&gt;    &lt;li&gt;A user control deployed to the ControlTemplates directory can be used by any ASP.NET components deployed to the farm.&lt;/li&gt;    &lt;li&gt;An application page deployed to the Layouts directory is visible to end users from any SharePoint site in the Farm. Most importantly, you cannot manage the security permission on the Page easily. The page will observe the default security permission for all the pages in Layouts directory. Also, the code behind dll for an application page has to have full trust since everything in Layout has full trust. This violates the basic security principle. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Item 4 will do the most damage since end users will see the pollution right way and it is not easy to apply security to the page to fix it. Item 1 will only affect SharePoint administrators. Item 2 and 3 will affect developers and infrastructure team.&lt;/p&gt;  &lt;p&gt;However, Item 4 is the least aware among developers since it is just so easy.&lt;/p&gt;  &lt;p&gt;An alternative to create an application page is to deploy the page to a document library in the site needing the page. Because it is in a document library, you can apply different security policies to the page. So only the right people can access the page with the right permissions. Also, the code behind dll of it can be deployed to bin directory without full trust since it is not in Layouts directory. Obviously, this approach solves all the issues listed in Item 4.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-792165452202514980?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2010/08/avoid-polluting-sharepoint-farm.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-4637016794010696104</guid><pubDate>Wed, 11 Aug 2010 21:53:00 +0000</pubDate><atom:updated>2010-08-11T14:53:42.199-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Others</category><title>ComponentOne 2.x upgrade issues</title><description>&lt;p&gt;We&amp;#160; have been using ComponentOne 1.x for quite some time. We used C1PrintDocument to merge some RTF templates and generate PDF document. Recently we planed to upgrade our server to 64-bit machine. When we tested out the ComponentOne PDF generation code, we kept getting &amp;quot;Attempted to read or write protected memory. This is often an indication that other memory is corrupt&amp;quot; error. After upgrade to ComponentOne 2.x, that issue is gone. However, we ran into several other issues. When I re-compile the code after the upgrade, a lot of syntax do not work anymore. Some of them are easy to fix, but some of the deprecated functions are not that easy to replace since they no longer exist in the package. There are the changes I want to document here:&lt;/p&gt;  &lt;p&gt;1. &amp;quot;Page [@@PageNo@@] of [@@PageCount@@]&amp;quot;&lt;/p&gt;  &lt;p&gt;If you have used the code above, you have to add the following code now in order to use them:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;c1PrintDocument1.TagOpenParen = &lt;span style="color: #006080"&gt;&amp;quot;[@@&amp;quot;&lt;/span&gt;;
c1PrintDocument1.TagCloseParen = &lt;span style="color: #006080"&gt;&amp;quot;@@]&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;2. Table border style&lt;/p&gt;

&lt;p&gt;from:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;RenderTable headerTable = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RenderTable(c1PrintDocument1);
headerTable.Style.Borders.AllEmpty = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
headerTable.StyleTableCell.BorderTableHorz.Empty = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
headerTable.StyleTableCell.BorderTableVert.Empty = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;RenderTable headerTable = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RenderTable(c1PrintDocument1);
headerTable.Style.Borders.All = LineDef.Empty;
headerTable.Style.GridLines.All = LineDef.Empty;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;3. Page Header/Footer&lt;/p&gt;

&lt;p&gt;from:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;c1PrintDocument1.PageHeader.RenderObject = headerTable;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;c1PrintDocument1.PageLayouts.Default.PageHeader = headerTable;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;4. Check remaining space&lt;/p&gt;

&lt;p&gt;from:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;RenderRichText obj = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RenderRichText(c1PrintDocument1);
obj = ...;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (c1PrintDocument1.AvailableBlockFlowHeight &amp;lt; c1PrintDocument1.MeasureBlock(obj).Height) 
    c1PrintDocument1.NewPage();&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;RenderRichText obj = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RenderRichText(c1PrintDocument1);
SizeD objSize = obj.CalcSize(&lt;span style="color: #006080"&gt;&amp;quot;2in&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;auto&amp;quot;&lt;/span&gt;);
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (c1PrintDocument1.AvailableBlockFlowHeight &amp;lt; objSize.Height) 
    c1PrintDocument1.NewPage();&lt;/pre&gt;
&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-4637016794010696104?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2010/08/componentone-2x-upgrade-issues.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8886743894361413238</guid><pubDate>Wed, 24 Feb 2010 18:00:00 +0000</pubDate><atom:updated>2010-04-12T14:44:22.104-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Access external data in SharePoint with BDC (business data catalog), SSO (Single Sign On) and WCF (Windows Communication foundation)</title><description>&lt;pre class="csharpcode"&gt;&amp;#160;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/S4VpHb_N1pI/AAAAAAAAAgU/WqMdS39DTO4/s1600-h/image4.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="193" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/S4VpHnYh-TI/AAAAAAAAAgY/kurQEtad0hs/image_thumb2.png?imgmax=800" width="554" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;High Level Summary&lt;/h3&gt;

&lt;p&gt;Accessing external systems from SharePoint portals is a typical integration scenario. One reality that has not changed is that there are three basic components to any interoperability scheme.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;b&gt;Communication&lt;/b&gt;&amp;#8211;You must be able to connect and communicate with the foreign system, either through code or through infrastructure. &lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Identity Management&lt;/b&gt;&amp;#8211;You must have some way to authenticate users against the foreign system. &lt;/li&gt;

  &lt;li&gt;&lt;b&gt;Composition&lt;/b&gt;&amp;#8211;You must be able to assemble discrete pieces of data (from tables, function calls, and so on) into an entity that is meaningful and useful to business users. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are challenges in all three of these activities, regardless of what you are connecting. &lt;/p&gt;

&lt;p&gt;The architecture tackles the four issues elegantly. WCF provides the communication. Single Sign On provides the Identity management. Business data catalog allows different ways to compose such as DataViewWebPart, BDC object model, search and out-of-box BDC web parts. &lt;/p&gt;

&lt;p&gt;Comparing with directly accessing WCF web service, my favorite&amp;#160; argument to support this architecture is that BDC is a layer of security boundary in addition to its support to search. BDC allows you to authorize the access to BDC entities through Shared Service web pages. With direct WCF access, there is no easy way to achieve this level of seamless integration and flexibility to control the authorization. &lt;/p&gt;

&lt;p&gt;Another advantage of this architecture is to let BDC access external data through SSO, which allows the management of&amp;#160; identities in SharePoint central admin web pages. Invoking WCF or Web Service directly from code will run into the famous double hop issue in a distributed environment unless you hard code the user credentials.&amp;#160; The matter will be even more complicated if you use SharePoint&amp;#160; Form Authentication. BDC has very nice integration with SSO so it is a very nature approach to marry those two technologies together for accessing external data.&lt;/p&gt;

&lt;h3&gt;Implementation Details&lt;/h3&gt;

&lt;p&gt;Notice, it is not a step by step tutorial. Instead, it covers important ideas and possible catches during implementation.&lt;/p&gt;

&lt;h4&gt;Tools&lt;/h4&gt;

&lt;ol&gt;
  &lt;li&gt;Visual Studio 2008 for WCF development &lt;/li&gt;

  &lt;li&gt;Microsoft Application Definition Designer for BDC definition. &lt;/li&gt;

  &lt;li&gt;Microsoft MOSS server for SSO and BDC configuration &lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h4&gt;Ideas/Catches&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;h5&gt;Use BDC to control the authorization. In the home page of the ShareService administration web site, you will see the &amp;#8220;Business data catalog permission&amp;#8221; at the bottom-right corner as the following &lt;/h5&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/S4VpH1NNz9I/AAAAAAAAAgc/RfflAsDWlWo/s1600-h/image7.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="150" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/S4VpIBw4R6I/AAAAAAAAAgg/t8j1MKzZvyg/image_thumb3.png?imgmax=800" width="235" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;h5&gt;Use WCF to encapsulate your external system. BDC supports &amp;#8220;basichttpbinding&amp;#8221; only. The following is a sample web.config. Here is one of the biggest catch. If running the WCF inside VS2008, use &amp;#8220;NTLM&amp;#8221;. After deploying the WCF to production, use &amp;#8220;Windows&amp;#8221;. It appears that VS2008 debug web server has different behavior in terms of WCF authentication. Also, in VS2008, you cannot test WCF authorization through [PrincipalPermission(SecurityAction.Demand, Name = &amp;#8220;&amp;#8221;)], it won&amp;#8217;t work.&lt;/h5&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;behaviorConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthorizationBehavior&amp;quot;&lt;/span&gt;
         &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;BDCContractImplementation&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt;   &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt; 
                &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthenticationBinding&amp;quot;&lt;/span&gt;
     &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;IBDCContract&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;identity&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;dns&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;host&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;identity&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
       &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthorizationBehavior&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceMetadata&lt;/span&gt; &lt;span class="attr"&gt;httpGetEnabled&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceDebug&lt;/span&gt; &lt;span class="attr"&gt;includeExceptionDetailInFaults&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceCredentials&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;windowsAuthentication&lt;/span&gt; &lt;span class="attr"&gt;includeWindowsGroups&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;allowAnonymousLogons&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;serviceCredentials&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
             &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;serviceAuthorization&lt;/span&gt; &lt;span class="attr"&gt;principalPermissionMode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;UseWindowsGroups&amp;quot;&lt;/span&gt;
                &lt;span class="attr"&gt;impersonateCallerForAllOperations&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behavior&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;serviceBehaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;behaviors&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;basicHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WindowsAuthenticationBinding&amp;quot;&lt;/span&gt; 
                 &lt;span class="attr"&gt;maxBufferSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2147483647&amp;quot;&lt;/span&gt;
                 &lt;span class="attr"&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;2147483647&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt; &lt;span class="attr"&gt;mode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;TransportCredentialOnly&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;transport&lt;/span&gt; &lt;span class="attr"&gt;clientCredentialType&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Ntlm&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;&amp;lt;!-- works in VS2008 debug --&amp;gt;&lt;/span&gt;
            &lt;span class="rem"&gt;&amp;lt;!--&amp;lt;transport clientCredentialType=&amp;quot;Windows&amp;quot; /&amp;gt; --&amp;gt;&lt;/span&gt; &lt;span class="rem"&gt;&amp;lt;!-- works after deploying to IIS --&amp;gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;security&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;basicHttpBinding&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;bindings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;ul&gt;
  &lt;h6&gt;&lt;/h6&gt;

  &lt;ul&gt;&lt;/ul&gt;

  &lt;li&gt;
    &lt;h5&gt;The catch of the return value from IDEnumerator in BDC. If the ID is of type string, you can not return list&amp;lt;string&amp;gt; from IDEnumerator. You must implement a simple class to encapsulate the ID; otherwise, for some reason, Microsoft Application Definition Designer won&amp;#8217;t able to handle the method&lt;/h5&gt;

    &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/* The small class to encapsulate the string */&lt;/span&gt;
[DataContract]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MeetingID
 {
        [DataMember]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; MeetingIDStr { get; set; }
 }
[ServiceContract]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IMeetingBDC
 {
        [OperationContract]
        List&amp;lt;Meeting&amp;gt; GetAllMeetings(&lt;span class="kwrd"&gt;string&lt;/span&gt; filter);
        [OperationContract]
        Meeting GetMeetingSpecificFinder(&lt;span class="kwrd"&gt;string&lt;/span&gt; meetingId);
        [OperationContract] &lt;span class="rem"&gt;/* the signature for IDEnumerator */&lt;/span&gt;
        List&amp;lt;MeetingID&amp;gt; GetMeetingIdEnumerator();
 }&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;&lt;/h6&gt;

&lt;ul&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

  &lt;li&gt;
    &lt;h5&gt;BDC configuration using SSO. Copy paste and modify the following code:&lt;/h5&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;LobSystemInstance&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;BDCMeeting_Instance&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;LobSystemName&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;LobMeeting&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WebServiceAuthenticationMode&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Microsoft.Office.Server.ApplicationRegistry.SystemSpecific.WebService.HttpAuthenticationMode&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;WindowsCredentials&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;SsoProviderImplementation&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Microsoft.SharePoint.Portal.SingleSignon.SpsSsoProvider, Microsoft.SharePoint.Portal.SingleSignon, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WebServiceSsoApplicationId&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;System.String&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;your_sso_application_id&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;LobSystemInstance&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;



.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8886743894361413238?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2010/02/access-external-data-in-sharepoint-with.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/S4VpHnYh-TI/AAAAAAAAAgY/kurQEtad0hs/s72-c/image_thumb2.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3316216189685171300</guid><pubDate>Mon, 16 Nov 2009 21:23:00 +0000</pubDate><atom:updated>2009-11-16T13:23:38.219-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Others</category><title>HTTP Error 401.1 - Unauthorized: Access is denied due to invalid credentials.</title><description>&lt;p&gt;We just experienced a problem with web services authentication. Two of our production servers suddenly failed to authenticate users. We kept getting the 401.1 error. We are using &amp;quot;digest authentication&amp;quot;. We had this issue before when we setup a new server. Rebooting the server fixed it. However, this time the trick didn't work. Finally, our administrator decided to remove the server from the domain and re-join it. That fixed the issue.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3316216189685171300?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/11/http-error-4011-unauthorized-access-is.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-7616627334976489679</guid><pubDate>Fri, 06 Nov 2009 21:09:00 +0000</pubDate><atom:updated>2009-11-06T13:10:25.987-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET Compact Framework</category><title>Provisioning Windows Mobile Devices</title><description>&lt;p&gt;Recently I worked on a project in which I need to create a configuration tool for windows mobile device, so it can setup the device ID, date/time, Network connection, Wi-Fi, etc. I used the windows mobile provisioning tool. There are more information on &lt;a href="http://msdn.microsoft.com/en-us/bb737536.aspx" target="_blank"&gt;MSDN&lt;/a&gt; web site on how to use it. I am not going to repeat that. However, I want to document the issues I ran into while implementing it. Hope this will help others.&lt;/p&gt;  &lt;p&gt;Note: The devices I was configuring are Intermec CN50 and Symbol MC75 with windows mobile 6 professional.&lt;/p&gt;  &lt;p&gt;To use the provisioning tool, you will create a XML file with the following format. It contains the things you want to configure.&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wap-provisioningdoc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Registry&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HKCU\ControlPanel\Owner&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceID]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Owner&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceIDBinary]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;datatype&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;binary&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wap-provisioningdoc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Then in your code you will load the XML into a XmlDocument variable and call ProcessConfiguration() &lt;/div&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;XmlDocument xd = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlDocument();
xd.LoadXml(XMLContent);
XmlDocument xdResult = ConfigurationManager.ProcessConfiguration(xd, &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;Setup Device ID&lt;/h4&gt;

&lt;p&gt;There is a &lt;a href="http://msdn.microsoft.com/en-us/bb737683.aspx" target="_blank"&gt;DeviceInformation Configuration Service Provider&lt;/a&gt;, but surprisingly I couldn't find how you would setup the device ID. So I used &lt;a href="http://msdn.microsoft.com/en-us/bb737304.aspx" target="_blank"&gt;Registry configuration service provider&lt;/a&gt; to update the registry.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wap-provisioningdoc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Registry&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HKCU\ControlPanel\Owner&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceID]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Owner&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceIDBinary]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;datatype&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;binary&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HKCU\Software\Microsoft\Bluetooth\Settings&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;LocalName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceID]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;datatype&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HKLM\Ident&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Name&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceID]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;datatype&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wap-provisioningdoc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Notice the [DeviceIDBinary] field? I didn't have that in there at first. But after changing the DeviceID, it didn't change the owner info displayed on the Today screen, even after a reboot. After researching the registry, I found out that I have to change the Owner field and that is a binary field. &lt;/p&gt;

&lt;p&gt;Also most of the time, you will need to specify the datatype. Otherwise you may get an error code 2147500037, or something like that.&lt;/p&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h4&gt;Set VPN connection&lt;/h4&gt;

&lt;p&gt;Using &lt;a href="http://msdn.microsoft.com/en-us/bb737433.aspx" target="_blank"&gt;CM_VPNEntries Configuration Service Provider&lt;/a&gt; to set VPN connection is very straight forward. Here is the sample XML. If you have more than one, you can set Enabled to 1 to make it default.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CM_VPNEntries&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;MyVPN&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SrcId&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{436EF144-B4FB-4863-A041-8F905A62C572}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DestId&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{A1182988-0D73-439e-87AD-2A5B369F808B}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Phone&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[MyIP]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;UserName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[UserName]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[Password]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Domain&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[MyDomain]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #008000"&gt;&amp;lt;!--Determins the type of authentication e.g. IPSec = 1 vs PPTP = 0--&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Type&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #008000"&gt;&amp;lt;!--Determins the type IPSec encryption, either pre shared key or cert based--&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IPSecAuth&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #008000"&gt;&amp;lt;!--pre shared key can be 256 chars long, but must be ASCII--&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;PresharedKey&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[NetworkKey]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Enabled&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;Wi-Fi configuration&lt;/h4&gt;

&lt;p&gt;The XML to configure Wi-Fi is simple, just follow &lt;a href="http://msdn.microsoft.com/en-us/bb737539.aspx" target="_blank"&gt;Wi-Fi Configuration Service Provider&lt;/a&gt;. However, there are a couple of things worth mention. First, we need to turn on Wi-Fi before apply the XML file, otherwise it will throw a error code. Second, this only worked for Intermec device. The Symbol device has its own way configuring Wi-Fi. I have to export their setting and use &lt;a href="http://msdn.microsoft.com/en-us/bb737304.aspx" target="_blank"&gt;Registry configuration service provider&lt;/a&gt; to configure it.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Wi-Fi&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;access-point&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[MyAccessPointName]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DestId&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{436EF144-B4FB-4863-A041-8F905A62C572}&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Encryption&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Authentication&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Hidden&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;KeyProvided&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;NetworkKey&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[NetworkKey]&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;KeyIndex&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Use8021x&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;Add URL Exceptions&lt;/h4&gt;

&lt;p&gt;To add URL Exceptions in the screen showed here, use the following XML.&lt;/p&gt;

&lt;h4&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/SvSQfxuDpVI/AAAAAAAAAbA/P1TI6otmsn8/image%5B2%5D.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SvSQgNaeHVI/AAAAAAAAAbE/NAEU2_DOwRs/image_thumb.png" width="185" border="0" /&gt;&lt;/a&gt;&lt;/h4&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CM_Mappings&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;16842751&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Pattern&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;http://*/*&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Network&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{A1182988-0D73-439E-87AD-2A5B369F808B}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;GPRS configuration&lt;/h4&gt;

&lt;p&gt;I used &lt;a href="http://msdn.microsoft.com/en-us/bb737338.aspx" target="_blank"&gt;CM_GPRSEntries Configuration Service Provider&lt;/a&gt; to configure GPRS. Nothing is special there.&lt;/p&gt;

&lt;div&gt;
  &lt;div&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;CM_GPRSEntries&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRS Connection&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DestId&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{436EF144-B4FB-4863-A041-8F905A62C572}&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;UserName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[DeviceID]&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Password&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[Password]&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Domain&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[Domain]&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;AlwaysOn&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DevSpecificCellular&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoValid&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoAccessPointName&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[AcceessPointName]&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;BearerInfoValid&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoProtocolType&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoL2ProtocolType&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;2&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoAddress&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoDataCompression&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GPRSInfoHeaderCompression&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;h4&gt;Set Date/Time and Time Zone&lt;/h4&gt;

&lt;p&gt;In this application, we also need to set the date/time and time zone information. I tried to use the &lt;a href="http://msdn.microsoft.com/en-us/bb737261.aspx" target="_blank"&gt;Clock Configuration Service Provider&lt;/a&gt;, but it doesn't work. I don't know what is wrong. I followed the sample xml, but I couldn't get it to work. Finally, since we only use 4 of the time zones, I queried the TimeZoneInformation for each time zone and exported the values. Then put those values in the application's configuration file. I load them in when the user choose a time zone and pass it to the following xml to set the time zone. To set the date/time, I used OpenNETCF.WinAPI.Core.SetLocalDateTime(). This is not pretty, but it worked.&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;wap-provisioningdoc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Registry&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HKLM\Time&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;TimeZoneInformation&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[TimeZoneInformation]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;datatype&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;binary&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;HKLM\Software\Microsoft\Clock&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;parm&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;GMT_OFFSET&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;[GMT_OFFSET]&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;datatype&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;integer&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;characteristic&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;wap-provisioningdoc&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;If you are changing the time zone and you need to display current date/time on your configuration screen like we did, you need to get the local time using native function call instead of using DateTime.Now. Otherwise, it will mess up. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-7616627334976489679?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/11/provisioning-windows-mobile-devices.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_ElXg_EOWn5c/SvSQgNaeHVI/AAAAAAAAAbE/NAEU2_DOwRs/s72-c/image_thumb.png' height='72' width='72'/><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-7703297199308003206</guid><pubDate>Wed, 07 Oct 2009 21:34:00 +0000</pubDate><atom:updated>2009-10-07T14:34:06.514-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET Compact Framework</category><title>Creating Transparent Controls in .NET Compact Framework</title><description>&lt;p&gt;Recently I was working on improving the user interface of our windows mobile application - &lt;a href="http://www.dotnetideas.com/products.aspx"&gt;UnitConverter&lt;/a&gt;. It had plain solid background. I wanted to add background image to it. I found this &lt;a href="http://msdn.microsoft.com/en-us/windowsmobile/dd296751.aspx"&gt;video tutorial&lt;/a&gt; on how to display background image on a form. However, that tutorial told us if we need to have transparent controls on top of the image, we have to write our own user controls. That’s how I started researching on how to create transparent controls. I found an &lt;a href="http://breathingtech.com/2009/creating-gradient-background-with-transparent-labels-in-net-compact-framework/"&gt;article&lt;/a&gt; by &lt;a href="http://breathingtech.com/about/"&gt;Per Ola Sæther&lt;/a&gt; which laid the foundation of my solution. &lt;/p&gt;  &lt;p&gt;The basic ideas to create a transparent control is to override the OnPaintBackgound method of the control so it calls the parent form’s OnPaintBackgound to draw the background and then draw content of the control on top of it. &lt;/p&gt;  &lt;p&gt;In that article, the author showed how to create a transparent label control. But the code can be simplified. I also did some refactoring work so it extends to not just label control. &lt;/p&gt;  &lt;p&gt;First I created the same interface introduced in that article.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IPaintControl&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #008000"&gt;// have the background painted&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvokePaintBackground(PaintEventArgs e);&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Then I created a base form so I don’t have to write the same code for each form. &lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CcForm : Form, IPaintControl&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvokePaintBackground(PaintEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        OnPaintBackground(e);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;A base control is created so we not only can have transparent label, but also other kinds of controls, such as radio button and checkbox. It has a property called “TransparentBackground”. If you don’t want your control to be transparent for some reason, you can change this property. In the “OnPaintBackground” method, it calls its parent’s “InvokePaintBackground” to draw the background.&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CcTransparentControl : Control&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; _transparentBackgound = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; TransparentBackground&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; _transparentBackgound;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            _transparentBackgound = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPaintBackground(PaintEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_transparentBackgound)&lt;br /&gt;        {&lt;br /&gt;            IPaintControl parent = (IPaintControl)Parent;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (parent != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                parent.InvokePaintBackground(e);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnPaintBackground(e);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Now we can create the transparent label control using the following code.&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CcTransparentLabel : CcTransparentControl&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; ContentAlignment textAlign = ContentAlignment.TopLeft;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ContentAlignment TextAlign&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; textAlign;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            textAlign = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CcTransparentLabel()&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPaint(PaintEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        Graphics gfx = e.Graphics;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.TextAlign == ContentAlignment.TopLeft)&lt;br /&gt;        {&lt;br /&gt;            gfx.DrawString(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Font,&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SolidBrush(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ForeColor), ClientRectangle);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.TextAlign == ContentAlignment.TopCenter)&lt;br /&gt;        {&lt;br /&gt;            SizeF size = gfx.MeasureString(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Font);&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; left = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Width / 2 - (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)size.Width / 2;&lt;br /&gt;            var rect = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(ClientRectangle.Left + left,&lt;br /&gt;            ClientRectangle.Top, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)size.Width,&lt;br /&gt;            ClientRectangle.Height);&lt;br /&gt;            gfx.DrawString(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Font,&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SolidBrush(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ForeColor), rect);&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.TextAlign == ContentAlignment.TopRight)&lt;br /&gt;        {&lt;br /&gt;            SizeF size = gfx.MeasureString(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Font);&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; left = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Width - (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)size.Width + &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Left;&lt;br /&gt;            var rect = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(ClientRectangle.Left + left,&lt;br /&gt;            ClientRectangle.Top, (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)size.Width,&lt;br /&gt;            ClientRectangle.Height);&lt;br /&gt;            gfx.DrawString(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Font,&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SolidBrush(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ForeColor), rect);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;In our form, we change the form to inherit from CcForm and drag/drop a CcTransparentLabel onto it.&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FormWithSolidColorBackground : CcForm&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Here is the screen shot. As you can see, the label has transparent background now.&lt;/div&gt;

&lt;div&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Ss0JRMO1R9I/AAAAAAAAAag/l_qrJQcAkdY/s1600-h/image2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_ElXg_EOWn5c/Ss0JRR4tOmI/AAAAAAAAAak/UNhl6W0_46g/image_thumb.png?imgmax=800" width="184" height="244" /&gt;&lt;/a&gt; &lt;/div&gt;

&lt;div&gt;However, when I tried to add image background with gradient color, my label doesn’t look right anymore.&lt;/div&gt;

&lt;div&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Ss0JRi_b5RI/AAAAAAAAAao/78eyU0zH6Zw/s1600-h/image5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Ss0JR4aIB4I/AAAAAAAAAas/o1ogvBp0YWs/image_thumb1.png?imgmax=800" width="183" height="244" /&gt;&lt;/a&gt; &lt;/div&gt;

&lt;div&gt;To understand the issue, we need to first take a look of how we display background image on a form.&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FormWithImageBackground : CcForm&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Rectangle _backgroundRect;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Bitmap _background;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; FormWithImageBackground()&lt;br /&gt;    {&lt;br /&gt;        InitializeComponent();&lt;br /&gt;&lt;br /&gt;        _background = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Bitmap(currentPath + &lt;span style="color: #006080"&gt;@&amp;quot;\ImageBackground.jpg&amp;quot;&lt;/span&gt;);&lt;br /&gt;        _backgroundRect = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(0, 0, _background.Width, _background.Height);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPaintBackground(PaintEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        Graphics g = e.Graphics;&lt;br /&gt;        g.DrawImage(_background, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ClientRectangle, _backgroundRect, GraphicsUnit.Pixel);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;What happened is when the OnPaintBackground was called by the transparent label control, it re-draws the image inside of the label control. So it shows the top-left corner of the image on the label’s background. To fix this issue, I pass in the location of the label control to the form and use it to re-draw the image. For example, if the label is located at (10, 20), the image background would be displayed at (-10, –20). This may not be the best solution, but it worked. Here is revised interface and controls.&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IPaintControl&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #008000"&gt;// have the background painted&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvokePaintBackground(PaintEventArgs e, Point location);&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CcForm : Form, IPaintControl&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvokePaintBackground(PaintEventArgs e, Point location)&lt;br /&gt;    {&lt;br /&gt;        OnPaintBackground(e);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CcTransparentControl : Control&lt;br /&gt;{&lt;br /&gt;    ....&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnPaintBackground(PaintEventArgs e)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_transparentBackgound)&lt;br /&gt;        {&lt;br /&gt;            IPaintControl parent = (IPaintControl)Parent;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (parent != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                parent.InvokePaintBackground(e, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Location);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.OnPaintBackground(e);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;In the form, I then override the InvokePaintBackground method to draw the image at the desired location.&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InvokePaintBackground(System.Windows.Forms.PaintEventArgs e, System.Drawing.Point location)&lt;br /&gt;{&lt;br /&gt;    Graphics g = e.Graphics;&lt;br /&gt;    Rectangle destRect = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(-1 * location.X, -1 * location.Y, ClientRectangle.Width, ClientRectangle.Height);&lt;br /&gt;    g.DrawImage(_background, destRect, _backgroundRect, GraphicsUnit.Pixel);&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Now we have a transparent label over image background. 
  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/Ss0JSL4zduI/AAAAAAAAAaw/eQCc_mlMr1E/s1600-h/image8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/Ss0JSt8z4xI/AAAAAAAAAa0/4sBtRffpApk/image_thumb2.png?imgmax=800" width="184" height="244" /&gt;&lt;/a&gt; &lt;/div&gt;

&lt;div&gt;I also created transparent radio button and checkbox controls. These are the controls commonly used in a form. So is the Panel control. The following example showed the transparent radio button and checkbox on a transparent panel. You can download the complete source code from &lt;a href="http://www.dotnetideas.com/Download/TransparentControlSample.zip"&gt;here&lt;/a&gt;. &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Ss0JS4vJqJI/AAAAAAAAAa4/zeCAsDA_ZfA/s1600-h/image14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/Ss0JTYPrCdI/AAAAAAAAAa8/rOjE0LegW9c/image_thumb4.png?imgmax=800" width="184" height="244" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;&amp;#160; &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-7703297199308003206?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/10/creating-transparent-controls-in-net.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_ElXg_EOWn5c/Ss0JRR4tOmI/AAAAAAAAAak/UNhl6W0_46g/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8683951125187496143</guid><pubDate>Fri, 25 Sep 2009 20:55:00 +0000</pubDate><atom:updated>2009-09-25T13:55:51.871-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Others</category><title>Learning Silverlight – Miscellaneous Tips</title><description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;How to use OpenFileDialog?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;OpenFileDialog ofd = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; OpenFileDialog();&lt;br /&gt;ofd.Multiselect = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;ofd.Filter = &lt;span style="color: #006080"&gt;&amp;quot;xml files (*.xml)|*.xml&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (ofd.ShowDialog()==&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileContent = ofd.File.OpenText().ReadToEnd();&lt;br /&gt;    &lt;span style="color: #008000"&gt;// do some thing&lt;/span&gt;&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;strong&gt;&lt;em&gt;How to use SaveFileDialog?&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;

&lt;div&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;SaveFileDialog sfd = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SaveFileDialog();&lt;br /&gt;sfd.Filter = &lt;span style="color: #006080"&gt;&amp;quot;xml files (*.xml)|*.xml&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (sfd.ShowDialog() == &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] fileBytes = System.Text.Encoding.UTF8.GetBytes(fileString); &lt;span style="color: #008000"&gt;// fileString would be something you want to save to the file&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (Stream fs = (Stream)sfd.OpenFile())&lt;br /&gt;    {&lt;br /&gt;        fs.Write(fileBytes, 0, fileBytes.Length);&lt;br /&gt;        fs.Close();&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;How to parse XML?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To parse a XML file like this:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippetWrapper"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;List&lt;/span&gt; &lt;span style="color: #ff0000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DotNetIdeas.CF.RecipeBox.RecipeBox&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;category&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Breakfast&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;order&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;item&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;pan cake&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;item&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;milk&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;category&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Desert&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;order&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;List&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;

    &lt;br /&gt;&lt;/div&gt;
You can do something like this:&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;XDocument xd = XDocument.Parse(xml);&lt;br /&gt;&lt;br /&gt;XElement node = xd.Root;&lt;br /&gt;&lt;br /&gt;var categories = (from category &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; xd.Descendants(&lt;span style="color: #006080"&gt;&amp;quot;category&amp;quot;&lt;/span&gt;)&lt;br /&gt;                  select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Category()&lt;br /&gt;                  {&lt;br /&gt;                      Name = category.Attribute(&lt;span style="color: #006080"&gt;&amp;quot;name&amp;quot;&lt;/span&gt;).Value,&lt;br /&gt;                      Order = Convert.ToInt32(category.Attribute(&lt;span style="color: #006080"&gt;&amp;quot;order&amp;quot;&lt;/span&gt;).Value),&lt;br /&gt;                      Items = FromXml(category.Elements(&lt;span style="color: #006080"&gt;&amp;quot;item&amp;quot;&lt;/span&gt;))&lt;br /&gt;                  }).ToList();&lt;br /&gt;       &lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;If you happened to be like me, migrating the code from some old programs, don’t forget to add “using System.Linq” which is in System.Core.dll. Otherwise you will get a compiler error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;How to use TreeView?&lt;/em&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/Sr0uVFwuTnI/AAAAAAAAAaY/r2QVdLI6Mfw/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/Sr0uVrCHxmI/AAAAAAAAAac/ib99sjmwrNQ/image_thumb.png?imgmax=800" width="244" height="223" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a TreeView like this one, you will need to use HierarchicalDataTemplate. It is in System.Windows.Controls. So add the following namespace first:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;xmlns:control=&amp;quot;clr-namespace:System.Windows;assembly=System.Windows.Controls&amp;quot;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&amp;lt;controls:TreeView x:Name=&lt;span style="color: #006080"&gt;&amp;quot;ingredientList&amp;quot;&lt;/span&gt; Height=&lt;span style="color: #006080"&gt;&amp;quot;330&amp;quot;&lt;/span&gt; Width=&lt;span style="color: #006080"&gt;&amp;quot;248&amp;quot;&lt;/span&gt; Canvas.Left=&lt;span style="color: #006080"&gt;&amp;quot;17&amp;quot;&lt;/span&gt; Canvas.Top=&lt;span style="color: #006080"&gt;&amp;quot;18&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;    &amp;lt;controls:TreeView.ItemTemplate&amp;gt;&lt;br /&gt;        &amp;lt;control:HierarchicalDataTemplate ItemsSource=&lt;span style="color: #006080"&gt;&amp;quot;{Binding Items}&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;            &amp;lt;StackPanel Orientation=&lt;span style="color: #006080"&gt;&amp;quot;Horizontal&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;                &amp;lt;CheckBox x:Name=&lt;span style="color: #006080"&gt;&amp;quot;itemCheckbox&amp;quot;&lt;/span&gt; IsChecked=&lt;span style="color: #006080"&gt;&amp;quot;{Binding ItemChecked, Mode=TwoWay}&amp;quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;                &amp;lt;TextBlock Text=&lt;span style="color: #006080"&gt;&amp;quot;{Binding Path=Name}&amp;quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;            &amp;lt;/StackPanel&amp;gt;&lt;br /&gt;        &amp;lt;/control:HierarchicalDataTemplate&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;/controls:TreeView.ItemTemplate&amp;gt;&lt;br /&gt;&amp;lt;/controls:TreeView&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;strong&gt;&lt;em&gt;How to force data binding in TextChanged event?&lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;

&lt;div&gt;When a text box has data binding, it will not update the source until it lost the focus. Sometimes we want the source to change as soon as we type something. Here is how to do it:&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ingredientName_TextChanged(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, System.Windows.Controls.TextChangedEventArgs e)&lt;br /&gt;{&lt;br /&gt;    BindingExpression bExp = ingredientName.GetBindingExpression(TextBox.TextProperty);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (bExp != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;    {&lt;br /&gt;        bExp.UpdateSource();&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8683951125187496143?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/09/learning-silverlight-miscellaneous-tips.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_ElXg_EOWn5c/Sr0uVrCHxmI/AAAAAAAAAac/ib99sjmwrNQ/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-7126726765664671084</guid><pubDate>Fri, 25 Sep 2009 14:25:00 +0000</pubDate><atom:updated>2009-09-25T07:25:41.414-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Others</category><title>Learning Silverlight – How to programmatically add animation?</title><description>&lt;p&gt;Recently I created a little Silverlight application called “&lt;a href="http://www.dotnetideas.com/silverlight/littlemath/littlemath.html"&gt;LittleMath&lt;/a&gt;”. It is a simple number addition game. It randomly generate two numbers between 0 and 9. The user clicks on the number pad to give the answer and check it by clicking on “Check Answer”. This is my first Silverlight application. I found it very interesting. With the help of Expression Blend, you can build nice looking application with animation fairly quickly. However, sometimes you may need to animation programmatically. In my &lt;a href="http://www.dotnetideas.com/silverlight/littlemath/littlemath.html"&gt;demo&lt;/a&gt;, when you check “Show Beads”, it will show the red beads one by one according to the randomly generated numbers. Here is how to do it.&lt;/p&gt;  &lt;p&gt;First we create a story board and animation duration for each bead:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;div id="codeSnippetWrapper"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; beadDuration = 0.5;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Storyboard showBeadsStoryBoard = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Storyboard();&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Then add the story board to resources with a name&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;LayoutRoot.Resources.Add(&lt;span style="color: #006080"&gt;&amp;quot;showBeads&amp;quot;&lt;/span&gt;, showBeadsStoryBoard);&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Before showing the beads, we need to clear the existing beads. Then set the story board duration based on the total numbers. For each bead, we create a DoubleAnimation so the bead will gradually appear on the screen. Because we want the bead to show up one by one, we will need to set the BeginTime. The rest is pretty straight forward. 
  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShowBeads()&lt;br /&gt;{&lt;br /&gt;    ClearBeads();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; num1 = Convert.ToInt32(number1.Text);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; num2 = Convert.ToInt32(number2.Text);&lt;br /&gt;    Duration storyBoardduration = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Duration(TimeSpan.FromSeconds(beadDuration * (num1 + num2)+1));&lt;br /&gt;    showBeadsStoryBoard.Duration = storyBoardduration;&lt;br /&gt;    Duration duration = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Duration(TimeSpan.FromSeconds(beadDuration));&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; num1; i++)&lt;br /&gt;    {&lt;br /&gt;        AddBead(beadsPanel1, TimeSpan.FromSeconds(beadDuration * i + 1), duration);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; num2; i++)&lt;br /&gt;    {&lt;br /&gt;        AddBead(beadsPanel2, TimeSpan.FromSeconds(beadDuration * (num1 + i) + 1), duration);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;// Begin the animation.&lt;/span&gt;&lt;br /&gt;    showBeadsStoryBoard.Begin();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddBead(StackPanel beadsPanel, TimeSpan beginTime, Duration duration)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #008000"&gt;// Add bead&lt;/span&gt;&lt;br /&gt;    Ellipse bead = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Ellipse();&lt;br /&gt;    bead.Width = 20;&lt;br /&gt;    bead.Height = 20;&lt;br /&gt;    bead.Margin = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thickness(0);&lt;br /&gt;    bead.Fill = beadBrush;&lt;br /&gt;    bead.Opacity = 0;&lt;br /&gt;    beadsPanel.Children.Add(bead);&lt;br /&gt;               &lt;br /&gt;    &lt;span style="color: #008000"&gt;// Add animation&lt;/span&gt;&lt;br /&gt;    DoubleAnimation beadDoubleAnimation = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DoubleAnimation();&lt;br /&gt;    beadDoubleAnimation.Duration = duration;&lt;br /&gt;    beadDoubleAnimation.BeginTime = beginTime;&lt;br /&gt;    showBeadsStoryBoard.Children.Add(beadDoubleAnimation);&lt;br /&gt;    Storyboard.SetTarget(beadDoubleAnimation, bead);&lt;br /&gt;    Storyboard.SetTargetProperty(beadDoubleAnimation, &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PropertyPath(&lt;span style="color: #006080"&gt;&amp;quot;(UIElement.Opacity)&amp;quot;&lt;/span&gt;));&lt;br /&gt;    beadDoubleAnimation.To = 1;&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ClearBeads()&lt;br /&gt;{&lt;br /&gt;    showBeadsStoryBoard.Stop();&lt;br /&gt;    beadsPanel1.Children.Clear();&lt;br /&gt;    beadsPanel2.Children.Clear();&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;It is really neat. 
  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-7126726765664671084?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/09/learning-silverlight-how-to.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-2771373947109249964</guid><pubDate>Thu, 10 Sep 2009 20:15:00 +0000</pubDate><atom:updated>2010-02-25T09:34:29.816-08:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET Compact Framework</category><title>Memory leak issue in “How Do I: Programmatically Monitor for a Specific Time of Day Without Draining a Device Battery?”</title><description>&lt;p&gt;Recently I worked on improving our SmartOrganizer 3.1 application. I need to add notification to it, so when a task or appointment is due, the application will prompt the user. Also I want this to run efficiently so it won’t drain the device battery. I found some sample code from &lt;a href="http://msdn.microsoft.com/en-us/windowsmobile/bb870451.aspx"&gt;“How Do I” video for Device&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Though the code worked well initially, I found a couple issues which caused memory leak later. Here I will post the original code and my fix.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div id="codeSnippetWrapper"&gt;     &lt;div id="codeSnippetWrapper"&gt;       &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.ComponentModel;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Data;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Drawing;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Windows.Forms;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Diagnostics;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; HowDoI.Examples;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Threading;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; TimeOfDayEvent_CS&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Form1 : Form&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Form1()&lt;br /&gt;        {&lt;br /&gt;            InitializeComponent();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _eventName = &lt;span style="color: #006080"&gt;@&amp;quot;TimeOfDayEventExample&amp;quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _timeOfDayEventName = &lt;span style="color: #006080"&gt;@&amp;quot;\\.\Notifications\NamedEvents\&amp;quot; + _eventName;&lt;br /&gt;        IntPtr _nativeWaitHandle = IntPtr.Zero;&lt;br /&gt;        Thread _backgroundThread = null;&lt;br /&gt;        bool _programIsShuttingDown = false;&lt;br /&gt;        private void menuSetTimeNtfy_Click(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            // Declare and convert time values&lt;br /&gt;            DateTime targetTime = GetTargetTime();&lt;br /&gt;            long targetTimeAsFileTimeUTC = targetTime.ToFileTime();&lt;br /&gt;            long targetTimeAsFileTimeLocal = 0;&lt;br /&gt;            Win32.FileTimeToLocalFileTime(ref targetTimeAsFileTimeUTC, &lt;br /&gt;                ref targetTimeAsFileTimeLocal);&lt;br /&gt;            SystemTime targetTimeAsSystemTime = new SystemTime();&lt;br /&gt;            Win32.FileTimeToSystemTime(ref targetTimeAsFileTimeLocal, targetTimeAsSystemTime);&lt;br /&gt;&lt;br /&gt;            // Create named Win32 Event Object&lt;br /&gt;            _nativeWaitHandle = Win32.CreateEvent(0, 0, 0, _eventName);&lt;br /&gt;&lt;br /&gt;            // Start the background thread&lt;br /&gt;            _backgroundThread = new Thread(ThreadFunction);&lt;br /&gt;            _backgroundThread.Start();&lt;br /&gt;&lt;br /&gt;            Win32.CeRunAppAtTime(_timeOfDayEventName, targetTimeAsSystemTime);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        void ThreadFunction()&lt;br /&gt;        {&lt;br /&gt;            // Wait for the event to signal&lt;br /&gt;            // When signaled our target time has happened&lt;br /&gt;            Win32.WaitForSingleObject(_nativeWaitHandle, -1);&lt;br /&gt;&lt;br /&gt;            // Do our Target Time processing&lt;br /&gt;            if (!_programIsShuttingDown)&lt;br /&gt;                BeginInvoke((TimeHasOccurredDelegate)TimeHasOccurred, new object[] { DateTime.Now }); &lt;br /&gt;            //TimeHasOccurred(DateTime.Now);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        void TimeHasOccurred(DateTime time)&lt;br /&gt;        {&lt;br /&gt;            notification1.Text = &lt;br /&gt;                string.Format(&amp;quot;&lt;/span&gt;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;font color=\&lt;span style="color: #006080"&gt;'#000000\'&amp;gt;&amp;lt;b&amp;gt;It'&lt;/span&gt;s Time: {0}&amp;lt;b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;span style="color: #006080"&gt;&amp;quot;, &lt;br /&gt;                time.ToString());&lt;br /&gt;            notification1.Visible = true;&lt;br /&gt;            Debug.WriteLine(&amp;quot;&lt;/span&gt;It's Time: &lt;span style="color: #006080"&gt;&amp;quot; + time.ToString());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        delegate void TimeHasOccurredDelegate(DateTime time);&lt;br /&gt;&lt;br /&gt;        private DateTime GetTargetTime()&lt;br /&gt;        {&lt;br /&gt;            //DateTime targetTime = new DateTime(2007, 8, 31, 10, 15, 0);&lt;br /&gt;            // For demo purposes pick date time 1 minute in the future&lt;br /&gt;            DateTime currentTime = DateTime.Now;&lt;br /&gt;            DateTime targetTime = currentTime + new TimeSpan(0, 1, 0);&lt;br /&gt;&lt;br /&gt;            Debug.WriteLine(&amp;quot;&lt;/span&gt;CurrentTime: &lt;span style="color: #006080"&gt;&amp;quot; + currentTime.ToString());&lt;br /&gt;            Debug.WriteLine(&amp;quot;&lt;/span&gt;TargetTime: &amp;quot; + targetTime.ToString());&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; targetTime;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; _threadShutdownTimeout = 30000;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Form1_Closing(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, CancelEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_nativeWaitHandle != IntPtr.Zero)&lt;br /&gt;            {&lt;br /&gt;                _programIsShuttingDown = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;                Win32.SetEvent(_nativeWaitHandle);&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_backgroundThread != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; shutdownSucceeded = _backgroundThread.Join(_threadShutdownTimeout);&lt;br /&gt;                    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!shutdownSucceeded)&lt;br /&gt;                        _backgroundThread.Abort();&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

      &lt;br /&gt;&lt;/div&gt;

    &lt;br /&gt;&lt;/div&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Here is the native method calls&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Text;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; HowDoI.Examples&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Win32&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; Win32 Time-related Functiions&lt;br /&gt;&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CeRunAppAtTime(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; application, SystemTime startTime);&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; FileTimeToSystemTime(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; lpFileTime, SystemTime lpSystemTime);&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; FileTimeToLocalFileTime(&lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; lpFileTime, &lt;span style="color: #0000ff"&gt;ref&lt;/span&gt; &lt;span style="color: #0000ff"&gt;long&lt;/span&gt; lpLocalFileTime);&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; ShowWindow(IntPtr hWnd, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; nCmdShow);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; Win32  Event Object Functions&lt;br /&gt;&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; IntPtr CreateEvent(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; alwaysZero, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; manualReset, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; initialState, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; eventName);&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; WaitForSingleObject(IntPtr handle, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; waitTimeInMilliseconds);&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; EventModify(IntPtr handle, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; eventAction);&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDLL.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CloseHandle(IntPtr handle);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; SetEvent(IntPtr handle)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; EVENT_SET = 3;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; EventModify(handle, EVENT_SET); &lt;span style="color: #008000"&gt;// in WM, SetEvent, ResetEvent, &amp;amp; PulseEvent are all implemented as EventModify&lt;/span&gt;&lt;br /&gt;        }&lt;br /&gt;        &lt;br /&gt;&lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; Win32 SystemTime&lt;br /&gt;&lt;br /&gt;    [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SystemTime&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wYear;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wMonth;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wDayOfWeek;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wDay;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wHour;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wMinute;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wSecond;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;ushort&lt;/span&gt; wMilliseconds;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The time monitoring and notification in above code worked perfectly. However, I noticed that if I stop the application before the time is up, the application disappeared from the task manager, but the memory was not released. Furthermore, I used the Remote Process Viewer to check which process is running. I can see that process is still there. As I was writing this blog, I noticed that it only happen on device, not emulator. For some reasons, the device couldn’t kill the background thread when it is not done. The solution is. in fact, pretty simple - reset the timer. Add the following line of code before Join the background thread. [currentTime] is current time in SystemTime format.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Win32.CeRunAppAtTime(_timeOfDayEventName, [currentTime]);&lt;br /&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; shutdownSucceeded = _backgroundThread.Join(_threadShutdownTimeout);&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-2771373947109249964?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/09/memory-leak-issue-in-how-do-i.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-5684161142594705455</guid><pubDate>Fri, 04 Sep 2009 15:30:00 +0000</pubDate><atom:updated>2009-09-04T08:30:11.384-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Others</category><title>How to make an icon’s background transparent using Visual Studio Icon Editor?</title><description>&lt;p&gt;To make an icon’s background transparent, you open the icon file using Visual Studio Icon Editor, choose the “Fill Tool”. Then choose the “Transparent” color from “Colors” on the left. Click on the areas you want to make transparent. That’s it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/SqEygAwF8LI/AAAAAAAAAaQ/KeAVUD_cJ1A/s1600-h/image%5B3%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SqEygkRLHiI/AAAAAAAAAaU/vppTJQH6cJo/image_thumb%5B1%5D.png?imgmax=800" width="463" height="291" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-5684161142594705455?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/09/how-to-make-icons-background.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_ElXg_EOWn5c/SqEygkRLHiI/AAAAAAAAAaU/vppTJQH6cJo/s72-c/image_thumb%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8387775880895108784</guid><pubDate>Wed, 02 Sep 2009 14:12:00 +0000</pubDate><atom:updated>2009-09-09T12:03:53.992-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>Others</category><title>Microsoft Bing on SmartPhone</title><description>&lt;p&gt;To download “Bing”, type m.bing.com in your web browser. Click “Download interactive maps” for Windows Mobile. Then following the on-screen instruction.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/Sp59O7QTMeI/AAAAAAAAAZg/mMsdD_yJPZc/s1600-h/image5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/Sp59PIwr9fI/AAAAAAAAAZk/y-kMe6Q_GPw/image_thumb1%5B1%5D.png?imgmax=800" width="187" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After the installation, you will see the “Bing” icon in Programs.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/Sp59PlaHH9I/AAAAAAAAAZo/J75tGV8v59M/s1600-h/image14.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sp59P1orgjI/AAAAAAAAAZs/1L9mhm9sYlI/image_thumb4.png?imgmax=800" width="185" height="244" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Tap on “Bing” icon to run it. Below is the dashboard of Bing. The Map is very similar to Google Map. It also use cellular phone tower to decide your location, so it is not very accurate. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/Sp59QCeZNvI/AAAAAAAAAZw/mSPFCYuAkH0/s1600-h/image17.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/Sp59QtMxmtI/AAAAAAAAAZ0/9wGkLmxrA1Y/image_thumb5.png?imgmax=800" width="185" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The two features I really like is the “Traffic” and “Movies”. The “Traffic” map seems accurate and it automatically update every 2 minutes. The “Movies” is easy to navigate. You can quickly find the theater a movie is playing in or check the show time of any particular theater around your area. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/Sp59RkSH7GI/AAAAAAAAAZ4/d-3e-bucX-c/s1600-h/image2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/Sp59Sb4n1AI/AAAAAAAAAZ8/DGeBld6rJbU/image_thumb.png?imgmax=800" width="185" height="244" /&gt;&lt;/a&gt; &lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Sp59TLfTKcI/AAAAAAAAAaA/n5vED9nLVKw/s1600-h/image5%5B1%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/Sp59Tnb9s0I/AAAAAAAAAaE/UjwLiEOHK4Q/image_thumb1.png?imgmax=800" width="186" height="244" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;The “Gas Princes” searches the lowest gas price around your area. But I think they could add more sorting capabilities.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Sp59UP28ARI/AAAAAAAAAaI/xyPrk8Znr2A/s1600-h/image8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sp59Ut70dxI/AAAAAAAAAaM/jA0dxu_LSOg/image_thumb2.png?imgmax=800" width="184" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;“Categories” allow you search local business by category. It is like a yellow page and I think it is very handy.&lt;/p&gt;  &lt;p&gt;“Collections” has some predefined search criteria. I found the “Upcoming event” is kind of strange.&amp;#160; It is not sorted by date/time. It even listed classes at some hospitals.&lt;/p&gt;  &lt;p&gt;“Bing” crashed a couple times when the memory on my cell phone running low. With all the maps and automatic updates, you could imagine that it requires a lot of resources. But overall, I think “Bing” is a really nice application. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8387775880895108784?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/09/microsoft-bing-on-smartphone.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_ElXg_EOWn5c/Sp59PIwr9fI/AAAAAAAAAZk/y-kMe6Q_GPw/s72-c/image_thumb1%5B1%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-4650875287651335630</guid><pubDate>Tue, 25 Aug 2009 17:47:00 +0000</pubDate><atom:updated>2009-08-25T10:47:37.769-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET Compact Framework</category><title>This application requires a newer version of the Microsoft .NET Compact Framework than the version installed on this device</title><description>&lt;p&gt;This is the second time I ran into this error in last couple months. I better write it down so I don’t forget again. &lt;/p&gt;  &lt;p&gt;I was creating a .NET Compact Framework Application. I want it to be able to run on older devices, so I choose .NET Framework 2.0 thinking the project will be .NET 2.0 project(see picture 1). However, when I tried to run the application on a smart phone, I got the error “This application requires a newer version of the Microsoft .NET Compact Framework than the version installed on this device.” You have to specify the version of .NET Compact Framework on the second dialog box(see picture 2). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/SpQjoEpfp1I/AAAAAAAAAY4/1tdatnS3zQA/s1600-h/image5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SpQjopKgxlI/AAAAAAAAAY8/4cyYHu8GP84/image_thumb1.png?imgmax=800" width="244" height="157" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Picture 1&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/SpQjpoYRS6I/AAAAAAAAAZA/DY1YY_Mj5U0/s1600-h/image8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SpQjqeCao_I/AAAAAAAAAZE/vHYSmDn327E/image_thumb2.png?imgmax=800" width="244" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Picture 2&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-4650875287651335630?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/08/this-application-requires-newer-version.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_ElXg_EOWn5c/SpQjopKgxlI/AAAAAAAAAY8/4cyYHu8GP84/s72-c/image_thumb1.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-5061497504069868901</guid><pubDate>Mon, 17 Aug 2009 14:41:00 +0000</pubDate><atom:updated>2009-08-18T05:33:30.557-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint Analysis and Design Tips.</title><description>Object-Oriented Analysis and Design is a relatively mature technique. We call it Object-Oriented because the technique is to implement various requirements with objects in code. Likewise, In SharePoint Analysis and Design, we map requirements to SharePoint components such as web parts, lists, document libraries, views, site columns, content types, page layouts, info path forms, application pages, excel services, business catalogs, user profiles, my sites, site maps and so on. &lt;br /&gt;
The article is not to establish a methodology. It tries to explain a couple of experiences that may help in SharePoint Analysis and Design.&lt;br /&gt;
&lt;b&gt;1. &lt;/b&gt;&lt;b&gt;Map business requirements to technical solution as early as possible. &lt;/b&gt;&lt;br /&gt;
In object-oriented design, separating business domain requirements and technical solutions is a good practice. Technical solutions should not impact collecting business requirements if possible. However, this separation of requirement and solution is what SharePoint Analysis and Design should avoid. Considering technical solution at early stage will provide the following benefits:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Make business users aware what cannot be done with SharePoint's out-of-box features.&lt;/strong&gt; Business users expect SharePoint to do Anything through configuration, but custom development is inevitable for most of the enterprise-level MOSS applications. Custom development demands more efforts, and we need to inform those efforts to customers as early as possible. &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Give SharePoint developers the opportunities to explain the out-of-box features that will meet or exceed the same business goals with different business processes.&lt;/strong&gt; For example, the business goal of sharing knowledge and experience among employees can be archived by using out-of-box wiki library. Therefore, the original use cases collected from customers for achieving the same business goal will be altered according to the wiki libraries' behavior.&lt;/li&gt;
&lt;/ul&gt;2. &lt;b&gt;Strive for configurable/customizable solutions&lt;/b&gt;.&lt;br /&gt;
SharePoint allows end users to customize solutions without going through development cycles. End users may customize lists, document libraries, site pages, site master pages, define security groups and permission levels, etc; They may publish InfoPath forms and excel sheets, and create ad-hoc reports and dashboards using PerformancePoint. To take advantage of those features while designing SharePoint solution, consider separate the responsibilities of developers and end users. Both end users and developers have the responsibilities to contribute to SharePoint solutions. For example, in an InfoPath form, developers implement the web services for InfoPath to connect to and configure the SSO application while end users are responsible to create the InfoPath connections to the web services using SSO authentication. The relationship between developers and end users is very much like how frameworks' developers are related to the developers who use the frameworks. Basically, developers should deal with more difficult tasks and expose their work through interfaces to end users. The interfaces in SharePoint context, which is very different from the .NET interfaces, are in the formats of InfoPath connection, SSO, Content Type, Page Layout, etc.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-5061497504069868901?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/08/sharepoint-analysis-and-design.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-1506076511286110878</guid><pubDate>Sun, 09 Aug 2009 21:24:00 +0000</pubDate><atom:updated>2009-08-20T09:38:01.221-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint Workflow - Use IListItemService to manipulate list items other than the workflow list items.</title><description>&lt;p&gt;SharePoint workflows can use OnWorkflowItemChanged and OnWorkflowItemDeleted activities to capture the &amp;quot;changed&amp;quot; and &amp;quot;deleted&amp;quot; events for the list items associated with the SharePoint workflow instances. To capture the &amp;quot;changed&amp;quot; and &amp;quot;deleted&amp;quot; events for the list items &lt;i&gt;&lt;strong&gt;not &lt;/strong&gt;associated&lt;/i&gt; with SharePoint workflow instances, we need to use SharePoint workflows' IListItemService.&lt;/p&gt;  &lt;p&gt;IListItemService is one of four ExternalDataExchange services - IListItemService, ISharPointService, ITaskService and IWorkflowModificationService - registered by SharePoint runtime. IListItemService provides the methods and events to handle any list items in the SharePoint Site Collection where a workflow instance is running. To study the interface, I developed two workflows to illustrate two different scenarios using IListItemService.&lt;/p&gt;  &lt;h4&gt;&lt;b&gt;Scenario 1:&lt;/b&gt; A workflow needs to capture the OnItemChanged event of a pre-existing list item. &lt;/h4&gt;  &lt;p&gt;To test the scenario, I created two SharePoint lists: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;workflowlist&lt;/b&gt;: it has a workflow association with the testing workflow and one item called &amp;quot;workflow item&amp;quot;. &lt;/li&gt;    &lt;li&gt;&lt;b&gt;anotherlist&lt;/b&gt;: the changed events of its items should be captured by the testing workflow associated with workflowlist above. The list's listid is 7c455073-56ce-4ecd-bfa8-2923fc521b9e and it has one item called &amp;quot;another list item&amp;quot;. The id of the item is 1. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following is the design view of the testing workflow:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SoxkzdCMxQI/AAAAAAAAAYA/jTpxAugNsG8/s1600-h/clip_image002%5B5%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxkz91NcGI/AAAAAAAAAYE/1ZEwQ6rn33g/clip_image002_thumb%5B2%5D.jpg?imgmax=800" width="360" height="241" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The workflow includes three activities:&lt;/p&gt;  &lt;p&gt;1. OnWorkflowActivated activity is required by all the SharePoint workflows. &lt;/p&gt;  &lt;p&gt;2. InvokeIntializeForEvent is a subclass of CallExternalMethodActivity with the following parameters:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Soxk0GzFA2I/AAAAAAAAAYI/YOCBsHh65C4/s1600-h/clip_image004%5B6%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh4.ggpht.com/_ElXg_EOWn5c/Soxk0jw953I/AAAAAAAAAYM/6h-lWqv8QJo/clip_image004_thumb%5B3%5D.jpg?imgmax=800" width="462" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The activity will invoke the InitializeForEvent method defined in the IListItemService interface. The signature of the method is:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[CorrelationParameter(&lt;span style="color: #006080"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;), CorrelationParameter(&lt;span style="color: #006080"&gt;&amp;quot;itemId&amp;quot;&lt;/span&gt;), CorrelationParameter(&lt;span style="color: #006080"&gt;&amp;quot;listId&amp;quot;&lt;/span&gt;), ExternalDataExchange, SharePointPermission(SecurityAction.LinkDemand, ObjectModel=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;), SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel=&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IListItemService&lt;br /&gt;{&lt;br /&gt;    ......&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; InitializeForEvent(Guid id, Guid listId, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; itemId);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&lt;/div&gt;

&lt;p&gt;
  &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td valign="top" width="678"&gt;
          &lt;p&gt;
            &lt;table border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;Parameter Name&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;Parameter Value&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;Description&lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;id&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;f1bb0cd5-e470-4e70-90ea-e37525a3662a&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;A GUID generated at development time&lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;itemId&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;1&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;The id for the “another list item” list item&amp;#160; in the &amp;quot;anotherlist&amp;quot; SharePoint list &lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;

                &lt;tr&gt;
                  &lt;td valign="top" width="108"&gt;
                    &lt;p&gt;listId&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="342"&gt;
                    &lt;p&gt;7c455073-56ce-4ecd-bfa8-2923fc521b9e&lt;/p&gt;
                  &lt;/td&gt;

                  &lt;td valign="top" width="225"&gt;
                    &lt;p&gt;The id of the &amp;quot;anotherlist&amp;quot; SharePoint list&lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;&lt;/table&gt;
          &lt;/p&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/p&gt;

&lt;p&gt;3. handeItemChangedEvent is a HandleExternalEvent activity with the following parameters:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soxk1bidPYI/AAAAAAAAAYQ/N2UtuYnqQuA/s1600-h/clip_image006%5B5%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh4.ggpht.com/_ElXg_EOWn5c/Soxk1x88sHI/AAAAAAAAAYU/PtiCF49jDLA/clip_image006_thumb%5B2%5D.jpg?imgmax=800" width="448" height="307" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This activity will wait on the OnItemChanged event defined in IListItemService interface. It should use the same Correlation Token, newtoken, for the activity prior to it. &lt;/p&gt;

&lt;p&gt;We can test the workflow with the following steps:&lt;/p&gt;

&lt;p&gt;1. Start the workflow for the &amp;quot;workflow item” list item in the &amp;quot;workflowlist&amp;quot; SharePoint list. The workflow should stop at &amp;quot;in progress&amp;quot; status since it is blocked and waiting for the OnItemChanged event.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soxk2P1WUGI/AAAAAAAAAYY/sZenqJvkeTQ/s1600-h/clip_image008%5B6%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh6.ggpht.com/_ElXg_EOWn5c/Soxk2jSjEvI/AAAAAAAAAYc/-Vr8y0QGm0E/clip_image008_thumb%5B3%5D.jpg?imgmax=800" width="447" height="171" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2. Modify the &amp;quot;another list item&amp;quot; list item in the &amp;quot;anotherlist&amp;quot; list and change its title to &amp;quot;another list item changed&amp;quot;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soxk3Rxx1jI/AAAAAAAAAYg/ZgUX-F_eCPc/s1600-h/clip_image010%5B7%5D.jpg"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxk34LR1eI/AAAAAAAAAYk/_BzH-_d3uyQ/clip_image010_thumb%5B4%5D.jpg?imgmax=800" width="488" height="246" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3. Go back to the workflow list. Its workflow status is changed to complete since step 2 modifies the list item and trigger OnItemChanged event.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxk4ISsfyI/AAAAAAAAAYo/3p7ba2XQQyw/s1600-h/image%5B8%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soxk4iKaqlI/AAAAAAAAAYs/GptqVTObZOY/image_thumb%5B6%5D.png?imgmax=800" width="514" height="291" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The solution demonstrates the following key points:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;IListItemService.InitializeForEvent should be invoked to establish the correlation token for a list item before you can capture the event for the list item. (You may use IListItemService.UpdateListItem, CheckInListItem, etc instead. ). &lt;/li&gt;

  &lt;li&gt;listId and itemId for InitializeForEvent must match the ids of the SharePoint list and list item. &lt;/li&gt;

  &lt;li&gt;id for InitalizeForEvent can be any uniquely generated GUID. It does not need to match any ids. &lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;&lt;b&gt;Scenario 2&lt;/b&gt;: A workflow needs to create an new list item and wait on its changed events. &lt;/h4&gt;

&lt;p&gt;In this case, you need to use IListItemSevice.CreateListItem to create the list. However, you cannot use the correlation token for CreateListItem because the &amp;quot;itemId&amp;quot; parameter is unknown while invoking the method.&amp;#160; You can get the itemId as a &amp;quot;returnvalue&amp;quot; in your workflow instead.&lt;/p&gt;

&lt;p&gt;So, here is the solution:&lt;/p&gt;

&lt;p&gt;1. Add a CallExternalMethod activity to invoke the &amp;quot;CreateListItem&amp;quot; method. The activity should include an event handler for MethodInvokded event. In the event handler, get the return value and assign the value to a member variable to the workflow.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnMethodInvoked(EventArgs e)&lt;br /&gt;{&lt;br /&gt;   &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ItemId = (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;)&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.ParameterBindings[&lt;span style="color: #006080"&gt;&amp;quot;(ReturnValue)&amp;quot;&lt;/span&gt;].Value;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&lt;/div&gt;

&lt;p&gt;2. Add an InitializeForEevnt activity to invoke the &amp;quot;InitializeForEvent&amp;quot; method. Make sure use the ItemId returned by CreateListItem. This activity should create a new token, which is different from the one for &amp;quot;CreateListItem&amp;quot;. The token for &amp;quot;CreateListItem&amp;quot; is basically not used any where.&lt;/p&gt;

&lt;p&gt;3. Add an HandleExteranlEvent activity as in Scenario 1. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-1506076511286110878?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/08/sharepoint-workflow-use.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/Soxkz91NcGI/AAAAAAAAAYE/1ZEwQ6rn33g/s72-c/clip_image002_thumb%5B2%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-2126160155847211939</guid><pubDate>Thu, 06 Aug 2009 02:15:00 +0000</pubDate><atom:updated>2009-08-19T19:15:45.230-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET General</category><title>Get LINQ to SQL Connection String from config file</title><description>&lt;p&gt;When using Visual Studio 2008 to create LINQ to SQL DBML file, it automatically generates database connection information for us. However most of the time, we want to get the connection string from a config file. Here is how to do that:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add ConnectionString to config file&lt;/li&gt; &lt;/ul&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configSections&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;add&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DotNetIdeasConnectionString&amp;quot;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #ff0000"&gt;connectionString&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Data Source=MyServer;Initial Catalog=DotNetIdeas;Integrated Security=True&amp;quot;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #ff0000"&gt;providerName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;System.Data.SqlClient&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Open the DBML file in designer mode. Clear the “Connection String” in properties&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/Soyxzgh8J0I/AAAAAAAAAYw/5f_ht-9gsuY/s1600-h/image%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Soyxz6AFzVI/AAAAAAAAAY0/oZRgpOUlEak/image_thumb.png?imgmax=800" width="244" height="161" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Add partial class, for example:&lt;/li&gt;
&lt;/ul&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; System.Configuration;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; DotNetIdeasData&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DotNetIdeasDataContext&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; DotNetIdeasDataContext()&lt;br /&gt;            : &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;(ConfigurationManager.ConnectionStrings[&lt;span style="color: #006080"&gt;&amp;quot;DotNetIdeasConnectionString&amp;quot;&lt;/span&gt;].ToString(), mappingSource)&lt;br /&gt;        {&lt;br /&gt;            OnCreated();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;One thing need to be pointed out here is that every time you modify the DBML file, you have to clear that “Connection String” in properties again. Because when you drag/drop tables to the designer, it re-generate everything!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-2126160155847211939?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/08/get-linq-to-sql-connection-string-from.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/Soyxz6AFzVI/AAAAAAAAAY0/oZRgpOUlEak/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-4034902227563904808</guid><pubDate>Fri, 31 Jul 2009 20:02:00 +0000</pubDate><atom:updated>2009-08-14T20:04:26.862-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Why are we getting "(1385) System.ComponentModel.Win32Exception: Logon failure: the user has not been granted the requested logon type at this computer"</title><description>SharePoint InfoPath Service can use SSO to access external resources such as web services and SQL server databases.&amp;#160; &lt;br /&gt; As explained at &lt;a title="http://blogs.msdn.com/infopath/archive/2006/06/27/advanced-server-side-authentication-for-data-connections-part-2.aspx" href="http://blogs.msdn.com/infopath/archive/2006/06/27/advanced-server-side-authentication-for-data-connections-part-2.aspx" target="_blank"&gt;MSDN site&lt;/a&gt;,&amp;#160; an InfoPath form can access external data sources through connection files. Behind the scene, the InfoPath runtime will get the credential to impersonate through SSO API and invoke LogOnUser function with the credential if Windows authentication is used.&amp;#160; &lt;br /&gt;You may run into the following exception while running an InfoPath form with SSO connections:  &lt;br /&gt;&lt;strong&gt;LogonUser failed for user 'domain\username' (1385) System.ComponentModel.Win32Exception: Logon failure: the user has not been granted the requested logon type at this computer&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/strong&gt;  &lt;br /&gt;If you Google&amp;#160; the exception for solution, you may find the advice to&amp;#160; give the delegated user “Allow Log on locally”&amp;#160; windows right. But, it won’t help. Even if you add the user to the local administrator group, it still doesn’t work. To solve this issue, we need to understand how InfoPath Service runtime impersonates with the credential configured in SSO. Writing a web part using SSO API and LogOnUser will help us to understand what is happening inside the InfoPath runtime.&amp;#160; &lt;br /&gt;The following code segment explains the three steps to use SSO in a web part:   &lt;br /&gt;  &lt;ul&gt;   &lt;li&gt;Retrieve the credential used to connect to the external database through SSO API; &lt;/li&gt;    &lt;li&gt;Impersonate the credential using LogonUser; &lt;/li&gt;    &lt;li&gt;Create a ADO connection to the database using Integrated Security;&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;div&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//*******************************************************************&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Step 1: Get the account for connecting to database from SSO API&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] strCredentialData = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Credentials.Get Credentials is a SharePoint SSO API&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;Credentials.GetCredentials(1, &lt;span style="color: #006080"&gt;&amp;quot;eex&amp;quot;&lt;/span&gt;, &lt;span style="color: blue"&gt;ref&lt;/span&gt; strCredentialData);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; strUserName = strCredentialData[0];&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;[] domainUserName = strUserName.Split('\\');&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; strPassword = strCredentialData[1];&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//***********************************************************************&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Step 2: Use LogOnUser to impersonate with the account&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;bool&lt;/span&gt; result = LogonUser(domainUserName[1], domainUserName[0],&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;strPassword,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;LogonSessionType.Batch,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;LogonProvider.Default,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;out&lt;/span&gt; token);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;WindowsIdentity id = &lt;span style="color: blue"&gt;new&lt;/span&gt; WindowsIdentity(token);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;impersonatedUser = id.Impersonate();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//************************************************************************&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: green"&gt;//Step 3:Use ADO.NET with Integrated Security to retrieve data from the external database.&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt; resultFromDb = &lt;span style="color: blue"&gt;null&lt;/span&gt;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; (SqlConnection connection = &lt;span style="color: blue"&gt;new&lt;/span&gt; SqlConnection(&lt;span style="color: #006080"&gt;&amp;quot;Integrated Security=SSPI;Initial Catalog=external_test;Data Source=sqlserver&amp;quot;&lt;/span&gt;))&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;connection.Open();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;SqlCommand command = &lt;span style="color: blue"&gt;new&lt;/span&gt; SqlCommand(&lt;span style="color: #006080"&gt;&amp;quot;select * from simple&amp;quot;&lt;/span&gt;, connection);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; (SqlDataReader reader = command.ExecuteReader())&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;reader.Read();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;resultFromDb = (&lt;span style="color: blue"&gt;string&lt;/span&gt;)reader[0];&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;connection.Close();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
The code above explains how, behind the scene, SharePoint Form Service is using LogOnUser to impersonate an account. So the reason we got the &amp;quot;LogonUser failed for user 'domain\username' (1385) System.ComponentModel.Win32Exception: Logon failure: the user has not been granted the requested logon type at this computer&amp;quot; is that SharePoint Form Service invokes LogonUser with &lt;strong&gt;Batch&lt;/strong&gt;&amp;#160; logon session type (the fourth parameter to LogonUser). Therefore, you need to configure the the security policy of your Web Front End to&amp;#160; give the delegated user “Log on as Batch” right. The following screen shot demonstrates the configuration.&amp;#160;&amp;#160; &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/SnNNtRb2ZfI/AAAAAAAAAWI/DZBp6d7s4KM/s1600-h/image%5B6%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="159" alt="image" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SnNNuAcXURI/AAAAAAAAAWM/T-P65Bb7zMc/image_thumb%5B4%5D.png?imgmax=800" width="734" border="0" /&gt;&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-4034902227563904808?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/infopath-service-single-sign-on.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_ElXg_EOWn5c/SnNNuAcXURI/AAAAAAAAAWM/T-P65Bb7zMc/s72-c/image_thumb%5B4%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-2468419765391395682</guid><pubDate>Thu, 30 Jul 2009 15:06:00 +0000</pubDate><atom:updated>2009-07-30T08:06:31.813-07:00</atom:updated><title>Developing Orientation-Aware and Dpi-Aware Smart Device Application in .NET</title><description>&lt;p&gt;When developing smart device application, we need to be aware of screen orientation and DPI(Dots Per Inch) since user’s device may vary. In this article, I am going to use a simple application to demonstrate how to create an Orientation-Aware and Dpi-Aware smart device application.&lt;/p&gt;  &lt;p&gt;You can also read this article and download the source code from &lt;a href="http://www.codeproject.com/KB/mobile/DpiAwareApp.aspx" target="_blank"&gt;Code Project&lt;/a&gt; web site.&lt;/p&gt;  &lt;p&gt;The following screen shot shows this application in Windows Mobile 6 Classic Emulator. It has some labels, textboxes and a button. But when you change the screen orientation to landscape, you will see the button disappeared. You have to scroll the screen to see it. That’s probably not a good idea for the user who prefer landscape screen. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/SnG2301K3AI/AAAAAAAAAVA/1e4GBTOes8E/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/_ElXg_EOWn5c/SnG24kZ1W-I/AAAAAAAAAVE/_lT63bl4wq8/clip_image002_thumb.jpg?imgmax=800" width="182" height="244" /&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/SnG249k3m-I/AAAAAAAAAVI/2tH-asZ_wJw/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh5.ggpht.com/_ElXg_EOWn5c/SnG25NY3xHI/AAAAAAAAAVM/87MxpqDnqPg/clip_image004_thumb.jpg?imgmax=800" width="244" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There is no easy way to solve this issue. If your form is not that crowded, you can try to squeeze everything into the upper half of the form. But in case you do have a lot of controls to display, one way to solve this issue is to create a landscape view of the form and dynamically re-position all the controls based on the screen orientation.&lt;/p&gt;  &lt;p&gt;Here we first create the Portrait view, copy the code regarding position and size and create a method called Portrait(). Then we rotate the design view to create the Landscape view and also create a method called Landscape().&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Portrait()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SuspendLayout();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(81, 232);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(72, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label0.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(45, 9);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label0.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(141, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(111, 32);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 21);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(16, 33);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(74, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(16, 70);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(74, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(111, 69);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 21);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ResumeLayout(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Landscape()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SuspendLayout();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(132, 152);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(72, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label0.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(101, 10);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label0.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(141, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(52, 39);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 21);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(3, 40);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(43, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(173, 40);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(54, 20);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(233, 39);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 21);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ResumeLayout(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Add the following code to Form’s Resize event, so it will change layout when the screen orientation is changed. Here we use Screen.PrimaryScreen.Bounds to determine the orientation.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Form1_Resize(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Screen.PrimaryScreen.Bounds.Height &amp;gt; &lt;br /&gt;    Screen.PrimaryScreen.Bounds.Width) Portrait();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; Landscape();&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Now it looks nice in Landscape orientation too.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/SnG25kxPW5I/AAAAAAAAAVQ/NwDZxBtTR40/s1600-h/clip_image006%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SnG25_PW-jI/AAAAAAAAAVU/2COMElJbpi0/clip_image006_thumb.jpg?imgmax=800" width="244" height="187" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, this solution works just fine until you have to run this application on a higher DPI device. Now let us change our emulator to Windows Mobile 6.1.4 Professional – VGA, which is 480x640.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SnG26BB8u6I/AAAAAAAAAVY/e1quTWDwtsk/s1600-h/clip_image008%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh6.ggpht.com/_ElXg_EOWn5c/SnG26TNTrxI/AAAAAAAAAVc/Tyrrx1_6FbQ/clip_image008_thumb.jpg?imgmax=800" width="186" height="244" /&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/SnG26jxsrjI/AAAAAAAAAVg/eBaCrSqwoTQ/s1600-h/clip_image010%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh5.ggpht.com/_ElXg_EOWn5c/SnG263FE5cI/AAAAAAAAAVk/tEKf9liWBrQ/clip_image010_thumb.jpg?imgmax=800" width="244" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It doesn’t look right, does it? Yes, that is because the two methods we added. If the actual device’s DPI is different from our designer, we cannot set the absolute position in our code and expect it displays everything correctly across different devices. &lt;/p&gt;

&lt;p&gt;You may be able to use “Dock” property to achieve some degree of flexibility. But when you have complicate layout, you may end up adding too many panels and it is not an easy thing to do.&lt;/p&gt;

&lt;p&gt;I found this &lt;a href=":/blogs.msdn.com/windowsmobile/archive/2005/12/15/DpiHelper.aspx"&gt;article&lt;/a&gt; about creating a DpiHelper for .NET CF 1.1. It provided a way to add High-Dpi support programmatically. I borrowed its idea and used it in this application to adjust controls’ location and size based on device’s DPI. Since we set the location and size in the Portrait() and Landscape() methods, we need to scale those settings after calling those methods. Below is the modified version of DpiHelper class:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;A helper object to adjust the sizes of controls based on the DPI.&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; DpiHelper&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;The real dpi of the device.&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; dpi = SafeNativeMethods.GetDeviceCaps(IntPtr.Zero, &lt;span style="color: #008000"&gt;/*LOGPIXELSX*/&lt;/span&gt;88);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IsRegularDpi&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (dpi == 96) &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;Adjust the sizes of controls to account for the DPI of the device.&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;parent&amp;quot;&amp;gt;The parent node of the tree of controls to adjust.&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AdjustAllControls(Control parent)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!IsRegularDpi)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Control child &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; parent.Controls)&lt;br /&gt;            {&lt;br /&gt;                AdjustControl(child);&lt;br /&gt;                AdjustAllControls(child);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AdjustControl(Control control)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (control.GetType() == &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(TabPage)) &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (control.Dock)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; DockStyle.None:&lt;br /&gt;                control.Bounds = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(&lt;br /&gt;                    control.Left * dpi / 96,&lt;br /&gt;                    control.Top * dpi / 96,&lt;br /&gt;                    control.Width * dpi / 96,&lt;br /&gt;                    control.Height * dpi / 96);&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; DockStyle.Left:&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; DockStyle.Right:&lt;br /&gt;                control.Bounds = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(&lt;br /&gt;                    control.Left,&lt;br /&gt;                    control.Top,&lt;br /&gt;                    control.Width * dpi / 96,&lt;br /&gt;                    control.Height);&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; DockStyle.Top:&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; DockStyle.Bottom:&lt;br /&gt;                control.Bounds = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Rectangle(&lt;br /&gt;                    control.Left,&lt;br /&gt;                    control.Top,&lt;br /&gt;                    control.Width,&lt;br /&gt;                    control.Height * dpi / 96);&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; DockStyle.Fill:&lt;br /&gt;                &lt;span style="color: #008000"&gt;//Do nothing;&lt;/span&gt;&lt;br /&gt;                &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;Scale a coordinate to account for the dpi.&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;x&amp;quot;&amp;gt;The number of pixels at 96dpi.&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Scale(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; x * dpi / 96;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; UnScale(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; x)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; x * 96 / dpi;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SafeNativeMethods&lt;br /&gt;    {&lt;br /&gt;        [DllImport(&lt;span style="color: #006080"&gt;&amp;quot;coredll.dll&amp;quot;&lt;/span&gt;)]&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; GetDeviceCaps(IntPtr hdc, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; nIndex);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;And here is how to use it:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Form1_Resize(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Screen.PrimaryScreen.Bounds.Height &amp;gt; Screen.PrimaryScreen.Bounds.Width) Portrait();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; Landscape();&lt;br /&gt;    DpiHelper.AdjustAllControls(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;As you can see in the following screen shot, everything is back to normal.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SnG27WAbZEI/AAAAAAAAAVo/DLXP4zHS9V8/s1600-h/clip_image012%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://lh3.ggpht.com/_ElXg_EOWn5c/SnG27v0jDrI/AAAAAAAAAVs/5wsDE0461hQ/clip_image012_thumb.jpg?imgmax=800" width="186" height="244" /&gt;&lt;/a&gt; &lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/SnG274OwI4I/AAAAAAAAAVw/Pc1tXnI09ww/s1600-h/clip_image014%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image014" border="0" alt="clip_image014" src="http://lh5.ggpht.com/_ElXg_EOWn5c/SnG28bp2i1I/AAAAAAAAAV0/W0OHG3lD0Pk/clip_image014_thumb.jpg?imgmax=800" width="244" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you use user controls in your form, you may want to modify the code to make it more generic. &lt;/p&gt;

&lt;p&gt;First, create an Interface called IRotatable.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IRotatable&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Portrait();&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Landscape();&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Second, create the user control, which implement IRotatable interface.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; UserControl1 : UserControl, IRotatable&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; UserControl1()&lt;br /&gt;    {&lt;br /&gt;        InitializeComponent();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #cc6633"&gt;#region&lt;/span&gt; IRotatable Members&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Portrait()&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SuspendLayout();&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(18, 13);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(43, 36);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(57, 96);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(72, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(43, 63);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(210, 134);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ResumeLayout(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Landscape()&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SuspendLayout();&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(49, 15);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.label1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(1, 38);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button1.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(62, 64);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.button1.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(72, 20);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox2.Location = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Point(107, 38);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.checkBox2.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(100, 20);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Size = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; System.Drawing.Size(210, 98);&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ResumeLayout(&lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #cc6633"&gt;#endregion&lt;/span&gt;&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Then modify the form to implement IRotatable interface too.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Form2 : Form, IRotatable&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Add new method to recursively loop though the form and all the controls in it.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Form2_Resize(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;    SetControlLocation(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetControlLocation(Control control)&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (control &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; IRotatable)&lt;br /&gt;    {&lt;br /&gt;        IRotatable rotatableControl = (IRotatable)control;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Screen.PrimaryScreen.Bounds.Height &amp;gt; Screen.PrimaryScreen.Bounds.Width) rotatableControl.Portrait();&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; rotatableControl.Landscape();&lt;br /&gt;    }&lt;br /&gt;    DpiHelper.AdjustControl(control);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (Control child &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; control.Controls)&lt;br /&gt;    {&lt;br /&gt;        SetControlLocation(child);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This is what it looks like with a user control.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SnG28jHSX7I/AAAAAAAAAV4/l3IIYQlWbME/s1600-h/clip_image016%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image016" border="0" alt="clip_image016" src="http://lh6.ggpht.com/_ElXg_EOWn5c/SnG28wuFjXI/AAAAAAAAAV8/X0CHek_whuA/clip_image016_thumb.jpg?imgmax=800" width="185" height="244" /&gt;&lt;/a&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/SnG29UfWWLI/AAAAAAAAAWA/mj6cYeaiHos/s1600-h/clip_image018%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image018" border="0" alt="clip_image018" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SnG29uAcTSI/AAAAAAAAAWE/tF8OI9dNrRE/clip_image018_thumb.jpg?imgmax=800" width="244" height="183" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;p&gt;&lt;a href="http://www.dotnetideas.com"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-2468419765391395682?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/developing-orientation-aware-and-dpi.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/SnG24kZ1W-I/AAAAAAAAAVE/_lT63bl4wq8/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-8382629138778399161</guid><pubDate>Thu, 23 Jul 2009 21:14:00 +0000</pubDate><atom:updated>2009-07-24T09:00:36.480-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Understand MOSS Search Run Time Architecture</title><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Understanding SharePoint Search Run Time Architecture is very helpful in planning/configuring SharePoint farm and troubleshooting Kerberos authentication. I recently read the following paragraph from &lt;a href="http://technet.microsoft.com/en-us/library/cc263044.aspx"&gt;Microsoft Web Site&lt;/a&gt; regarding SharePoint search planning:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;In Office SharePoint Server 2007, the index role is associated with a Shared Services Provider (SSP). The index role builds one index per SSP. One index server can be associated with multiple SSPs. However, indexes across SSPs cannot be combined. You can deploy multiple index servers to improve capacity. In this case, each index server is associated with different SSPs. Unlike the Windows SharePoint Services 3.0 search role, content indexes produced by the Office SharePoint Server 2007 index role are continuously propagated to all servers that host the query role in a farm. Consequently, the output of the Office SharePoint Server 2007 index server role (that is, the index) is considered redundant if the query role is deployed to more than one server computer.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Let me explain this in detail.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What are index role, query role, index server and query server?&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Index role&lt;/strong&gt; is a logic role or responsibility that crawls contents and build index files. &lt;strong&gt;Query role&lt;/strong&gt; is a logic role or responsibility that returns query results. &lt;strong&gt;Index Server/Query Server&lt;/strong&gt; is an &lt;b&gt;Office SharePoint Server Search&lt;/b&gt; Windows Service instance running on a server in the SharePoint Farm. The following picture shows the Services Console of a SharePoint Server:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_ElXg_EOWn5c/SmjSvrkhHII/AAAAAAAAAUg/oGKX71vRdHs/s1600-h/clip_image002%5B6%5D.jpg"&gt;&lt;img title="clip_image002" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="78" alt="clip_image002" src="http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSvw0eZ5I/AAAAAAAAAUk/Irdh7AHWCcI/clip_image002_thumb%5B3%5D.jpg?imgmax=800" width="709" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;An Office SharePoint Server Search&lt;/b&gt; Windows Service Instance can be configured to run as an index role, a query role or both. If an instance of MOSS Windows Search Service is configured as Index role. It is called Index Server. The same applies to the Search Role. &lt;/p&gt;  &lt;p&gt;To start and configure a Index or Search server, open SharePoint Central Administration. Click the operation tab and then click &amp;quot;Services on the Server&amp;quot;, the following window displays:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSwf-cKjI/AAAAAAAAAUo/8Ka86A1RgKU/s1600-h/clip_image004%5B6%5D.jpg"&gt;&lt;img title="clip_image004" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="326" alt="clip_image004" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SmjSwvsNANI/AAAAAAAAAUs/BYvLZGY5YGc/clip_image004_thumb%5B3%5D.jpg?imgmax=800" width="790" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Click the &amp;quot;Office SharePoint Server Search&amp;quot; link. The screen to configure the Server Role for the Office SharePoint Server Search displays:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/SmjSxEUkguI/AAAAAAAAAUw/rPs53QYWl9k/s1600-h/clip_image006%5B5%5D.jpg"&gt;&lt;img title="clip_image006" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="329" alt="clip_image006" src="http://lh5.ggpht.com/_ElXg_EOWn5c/SmjSxnKOzdI/AAAAAAAAAU0/ZZFnPXIiQZU/clip_image006_thumb%5B2%5D.jpg?imgmax=800" width="650" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In this page, you can determine what roles the instance of &lt;b&gt;Office SharePoint Server &lt;/b&gt;will play by selecting the check boxes at the top of the page.&lt;/p&gt;  &lt;p&gt;We know how to create Index and Search server for a SharePoint farm. In a SharePoint Farm, we can have multiple SSPs. Each SSP may have different contents to search. The question is which SSP the index and Search server will work for. To answer the question, we need to study another setting. While creating a SSP, you will be ask to choose an index server:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSx1kKFII/AAAAAAAAAU4/H77L6tveRq8/s1600-h/clip_image008%5B5%5D.jpg"&gt;&lt;img title="clip_image008" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="236" alt="clip_image008" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SmjSySrSI3I/AAAAAAAAAU8/mJWSyy3uyiQ/clip_image008_thumb%5B2%5D.jpg?imgmax=800" width="551" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The &amp;quot;Index Server&amp;quot; drop down list will allow you to choose which index server to use for the SSP. However, there is no selection for a Search Server. Therefore, we know:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;A SSP can have one and only one index server.&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;A Search Server will serve for all the SSPs created in the farm.&lt;/strong&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now, let us re-visit the paragraph from Microsoft Web Site using the knowledge we just learned:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;In Office SharePoint Server 2007, the index role is associated with a Shared Services Provider (SSP). The index role builds one index per SSP. One index server can be associated with multiple SSPs. However, indexes across SSPs cannot be combined. You can deploy multiple index servers to improve capacity. In this case, each index server is associated with different SSPs.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is in line with &amp;quot;A SSP can have one and only one index server&amp;quot;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Unlike the Windows SharePoint Services 3.0 search role, content indexes produced by the Office SharePoint Server 2007 index role are continuously propagated to all servers that host the query role in a farm. &lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It is in line with &amp;quot;A Search Server will serve all the SSPs created in the farm&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Consequently, the output of the Office SharePoint Server 2007 index server role (that is, the index) is considered redundant if the query role is deployed to more than one server computer.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;It basically says that you can scale out for Search Server. However, you cannot scale out for Index Server inside one instance of SSP. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-8382629138778399161?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/understand-moss-search-run-time.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_ElXg_EOWn5c/SmjSvw0eZ5I/AAAAAAAAAUk/Irdh7AHWCcI/s72-c/clip_image002_thumb%5B3%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3927883542614915375</guid><pubDate>Sat, 18 Jul 2009 13:39:00 +0000</pubDate><atom:updated>2009-07-24T12:27:41.481-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Interesting observation on SharePoint Security</title><description>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The article lists some SharePoint Security related facts/experience that may be helpful. Please add your comments if you think the list should expand&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Anonymous Users can add/edit/delete list items. However, they can never add/edit/delete document library items even though they can view document library items. &lt;/li&gt;    &lt;li&gt;It is not possible to make some of the items in a list/document library accessible to anonymous users while other items not accessible. All the items in a list/document library must have the same accessibility for anonymous users. &lt;/li&gt;    &lt;li&gt;You cannot add a Windows Group to Site Collection Administrators. You can only add individual users. It is by design. In my opinion, however, it is not convenient for administration.&lt;/li&gt;    &lt;li&gt;A common misconception is that a user in the Site Owner group can access all the contents in a site. In theory, you must check item level permission for all the items in all the lists to make sure a user can access all the contents in a site. To be complete, you need also to check the Security Policy for the web application. Never assume a site owner can do anything.&lt;/li&gt;    &lt;li&gt;Limited Access Permission Level is to be added by SharePoint automatically. For example, assuming a user does not have any permission in a SharePoint site, if you add an item level read permission to the user for an item of a list. The SharePoint will add Limited Access Permission Level to the user at the list and the site level automatically. &lt;/li&gt;    &lt;li&gt;SharePoint does not have the finest permission granularity. For example, it is not possible to have one user to have edit site title and image permission and the other to have delete child sub sites permission. This is because &amp;quot;Manage Web Site&amp;quot; permission includes both edit site title/image and delete child sub sites. This lack of finest permission does cause problem in practice since you have to assign the same people to perform two very different categories of administrative tasks.&lt;/li&gt;    &lt;li&gt;...... more to come&lt;/li&gt; &lt;/ol&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3927883542614915375?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/interesting-observation-on-sharepoint.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3140411727173915446</guid><pubDate>Fri, 17 Jul 2009 03:00:00 +0000</pubDate><atom:updated>2009-08-14T19:56:12.160-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint Security for the contents in _layouts, _controltemplates and _vti_bin directories in the context of SharePoint NTLM authentication</title><description>&lt;p&gt;A SharePoint web application can be accessed through multiple IIS web sites with different authentication such as NTLM, Kerberos and Form. It is important to differentiate a SharePoint Web Application and the IIS Web Sites accessing the SharePoint Web Application. Typically, each IIS Web Site accessing a SharePoint Web Application will correspond to a zone in SharePoint's Alternate Access Mapping. Each zone has a public address and multiple internal addresses. The multiple internal addresses typically map to addresses for load balancing. &lt;/p&gt;  &lt;p&gt;The article discusses the authorization on accessing the files in _layouts (application pages and resources), _controltemplates (user controls and resources) , _vti_bin ( web services) in the context of an IIS Web Site or Zone configured with NTLM authentication.&lt;/p&gt;  &lt;p&gt;If an IIS Web Site to access a SharePoint Web application is configured with NTLM authentication, the authorization to the contents in those directories is mostly determined by ASP.NET 2.0 Windows authentication mechanism. &lt;/p&gt;  &lt;p&gt;When a SharePoint IIS web site is configured with NTLM authentication, the web.config file of the web site has &amp;quot;Windows&amp;quot; as its authentication method. In Windows authentication, Asp.NET 2.0 actually relies on IIS to perform authentication (basic, digest and integrated). The IIS will produce a security token after the authentication and then pass the security token to ASP.NET. Then, ASP.NET will perform two types of authorization using the identity encapsulated in the security token.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;URL authorization (You can edit the web.config files in _layouts, _controltemplates and _vti_bin to define URL authorization)&lt;/li&gt;    &lt;li&gt;ACL authorization. This authorization does not occur for Form authentication.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;It is important to realize both authorizations will apply. Therefore, even if a user has URL authority to access an ASPX or image file, he/she may still not be able to access them due to the failure of ACL authorization.&lt;/p&gt;  &lt;p&gt;Notice, the &amp;quot;impersonate&amp;quot; will not affect the above process. It will only affect when you write server side code, for example, when you try to open a local file in your web part. SharePoint always has &amp;quot;impersonate&amp;quot; as true.&lt;/p&gt;  &lt;p&gt;In SharePoint NTLM (not Form) authentication, accessing the files and resources in _layouts, _controltemplates and _vti_bin pretty much follows the two authorization methods (URL and ACL) of ASP.NET 2.0. However, there is just one exception to the rule. For ASPX pages in the layouts directory that inherits from out-of-box class Microsoft.SharePoint.WebContorls.LayoutsPageBase, the class will check if the current SharePoint user has &amp;quot;View Application Pages&amp;quot; permission. So, it is the third authorization methods applied to those pages.&lt;/p&gt;  &lt;p&gt;Now add anonymous users to the mix. Like authenticated users, the authorization for anonymous users is pretty much determined by ASP.NET 2.0 with one exception that is the pages inheriting from Microsoft.SharePoint.WebContorls.LayoutsPageBase. There are some interesting things worth metioning:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;URL authorization will use question mark &amp;quot;?&amp;quot; to denote anonymous users;&lt;/li&gt;    &lt;li&gt;ACL authorization will use IUSR_MachineName account. (This account is configurable in IIS);&lt;/li&gt;    &lt;li&gt;Anonymous users can never load pages inheriting from Microsoft.SharePoint.WebContorls.LayoutsPageBase;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The first two are just typical ASP.NET 2.0 way of handling security. The third one is really a surprise. SharePoint anonymous users by default should have &amp;quot;limited access&amp;quot; permission level that should have &amp;quot;View Application Pages&amp;quot; permission. However, anonymous users still cannot access the pages inheriting from Microsoft.SharePoint.WebContorls.LayoutsPageBase even with the &amp;quot;View Application Page&amp;quot; permission. I could not explain why and just remember that this as an exceptional scenario. To expose SharePoint Application Page to anonymous users, do not use Microsoft.SharePoint.WebContorls.LayoutsPageBase as its base page class.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3140411727173915446?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/07/sharepoint-security-for-contents-in.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>1</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-5921342840003542339</guid><pubDate>Thu, 11 Jun 2009 18:29:00 +0000</pubDate><atom:updated>2009-06-23T11:50:19.071-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>ASP.NET</category><title>Web site display issues in IE8</title><description>&lt;p&gt;After upgrading to IE8, I notice our web site (&lt;a href="http://www.dotnetideas.com"&gt;www.dotnetideas.com&lt;/a&gt;) doesn&amp;#8217;t look pretty anymore. One issue is the dropdown menus are blank. I searched the internet and found several solutions. I just used the easiest one. That is to add the following to your style sheet and page.&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #cc6633"&gt;.IE8Fix&lt;/span&gt;  &lt;br /&gt;{  &lt;br /&gt;    z-index: &lt;span style="color: #006080"&gt;100;&lt;/span&gt;  &lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DynamicMenuStyle&lt;/span&gt; &lt;span style="color: #ff0000"&gt;CssClass&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IE8Fix&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Another issue I run into does not just happen in IE8, but also in FireFox. Our master page contains three columns. The left and right columns are set to float left and right. They are displayed nicely in IE7. But in IE8 and FireFox, the left column was squeezed when there is no content and the background image of the middle column was moved over to the far left. The solution to it is add the following line to the style sheet for the middle column&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;overflow&lt;/span&gt;:&lt;span style="color: #006080"&gt;hidden;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-5921342840003542339?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/06/web-site-display-issues-in-ie8.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-4924917235960015728</guid><pubDate>Thu, 14 May 2009 22:00:00 +0000</pubDate><atom:updated>2009-05-18T14:16:54.308-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET Compact Framework</category><title>.NET Compact Framework Programming Tips</title><description>&lt;h4&gt;How to get entry assembly path?&lt;/h4&gt;  &lt;div&gt;   &lt;div&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Simulate Assembly.GetEntryAssembly that is not supported by the Compact Framework.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;Path and name of first executable as a string.&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetEntryAssembly()
{
    StringBuilder sb = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
    IntPtr moduleHandler = GetCurrentModuleHandle();
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (IntPtr.Zero != moduleHandler)
    {
        sb = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder(255);
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (0 == SafeGetModuleFileName(moduleHandler, sb, sb.Capacity))
        {
            sb = &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
        }
    }
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sb.ToString();
}

&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Safe wrapper for PINVOKE GetModuleHandle.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;A handle to the current module indicates success.&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; IntPtr GetCurrentModuleHandle()
{
    IntPtr moduleName = IntPtr.Zero;
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetModuleHandle(moduleName);
}

&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Safe wrapper for PINVOKE GetModuleFileName.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;moduleHandler&amp;quot;&amp;gt;Handle to the module whose executable file name is being requested.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;moduleName&amp;quot;&amp;gt;Pointer to a buffer that is filled in with the path and file name of the given module. &amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;capacity&amp;quot;&amp;gt; Specifies the length, in characters, of the ModuleName buffer.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;The length, in characters, of the string copied to the buffer indicates success. &amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; Int32 SafeGetModuleFileName(IntPtr moduleHandler, StringBuilder moduleName, Int32 capacity)
{
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (capacity &amp;gt; 255)
    {
        capacity = 255;
    }
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetModuleFileName(moduleHandler, moduleName, capacity);
}

&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// PINVOKE that gets a module handle for the specified module if the file has been mapped into the address space of the calling process. &lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;moduleName&amp;quot;&amp;gt;Pointer to a null-terminated string that contains the name of the module, which must be a DLL file.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;A handle to the specified module indicates success.&amp;lt;/returns&amp;gt;&lt;/span&gt;
[System.Runtime.InteropServices.DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDll.dll&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; IntPtr GetModuleHandle(IntPtr moduleName);

&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// PINVOKE that gets a module file name.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;moduleHandler&amp;quot;&amp;gt;Handle to the module whose executable file name is being requested.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;moduleName&amp;quot;&amp;gt;Pointer to a buffer that is filled in with the path and file name of the given module. &amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name=&amp;quot;capacity&amp;quot;&amp;gt; Specifies the length, in characters, of the ModuleName buffer.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;The length, in characters, of the string copied to the buffer indicates success. &amp;lt;/returns&amp;gt;&lt;/span&gt;
[System.Runtime.InteropServices.DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDll.dll&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; Int32 GetModuleFileName(IntPtr moduleHandler, StringBuilder moduleName, Int32 capacity);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;How to set a form foreground?&lt;/h4&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetForegroundWindow(Form form)
{
    form.Capture = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;
    IntPtr hwnd = GetCapture();
    form.Capture = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;
    SetForegroundWindow(hwnd);
}

[System.Runtime.InteropServices.DllImport(&lt;span style="color: #006080"&gt;&amp;quot;coredll.dll&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; SetForegroundWindow(IntPtr hWnd);

[System.Runtime.InteropServices.DllImport(&lt;span style="color: #006080"&gt;&amp;quot;coredll.dll&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; IntPtr GetCapture();&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;h4&gt;How to get memory status?&lt;/h4&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Retrieves the memory status of the device&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; MemoryStatus GlobalMemoryStatus()
{
    MemoryStatus ms = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MemoryStatus();
    GlobalMemoryStatusCE(&lt;span style="color: #0000ff"&gt;out&lt;/span&gt; ms);
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ms;
}

[System.Runtime.InteropServices.DllImport(&lt;span style="color: #006080"&gt;&amp;quot;coredll&amp;quot;&lt;/span&gt;, EntryPoint = &lt;span style="color: #006080"&gt;&amp;quot;GlobalMemoryStatus&amp;quot;&lt;/span&gt;, SetLastError = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GlobalMemoryStatusCE(&lt;span style="color: #0000ff"&gt;out&lt;/span&gt; MemoryStatus msce);&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Below is the MemoryStatus structure used above&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Memory Status Structure&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;struct&lt;/span&gt; MemoryStatus
{
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Length of Structure&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;internal&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Length;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Specifies a number between 0 and 100 that gives a general idea of current memory utilization, in which 0 indicates no memory use and 100 indicates full memory use.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; MemoryLoad;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Indicates the total number of bytes of physical memory.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; TotalPhysical;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Indicates the number of bytes of physical memory available.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; AvailablePhysical;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Indicates the total number of bytes that can be stored in the paging file. Note that this number does not represent the actual physical size of the paging file on disk.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; TotalPageFile;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Indicates the number of bytes available in the paging file.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; AvailablePageFile;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Indicates the total number of bytes that can be described in the user mode portion of the virtual address space of the calling process.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; TotalVirtual;
    &lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// Indicates the number of bytes of unreserved and uncommitted memory in the user mode portion of the virtual address space of the calling process.&lt;/span&gt;
    &lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; AvailableVirtual;
}&lt;/pre&gt;
&lt;/div&gt;

&lt;h4&gt;How to prevent device fall asleep?&lt;/h4&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// This function resets a system timer that controls whether or not the&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// device will automatically go into a suspended state.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
[DllImport(&lt;span style="color: #006080"&gt;&amp;quot;CoreDll.dll&amp;quot;&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;extern&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SystemIdleTimerReset();&lt;/pre&gt;
&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-4924917235960015728?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/05/net-compact-framework-programming-tips.html</link><author>noreply@blogger.com (DotNetIdeas)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-2133392215358143008</guid><pubDate>Thu, 02 Apr 2009 23:40:00 +0000</pubDate><atom:updated>2009-04-28T19:19:41.581-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>Inside SharePoint SafeControl</title><description>&lt;p&gt;I saw quite a few times that while seeing security exception thrown from SharePoint, the first reaction is to add a SafeControl entry. SharePoint will tell you very clearly if you need to add any SafeControl entry in your Web.Config. Typically, you should see the error message similar to the following:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;Parser Error &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;Parser Error Message: The control type 'Dummy.DummyUnsafeWebPart' is not allowed on this page. The type is not registered as safe.&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;If you have not seen the message, do not try to add any SafeControl. SafeControl is a SharePoint-special security mechanism. A common MISTAKE is to assume a Dll will have full trust&amp;#160; if the Dll is added to the SafeControl list. &lt;/p&gt;

&lt;p&gt;The SafeContol entries are checked by SharePoint parser to make sure Controls are &amp;#8220;safe&amp;#8221; to be placed in a page declaratively. It is important to know that only SharePoint Parser honors SafeControl. After parsing stage,&amp;#160; SafeControl is out of Picture. This can be explained by the following sample code:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;[ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummySPWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummySPWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;public class DummySafeWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    protected override void CreateChildControls()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        this.Controls.Clear();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        this.Controls.Add(new Dummy.DummyUnsafeWebPart());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;[ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummyWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummyWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;public class DummyUnsafeWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    protected override void RenderContents(HtmlTextWriter output)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        output.Write(&amp;quot;Hello World&amp;quot;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;&amp;#160;&lt;/div&gt;

&lt;p&gt;The code shows the implementation of two web parts, DummySafeWebPart and DummyUnsafeWebPart. DummySafeWebPart just creates and adds an DummyUnsafeWebPart to its Children&amp;#8217;s collection. Add an SafeControl entry to Web.Config for DummySafeWebPart. Now, testing the following two scenarios:&lt;/p&gt;

&lt;p&gt;Scenario 1: A sharepoint page containing DummySafeWebPart only&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;SPDummy&amp;quot; namespace=&amp;quot;SPDummy&amp;quot; tagprefix=&amp;quot;SPDummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SPDummy:DummySafeWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Open the page in a Brower, it works fine.&lt;/p&gt;

&lt;p&gt;Scenario 2. A sharepoint page containing DummyUnsafeWebpart only:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;Dummy&amp;quot; namespace=&amp;quot;Dummy&amp;quot; tagprefix=&amp;quot;Dummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;META&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WebPartPageExpansion&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;content&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;full&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;head&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Dummy:DummyUnsafeWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;  &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Open the page in a Brower,&amp;#160; it throws exception:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/SdVM1QzKu5I/AAAAAAAAAUA/S0g8Rg_-LXw/s1600-h/image%5B2%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="64" alt="image" src="http://lh4.ggpht.com/_ElXg_EOWn5c/SdVM142jkjI/AAAAAAAAAUE/aA7fMEQhygE/image_thumb.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The two testing scenarios show that an &amp;#8220;unsafe&amp;#8221; control can be loaded by a &amp;#8220;safe&amp;#8221; control in sharepoint. However, if you place the &amp;#8220;unsafe&amp;#8221; control declaratively in a sharepoint content page, sharepoint will complain. This is becanse SharePoint Parser can not see the loading of unsafe control inside safecontrol. Parser can only see whatever controls your place &lt;strong&gt;declaratively&lt;/strong&gt; in a page. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-2133392215358143008?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/04/inside-sharepoint-safecontrol.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_ElXg_EOWn5c/SdVM142jkjI/AAAAAAAAAUE/aA7fMEQhygE/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-3871683526807230619</guid><pubDate>Sat, 28 Mar 2009 21:44:00 +0000</pubDate><atom:updated>2009-03-30T14:16:32.431-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>SharePoint</category><title>SharePoint, Trust Level and Code Access Security</title><description>&lt;p&gt;In Windows, there are two types of security mechanisms: Role based Security and Code Access Security. Role based security is easy to understand. Code Access Security(CAS) is to prevent &amp;#8220;Bad&amp;#8221; module from doing any damage. A&amp;#160; module is &amp;#8220;Bad&amp;#8221; if it does not just do what it claims to do. For example, you run a module downloaded from internet to display a nice screen saver. However, although the module displays the screen saver, it also silently sends your local files to a remote location. In this case, the module does not just do what supposed to do.    &lt;br /&gt;How does CAS prevent &amp;#8220;Bad&amp;#8221; module from doing any damage? It is achieve by two mechanisms working together.     &lt;br /&gt;1.&amp;#160;&amp;#160;&amp;#160; Configure CAS policy so the &amp;#8220;Bad&amp;#8221; module won&amp;#8217;t have the CAS permission to do damage such as sending files to a remote location.     &lt;br /&gt;2.&amp;#160;&amp;#160;&amp;#160; The code of sending file to a remote location must use CAS security Demand to demand the calling module to have the CAS permission. In case of sending files to a remote location. &amp;#8220;WebRequest&amp;#8221; CAS permission is demanded. Without the security demanding, configuring CAS policy is useless since CAS security enforcement typically starts with CAS permission demanding and then checks the security policy to see if the demanded permission is granted to the calling module.&amp;#160; &lt;br /&gt;While developing CAS strategy, in addition to configure CAS security policy, it is important to use the second mechanism so the code you wrote won&amp;#8217;t be used by &amp;#8220;Bad&amp;#8221; module to cause any damage. &lt;/p&gt;  &lt;p&gt;In SharePoint, it is a best practice to deploy your Dlls to the bin directory instead of GAC and configure minimum CAS permissions for the Dlls through CAS policy files. The tutorial will guide your through how to do it.&amp;#160; The tutorial will use a couple of&amp;#160; simple custom web parts, deploy them into the bin directory and use them in sharepoint content pages.&amp;#160; &lt;/p&gt;  &lt;p&gt;Lab 1: Deploy and use the first web part in SharePoint&lt;/p&gt;  &lt;p&gt;Step 1: Develop DummyWebPart, build a Dll (Dummy.dll), copy dummy.dll to the SharePoint&amp;#8217;s Bin directory&lt;/p&gt;  &lt;p&gt;The source code of the first web part &lt;strong&gt;DummyWebpart&lt;/strong&gt; is as the following&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;namespace Dummy&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    [ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummyWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummyWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    public class DummyWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        protected override void RenderContents(HtmlTextWriter output)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;            output.Write(&amp;quot;Hello World&amp;quot;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;DummyWepart writes &amp;#8220;Hello World&amp;#8221;. That is it! &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Step 2: Do not forget adding the following SafeControl entry to your web.config since we are using DummyWebPart in a Customized Content Page.&amp;#160; It is important to know &amp;#8220;SafeControl&amp;#8221; has nothing to do with Code Access Security. It is something used by SharePoint Page Parser to forbid unregistered WebControl in a &lt;strong&gt;customized&lt;/strong&gt; &lt;strong&gt;content&lt;/strong&gt; page! &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Assembly&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Dummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Namespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Dummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TypeName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Safe&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;Step 3: Create a SharePoint Content Page Dummy.aspx to host the DummyWebPart. The source code of Dummy.aspx is as the following&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;Dummy&amp;quot; namespace=&amp;quot;Dummy&amp;quot; tagprefix=&amp;quot;Dummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Dummy:DummyWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;DummyWebPart1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Now, open Dummy.aspx in the SharePoint site in a browser. It just works without any trouble&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aIj280CI/AAAAAAAAATo/z50z27kpMjU/s1600-h/image%5B2%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="156" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aJPhWapI/AAAAAAAAATs/zVwVlwV9e2E/image_thumb.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Lab 2: Deploy and use the second web part,DummySPWebPart, in SharePoint, which will cause Code Access Security Exception.&lt;/p&gt;

&lt;p&gt;Step 1: Develop DummySPWebPart, build a Dll (SPDummy.dll), copy the SPDummy.dll to Bin directory &lt;/p&gt;

&lt;p&gt;The source code of the second&amp;#160; web part&amp;#160; &lt;strong&gt;DummySPWepart&lt;/strong&gt; is as the following &lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;namespace SPDummy&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    [ToolboxData(&amp;quot;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;{0}:DummySPWebPart runat=server&lt;span style="color: #0000ff"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;{0}:DummySPWebPart&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&amp;quot;)]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    public class DummySPWebPart : WebPart&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;       &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;        protected override void RenderContents(HtmlTextWriter output)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;            output.Write(string.Format(&amp;quot;root web title is {0}&amp;quot;,SPContext.Current.Site.RootWeb.Title));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;        }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;DummySPWepart writes the Title of the SharePoint root web site. It invokes SPContent.Current.Site.RootWeb.Title in order to get the Tile. &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Step 2: Do not forget adding the following SafeControl entry to your web.config. &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;     &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControl&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Assembly&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SPDummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Namespace&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SpDummy&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;TypeName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Safe&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;     ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;SafeControls&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;Step 3: Create a SharePoint Content Page SPDummy.aspx to host the DummySPWebPart. The source code of SPDummy.aspx is as the following&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="background-color: #ffff00"&gt;&amp;lt;%@ Register assembly=&amp;quot;SPDummy&amp;quot; namespace=&amp;quot;SPDummy&amp;quot; tagprefix=&amp;quot;SPDummy&amp;quot; %&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt; &lt;span style="color: #ff0000"&gt;dir&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ltr&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;form1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;SPDummy:DummySPWebPart&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;form&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;body&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;html&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;div id="codeSnippetWrapper"&gt;Now, open SPDummy.aspx in the SharePoint site in a browser. You will get the following:&lt;/div&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Sc6aKFoDEUI/AAAAAAAAATw/7z-CAMRU914/s1600-h/image%5B8%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="383" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aLFuSrTI/AAAAAAAAAT0/xyCUDGjewJU/image_thumb%5B4%5D.png?imgmax=800" width="632" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The exception thrown is caused by invoking SPContext.Current.Site.RootWeb.Title, which requests for the CAS permission of type 'Microsoft.SharePoint.Security.SharePointPermission&amp;#8221;. However, the current security policy does not grant the SPDummy.dll the CAS permission. In Lab 3, we will grant the CAS &amp;#8220;SharePointPermission&amp;#8221; to SPDummy.dll by editing CAS security policy.&lt;/p&gt;

&lt;p&gt;Lab 3: Step by step guide on editing CAS&lt;/p&gt;

&lt;p&gt;Step 1: Create a custom policy file wss_custom.config by copying the out-of-box policy file 
  &lt;br /&gt;a.&amp;#160;&amp;#160;&amp;#160; Open directory &amp;#8220;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG&amp;#8221;. The directory contains the out-of-box policy files defining Wss_Medium and Wss_Minimal trust levels of SharePoint. 

  &lt;br /&gt;b.&amp;#160;&amp;#160;&amp;#160; Make a copy wss_minimaltrust.config in the same directory and rename it to wss_custom.config.&lt;/p&gt;

&lt;p&gt;Step 2: Refer to the &amp;#8220;wss_custom.config&amp;#8221; policy file from the web.config 
  &lt;br /&gt;a.&amp;#160;&amp;#160;&amp;#160; Add a new trustLevel entry to the web.config. The trustLevel points to the new policy file&amp;#160; wss_custom.config your created in step 1.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;securityPolicy&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;      ......&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;trustLevel&lt;/span&gt; &lt;span style="color: #ff0000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WSS_Custom&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;policyFile&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\wss_custom.config&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;securityPolicy&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;b.&amp;#160;&amp;#160;&amp;#160; Change &amp;lt;trust level=&amp;quot;WSS_Minimal&amp;quot; originUrl=&amp;quot;&amp;quot; /&amp;gt; to &amp;lt;trust level=&amp;quot;WSS_Custom&amp;quot; originUrl=&amp;quot;&amp;quot; /&amp;gt;&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;trust&lt;/span&gt; &lt;span style="color: #ff0000"&gt;level&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;WSS_Custom&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;originUrl&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;br /&gt;After the first two steps, your sharepoint web application starts to use the custom poplicy file, wss_custom.config. Rememeber the &amp;#8220;wss_custom.config&amp;#8221; is just a copy of the out-of-box &amp;#8220;wss_minimaltrust.config&amp;#8221;. Now, we need to modify the file.&lt;/p&gt;

&lt;p&gt;Step 3: Modify the &amp;#8220;wss_custom.config&amp;#8221; policy file so the Dlls in bin directory of the sharepoint web application have CAS SharepointPermission. You just need to add one IPermission element to an existing permissionset element as the follows:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;PermissionSet&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;NamedPermissionSet&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SPRestricted&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;&amp;lt;!-- add the following element --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;IPermission&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #ff0000"&gt;ObjectModel&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;True&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;&amp;lt;!-- end of the element --&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;PermissionSet&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Save your change and open SPDummy.aspx. Now, it works without any exception!&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/Sc6aLtEFqRI/AAAAAAAAAT4/8UP-MlTEfCI/s1600-h/image%5B11%5D.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="118" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aMaYlc4I/AAAAAAAAAT8/YfEAwQaF0aY/image_thumb%5B5%5D.png?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;How did I figure out to add the SharePointPermission to the SPRestricted permissionset? First, the exception message already tells you that we need to add SharePointPermission. So, you need to add IPermission element with SharePointPermission as its class.You can just use Version=&amp;#8221;1&amp;#8221;. The real catch is how to figure out adding ObjectModel=&amp;#8221;true&amp;#8221;. Go to &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.security.sharepointpermission_properties.aspx"&gt;http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.security.sharepointpermission_properties.aspx&lt;/a&gt;. You notice the SharePointPermission is a .NET class with three public properties. ObjectModel is one of them. What I did was to try each property and assign them to true. After a few tries, ObjectModel=&amp;#8221;True&amp;#8221; is the only one that really matters. There is no silver bullet here. 

  &lt;br /&gt;You should also ask why I choose to add it to SPRestricted PermissionSet. This requires a basic understanding of the structure of the CAS Policy file. Do a search on &amp;#8220;SPRestricted&amp;#8221; in the WSS_custom.config file. You will find the following element:&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;CodeGroup&lt;/span&gt; &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;UnionCodeGroup&amp;quot;&lt;/span&gt;  &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;PermissionSetName&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;SPRestricted&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;IMembershipCondition&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #ff0000"&gt;class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;UrlMembershipCondition&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;    &lt;span style="color: #ff0000"&gt;Url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;$AppDirUrl$/*&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;CodeGroup&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This is the code group that dictates the CAS permission for all the Dlls under &amp;quot;$AppDirUrl$ directory, which includes the bin directory. This code group uses &amp;#8220;SPRestricted&amp;#8221; permission set. That is why to add the IPermission element to the &amp;#8220;SPRestricted&amp;#8221; permissionset.&lt;/p&gt;

&lt;p&gt;NOTE, the tutorial explains the CAS security in SharePoint. In real world, you should use Windows SharePoint Packaging (WSP) to deploy the changes to CAS policy. This tutorial tells you what happens behind the scene. I will write another blog regarding the deployment in near future.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-3871683526807230619?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/03/sharepoint-trust-level-and-code-access.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_ElXg_EOWn5c/Sc6aJPhWapI/AAAAAAAAATs/zVwVlwV9e2E/s72-c/image_thumb.png?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-1850047779793623762.post-5177224916784242636</guid><pubDate>Wed, 18 Mar 2009 14:14:00 +0000</pubDate><atom:updated>2009-03-18T08:22:41.515-07:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>.NET General</category><title>Updating User Interface during long running process in .NET</title><description>When an application has long running process, you may need to notify the user interface by updating a text box or a progress bar, etc. I created the following application to demonstrate. This is a simple demo. When you click on &amp;quot;Test&amp;quot; button. The text box will be updated with progress information.   &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_ElXg_EOWn5c/ScEBqtCnKiI/AAAAAAAAATQ/hCA-S-xo5no/image%5B6%5D.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="190" alt="image" src="http://lh6.ggpht.com/_ElXg_EOWn5c/ScEBq2DlRtI/AAAAAAAAATU/rBCfHQb6SMI/image_thumb%5B2%5D.png" width="206" border="0" /&gt;&lt;/a&gt;   &lt;br /&gt;  &lt;div&gt;   &lt;div&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 5; i++)
    {
        Thread.Sleep(1000); &lt;span style="color: #008000"&gt;// do something&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span style="color: #006080"&gt;@&amp;quot;
line &amp;quot;&lt;/span&gt; + Convert.ToString(i);
    }
}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
The code above will update the text box, but only after the whole loop, i.e 5 seconds. That was because this is a single thread application. The update to the text box will be executed after the click event. 

&lt;br /&gt;

&lt;br /&gt;If you want real time update, you will need to create a thread.

&lt;br /&gt;

&lt;br /&gt;

&lt;div&gt;
  &lt;div&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    Thread thread = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thread(DoSomeWork);
    thread.Start();
}

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DoSomeWork()
{
    &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 5; i++)
    {
        Thread.Sleep(1000); &lt;span style="color: #008000"&gt;// do something&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span style="color: #006080"&gt;@&amp;quot;
line &amp;quot;&lt;/span&gt; + Convert.ToString(i);
    }
}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
But when you run the code above, you will get &amp;quot;Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.&amp;quot; exception

&lt;br /&gt;

&lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_ElXg_EOWn5c/ScEBrRETVjI/AAAAAAAAATY/7K_IM2N6V-A/image2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="149" alt="image" src="http://lh5.ggpht.com/_ElXg_EOWn5c/ScEBrtBV39I/AAAAAAAAATc/nQawwGlZlbw/image_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; 

&lt;br /&gt;

&lt;br /&gt;That was because the text box was created by the main thread. You can not access it directly from a new thread. There are a lot of articles talking about this issue. You may check &lt;a href="http://www.infosysblogs.com/microsoft/2006/10/cross_thread_ui_control_access.html"&gt;this one&lt;/a&gt;. Basically what they are saying is you need a way to call back from the new thread. Here is quote talking about the Control.InvokeRequired property from MSDN:

&lt;br /&gt;

&lt;br /&gt;

&lt;blockquote&gt;&lt;em&gt;Controls in Windows Forms are bound to a specific thread and are not thread safe. Therefore, if you are calling a control's method from a different thread, you must use one of the control's invoke methods to marshal the call to the proper thread. This property can be used to determine if you must call an invoke method, which can be useful if you do not know what thread owns a control. &lt;/em&gt;

  &lt;br /&gt;&lt;/blockquote&gt;
Below is the sample code. When you run it, you will see that the text box will be updated every second.

&lt;br /&gt;

&lt;br /&gt;

&lt;div&gt;
  &lt;div&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;partial&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Form1 : Form
{
    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UICallerDelegate(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i);

    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Form1()
    {
        InitializeComponent();
    }

    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; button1_Click(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        Thread thread = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thread(DoSomeWork);
        thread.Start();
    }

    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; DoSomeWork()
    {
        &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 5; i++)
        {
            Thread.Sleep(1000); &lt;span style="color: #008000"&gt;// do something&lt;/span&gt;
            UpdateTextbox(i);
        }
    }

    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateTextbox(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; i)
    {
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.InvokeRequired)
        {
            UICallerDelegate dlg = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UICallerDelegate(UpdateTextbox);
            BeginInvoke(dlg, i);
        }
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        {
            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span style="color: #006080"&gt;@&amp;quot;
 &amp;quot;&lt;/span&gt; + Convert.ToString(i);
        }
    }
}&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1850047779793623762-5177224916784242636?l=dotnetideasblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://dotnetideasblog.blogspot.com/2009/03/updating-user-interface-during-long.html</link><author>noreply@blogger.com (DotNetIdeas)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_ElXg_EOWn5c/ScEBq2DlRtI/AAAAAAAAATU/rBCfHQb6SMI/s72-c/image_thumb%5B2%5D.png' height='72' width='72'/><thr:total>0</thr:total></item></channel></rss>