<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Random Musings of Jeremy Jameson</title><subtitle type="html" /><id>http://blogs.msdn.com/jjameson/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/jjameson/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2009-10-17T06:54:00Z</updated><entry><title>Constraining Tables with CSS</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/11/01/constraining-tables-with-css.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/11/01/constraining-tables-with-css.aspx</id><published>2009-11-01T14:15:00Z</published><updated>2009-11-01T14:15:00Z</updated><content type="html">&lt;P&gt;Have your ever wanted to display data in a table but limit the size of the rows and columns within the table?&lt;/P&gt;
&lt;P&gt;For example, consider the classic master/detail view that we often find in software applications, in which items are shown in a summary table and each row provides a link to allow users to see more detail about the item.&lt;/P&gt;
&lt;P&gt;However, unlike the typical master/detail scenario, you need to limit the amount of real estate consumed on the page by the summary table. In addition, if text within a column is too long to fit within the constrained area, you want to show the full text when the mouse cursor hovers over the cell.&lt;/P&gt;
&lt;P&gt;The following figure illustrates the desired end result:&lt;/P&gt;
&lt;DIV class=image&gt;&lt;IMG title="" alt="" src="http://blogs.msdn.com/photos/jjameson/images/9915847/500x148.aspx" width=500 height=148 mce_src="http://blogs.msdn.com/photos/jjameson/images/9915847/500x148.aspx"&gt; 
&lt;DIV class=caption&gt;Figure 1: Constrained table&lt;/DIV&gt;
&lt;DIV class=imageLink&gt;&lt;A href="http://blogs.msdn.com/photos/jjameson/images/9915847/original.aspx" target=_blank mce_href="http://blogs.msdn.com/photos/jjameson/images/9915847/original.aspx"&gt;See full-sized image.&lt;/A&gt; &lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Here is the sample ASP.NET page that I created this morning to demonstrate this:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;%&lt;SPAN style="COLOR: #0000ff"&gt;@&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;Page&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Language&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="C#"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;AutoEventWireup&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&lt;BR&gt;    &lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;CodeBehind&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ConstrainedTable.aspx.cs"&lt;BR&gt;   &lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Inherits&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Fabrikam.Demo.Web.UI.ConstrainedTable"&lt;/SPAN&gt; %&amp;gt;

&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;!&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DOCTYPE&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;html&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;PUBLIC&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;

&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;html&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://www.w3.org/1999/xhtml"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;head&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;title&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;Demo - Constrained Tabular Data&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;title&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: #a31515"&gt;link&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;rel&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Stylesheet"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;href&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="http://meyerweb.com/eric/tools/css/reset/reset.css"&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: #a31515"&gt;style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #008000"&gt;/* Basic formatting
        ----------------------------------------------------------------------*/
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #a31515"&gt;body&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;color&lt;/SPAN&gt;:&lt;SPAN style="COLOR: #0000ff"&gt;#000000&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;font-family&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;Verdana,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Arial,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Helvetica&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;font-size&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;small&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;margin&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;10px&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;h1&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;h2&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;h3&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;h4&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;h5&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;h6&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;strong&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;font-weight&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;bold&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;h1&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;font-size&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;1.5em&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;margin&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;.67em&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;0&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;table&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;caption&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;font-weight&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;bold&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;margin&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;10px&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;0&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;table.displayTable&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;border-left&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;1px&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;solid&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;#36295E&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;border-right&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;1px&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;solid&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;#36295E&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;margin&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;1em&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;0&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;table.displayTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;th&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;text-align&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;left&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;table.displayTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;th&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;table.displayTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;td&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;border-bottom&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;1px&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;solid&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;#36295E&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;padding&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;5px&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;10px&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;vertical-align&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;top&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;table.displayTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;thead&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;th&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;background&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;#36295E&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;color&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;#FFF&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;padding&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;8px&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;10px&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;border-bottom-width&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;0&lt;/SPAN&gt;;
        }        
        &lt;SPAN style="COLOR: #a31515"&gt;table.displayTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;tr.altRow&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;background&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;#F4F4F4&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #008000"&gt;/* =constrainedTable
        ----------------------------------------------------------------------*/
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #a31515"&gt;table.constrainedTable&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;table-layout&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;fixed&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;width&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;540px&lt;/SPAN&gt;;
        }
        &lt;SPAN style="COLOR: #a31515"&gt;table.constrainedTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;th.nameColumn&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;width&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;140px&lt;/SPAN&gt;;
        }        
        &lt;SPAN style="COLOR: #a31515"&gt;table.constrainedTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;td&lt;/SPAN&gt; {
            &lt;SPAN style="COLOR: #ff0000"&gt;overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;hidden&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;-o-text-overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;ellipsis&lt;/SPAN&gt;; &lt;SPAN style="COLOR: #008000"&gt;/* Opera */
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;text-overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;ellipsis&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #ff0000"&gt;white-space&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;nowrap&lt;/SPAN&gt;;
        }
    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;style&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;head&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;body&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: #a31515"&gt;form&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;id&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="form1"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;h1&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;Demo - Constrained Tabular Data&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;h1&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ConstrainedGrid"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;AutoGenerateColumns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;Caption&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Constrained Table"
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="displayTable constrainedTable"
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;OnRowDataBound&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="ConstrainedGrid_RowDataBound"
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;EnableViewState&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="false"
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff0000"&gt;UseAccessibleHeader&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"&amp;gt;
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;AlternatingRowStyle&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="altRow"&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: #a31515"&gt;RowStyle&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="row"&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: #a31515"&gt;Columns&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HyperLinkField
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;DataTextField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Site"
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;DataNavigateUrlFields&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="URL"
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;HeaderText&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Site"
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;HeaderStyle-CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="nameColumn"&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;BoundField
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;DataField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Notes"
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;HeaderText&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Notes"
&lt;/SPAN&gt;                    &lt;SPAN style="COLOR: #ff0000"&gt;HeaderStyle-CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="notesColumn"&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: #a31515"&gt;Columns&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&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: #a31515"&gt;form&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;body&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;html&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;The most interesting parts of the ASP.NET page are the CSS rules for the &lt;CODE&gt;&lt;SPAN style="COLOR: #a31515"&gt;constrainedTable&lt;/SPAN&gt; &lt;/CODE&gt;class:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #a31515"&gt;table.constrainedTable&lt;/SPAN&gt; {
    &lt;SPAN style="COLOR: #ff0000"&gt;table-layout&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;fixed&lt;/SPAN&gt;;
    &lt;SPAN style="COLOR: #ff0000"&gt;width&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;540px&lt;/SPAN&gt;;
}
&lt;SPAN style="COLOR: #a31515"&gt;table.constrainedTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;th.nameColumn&lt;/SPAN&gt; {
    &lt;SPAN style="COLOR: #ff0000"&gt;width&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;140px&lt;/SPAN&gt;;
}        
&lt;SPAN style="COLOR: #a31515"&gt;table.constrainedTable&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;td&lt;/SPAN&gt; {
    &lt;SPAN style="COLOR: #ff0000"&gt;overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;hidden&lt;/SPAN&gt;;
    &lt;SPAN style="COLOR: #ff0000"&gt;-o-text-overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;ellipsis&lt;/SPAN&gt;; &lt;SPAN style="COLOR: #008000"&gt;/* Opera */
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #ff0000"&gt;text-overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;ellipsis&lt;/SPAN&gt;;
    &lt;SPAN style="COLOR: #ff0000"&gt;white-space&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;nowrap&lt;/SPAN&gt;;
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Changing the &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;table-layout &lt;/SPAN&gt;&lt;/CODE&gt;to &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;fixed &lt;/SPAN&gt;&lt;/CODE&gt;constrains the table to the specified width. Since I don't specify a width for the &lt;CODE&gt;&lt;SPAN style="COLOR: #a31515"&gt;notesColumn&lt;/SPAN&gt; &lt;/CODE&gt;it consumes the remaining width of the table.&lt;/P&gt;
&lt;P&gt;Next, I specify that all cells in the constrained table should truncate the text within each cell if it is too wide to fit within the width of the column. This is achieved using the combination of &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;overflow&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;hidden&lt;/SPAN&gt;&lt;/CODE&gt; and &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;white-space&lt;/SPAN&gt;: &lt;SPAN style="COLOR: #0000ff"&gt;nowrap&lt;/SPAN&gt;&lt;/CODE&gt;. Finally, I use the &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;&lt;A href="http://www.css3.info/preview/text-overflow/" mce_href="http://www.css3.info/preview/text-overflow/"&gt;text-overflow&lt;/A&gt; &lt;/SPAN&gt;&lt;/CODE&gt;CSS property to show ellipsis when text within a cell is clipped (as well as a slight variation for the Opera browser).&lt;/P&gt;
&lt;BLOCKQUOTE class=note&gt;
&lt;DIV class=noteTitle&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;Support for the &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;text-overflow&lt;/SPAN&gt;&lt;/CODE&gt; CSS property is somewhat limited. In particular, you will find that a clipped table cell renders without the ellipsis in Firefox (at least in version 3.5.3). Oddly enough, this appears to have been supported in Internet Explorer since version 6. In addition to Internet Explorer and Opera, this also appears as expected in Safari.&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Also note that constraining table cells using CSS does not automatically display the tooltip with the complete text. For that, you are on your own.&lt;/P&gt;
&lt;P&gt;When using an ASP.NET GridView control, I recommend using the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx"&gt;RowDataBound&lt;/A&gt; event in order to set the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tooltip.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.tooltip.aspx"&gt;ToolTip&lt;/A&gt; property of the table cell. Just be sure to decode the contents of the cell to avoid having it encoded twice:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; ConstrainedGrid_RowDataBound(
            &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender,
            &lt;SPAN style="COLOR: #2b91af"&gt;GridViewRowEventArgs&lt;/SPAN&gt; e)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;TableCell&lt;/SPAN&gt; cell &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; e.Row.Cells)
            {
                &lt;SPAN style="COLOR: #008000"&gt;// Note: We need to decode the cell text in order to avoid
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #008000"&gt;// having it encoded twice (e.g. "&amp;amp;amp;gt;")
&lt;/SPAN&gt;                cell.ToolTip = &lt;SPAN style="COLOR: #2b91af"&gt;HttpUtility&lt;/SPAN&gt;.HtmlDecode(cell.Text);
            }
        }&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;This is somewhat of a "brute force" approach since it makes no attempt to determine if the text will be truncated, but rather sets the ToolTip (in other words, the title attribute on the HTML element) for every cell. However, the simplicity of this approach -- and the resulting user experience -- far outweighs any extraneous markup (at least in my opinion).&lt;/P&gt;
&lt;P&gt;Be aware that this simple approach for setting the ToolTip property doesn't support columns generated from a &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx"&gt;HyperLinkField&lt;/A&gt;, in which case &lt;CODE&gt;cell.Text&lt;/CODE&gt; is empty (because the cell contains child controls, not simple text). In other words, it's a good thing my demo doesn't specify very long site names that don't fit within the 140 pixel width column constraint ;-)&lt;/P&gt;
&lt;P&gt;Here is the complete code-behind for my sample ASP.NET page so you can run it yourself:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Data;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Globalization;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Web;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Web.UI.WebControls;

&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Demo.Web.UI
{
    &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; &lt;SPAN style="COLOR: #2b91af"&gt;ConstrainedTable&lt;/SPAN&gt; : System.Web.UI.&lt;SPAN style="COLOR: #2b91af"&gt;Page
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; Page_PreRender(
            &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender,
            &lt;SPAN style="COLOR: #2b91af"&gt;EventArgs&lt;/SPAN&gt; e)
        {
            BindSampleData(&lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;.ConstrainedGrid);

            &lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;.ConstrainedGrid.HeaderRow.TableSection =
                &lt;SPAN style="COLOR: #2b91af"&gt;TableRowSection&lt;/SPAN&gt;.TableHeader;
        }

&lt;SPAN style="COLOR: #0000ff"&gt;        #region&lt;/SPAN&gt; BindSampleData

        &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;void&lt;/SPAN&gt; BindSampleData(
            &lt;SPAN style="COLOR: #2b91af"&gt;GridView&lt;/SPAN&gt; grid)
        {
            &lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt; sampleData = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt;();
            sampleData.Locale = &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture;

            sampleData.Columns.Add(&lt;SPAN style="COLOR: #a31515"&gt;"Site"&lt;/SPAN&gt;);
            sampleData.Columns.Add(&lt;SPAN style="COLOR: #a31515"&gt;"URL"&lt;/SPAN&gt;);
            sampleData.Columns.Add(&lt;SPAN style="COLOR: #a31515"&gt;"Notes"&lt;/SPAN&gt;);

            sampleData.Rows.Add(
                &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;[]
                {
                    &lt;SPAN style="COLOR: #a31515"&gt;"Microsoft"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"http://www.microsoft.com"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;"Morbi at sem lorem, ac blandit leo. Phasellus at"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;"ligula vitae enim dignissim tincidunt ornare nisl."
&lt;/SPAN&gt;                });

            sampleData.Rows.Add(
                &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;[]
                {
                    &lt;SPAN style="COLOR: #a31515"&gt;"MSDN"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"http://msdn.microsoft.com"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Sed posuere mattis egestas. Aliquam commodo dolor"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" vulputate odio lacinia bibendum. Nullam bibendum,"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" neque vitae ullamcorper elementum, ligula dolor"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" mollis erat, ut ultricies mauris tortor ut eros."
&lt;/SPAN&gt;                });

            sampleData.Rows.Add(
                &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt;[]
                {
                    &lt;SPAN style="COLOR: #a31515"&gt;"TechNet"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"http://technet.microsoft.com"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Vestibulum a leo nisl, sit amet porta eros. Proin vitae"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" semper nunc. In facilisis nunc sit amet lacus"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" accumsan mattis. Nulla facilisi. Pellentesque nisl"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" sapien, dignissim ultrices semper et, mollis"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" interdum sem. "
&lt;/SPAN&gt;                });
            
            grid.DataSource = sampleData;
            grid.DataBind();
        }

&lt;SPAN style="COLOR: #0000ff"&gt;        #endregion

&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; ConstrainedGrid_RowDataBound(
            &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; sender,
            &lt;SPAN style="COLOR: #2b91af"&gt;GridViewRowEventArgs&lt;/SPAN&gt; e)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;TableCell&lt;/SPAN&gt; cell &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; e.Row.Cells)
            {
                &lt;SPAN style="COLOR: #008000"&gt;// Note: We need to decode the cell text in order to avoid
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #008000"&gt;// having it encoded twice (e.g. "&amp;amp;amp;gt;")
&lt;/SPAN&gt;                cell.ToolTip = &lt;SPAN style="COLOR: #2b91af"&gt;HttpUtility&lt;/SPAN&gt;.HtmlDecode(cell.Text);
            }
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915855" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Web Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Web+Development/default.aspx" /></entry><entry><title>Recommendations for Code Analysis</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/31/recommendations-for-code-analysis.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/31/recommendations-for-code-analysis.aspx</id><published>2009-10-31T13:44:00Z</published><updated>2009-10-31T13:44:00Z</updated><content type="html">&lt;P&gt;In my &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/31/recommended-check-in-policies-for-team-foundation-server.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/31/recommended-check-in-policies-for-team-foundation-server.aspx"&gt;previous post&lt;/A&gt;, I briefly mentioned the Code Analysis feature of Visual Studio in the context of using check-in policies with Team Foundation Server (TFS). However, there's a lot more to talk about with regards to using Code Analysis.&lt;/P&gt;
&lt;P&gt;If you are ever find yourself "starting from a clean slate" on a software development project, I hope you take advantage of the opportunity to not only enable Code Analysis, but also to treat all Code Analysis warnings as errors. That's right, go ahead and check all of those boxes (for both &lt;STRONG&gt;Debug &lt;/STRONG&gt;and &lt;STRONG&gt;Release &lt;/STRONG&gt;configurations, of course) so that whenever potential issues are reported by Code Analysis, it stops developers dead in their tracks and considers the build to be broken.&lt;/P&gt;
&lt;P&gt;While you're at it, go ahead and select the &lt;STRONG&gt;All &lt;/STRONG&gt;option in the &lt;STRONG&gt;Treat warnings as errors &lt;/STRONG&gt;section on the &lt;STRONG&gt;Build &lt;/STRONG&gt;tab (something I definitely recommend as a best practice). Again, be sure to do this for all build configurations.&lt;/P&gt;
&lt;P&gt;Yes, this is going to be really painful for some developers.&lt;/P&gt;
&lt;P&gt;For example, you can say goodbye to using the overload of string.Format() that doesn't specify a CultureInfo:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; foo = &lt;SPAN style="COLOR: #a31515"&gt;"here"&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; logMessage = &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Format(
                &lt;SPAN style="COLOR: #a31515"&gt;"Imagine something interesting {0}."&lt;/SPAN&gt;,
                foo);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Attempting this will now result in a broken build:&lt;/P&gt;
&lt;BLOCKQUOTE class="directQuote errorMessage"&gt;Error 2 CA1305 : Microsoft.Globalization : Because the behavior of 'string.Format(string, object)' could vary based on the current user's locale settings, replace this call in 'Program.Main(string[])' with a call to 'string.Format(IFormatProvider, string, params object[])'. If the result of 'string.Format(IFormatProvider, string, params object[])' will be displayed to the user, specify 'CultureInfo.CurrentCulture' as the 'IFormatProvider' parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'. &lt;/BLOCKQUOTE&gt;
&lt;P&gt;To avoid the CA1305 error, you will need to use something like this instead:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; foo = &lt;SPAN style="COLOR: #a31515"&gt;"here"&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; logMessage = &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Format(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Imagine something interesting {0}."&lt;/SPAN&gt;,
                foo);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;You will also need to enable signing of all assemblies with a strong name key, and also specify various assembly level attributes (e.g. &lt;A href="http://msdn.microsoft.com/en-us/library/system.clscompliantattribute.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.clscompliantattribute.aspx"&gt;&lt;CODE&gt;[assembly: CLSCompliant(true)]&lt;/CODE&gt;&lt;/A&gt;). However, if you follow the steps I've provided in a &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx"&gt;previous post&lt;/A&gt;, this should only take you at most 1-2 minutes.&lt;/P&gt;
&lt;P&gt;Like I said before, this will probably cause some heartburn in the beginning, but trust me, developers will quickly get used to it and the code they write will be much better as a result.&lt;/P&gt;
&lt;P&gt;Now what about the other 99% of the time when you aren't starting from a clean slate, but instead are dealing with a substantial code base that causes the Code Analysis feature in Visual Studio to "light up like a Christmas tree" when you turn it on?&lt;/P&gt;
&lt;P&gt;Well, as with all software bugs, it all comes down to &lt;EM&gt;triage&lt;/EM&gt;. You obviously cannot simply halt all feature development in order to resolve code analysis issues. Instead, you should go for the "low hanging fruit" (meaning the issues that occur frequently but can be resolved with relatively little effort or risk of changing). You should also try to enable the Code Analysis rules that are most important, such as potential security issues.&lt;/P&gt;
&lt;P&gt;The following post provides some great information about which Code Analysis warnings to focus your attention on first:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;What rules do Microsoft have turned on internally? 2007-08-09.&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="http://blogs.msdn.com/fxcop/archive/2007/08/09/what-rules-do-microsoft-have-turned-on-internally.aspx" mce_href="http://blogs.msdn.com/fxcop/archive/2007/08/09/what-rules-do-microsoft-have-turned-on-internally.aspx"&gt;http://blogs.msdn.com/fxcop/archive/2007/08/09/what-rules-do-microsoft-have-turned-on-internally.aspx&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;This article is obviously a little dated, but still very relevant over two years later.&lt;/P&gt;
&lt;P&gt;Note that you will undoubtedly need to &lt;A href="http://msdn.microsoft.com/en-us/library/ms244717.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms244717.aspx"&gt;suppress some specific Code Analysis warnings&lt;/A&gt; from time to time, and therefore you'll have to choose how to suppress the warnings (whether inline within the source, or in a GlobalSuppressions.cs file). However, I hope you'll choose to fix the underlying issue that causes the Code Analysis warning (whenever practical) instead of simply suppressing a bunch of warnings.&lt;/P&gt;
&lt;P&gt;So, in conclusion, think of the Code Analysis feature in Visual Studio as a way of &lt;EM&gt;choosing&lt;/EM&gt; a more strict compiler. For example, back in the days when I used to program in C on Unix, the compiler wouldn't complain when I wrote something like this (even though this is obviously very wrong):&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (i = 1)
            {
                ...
            }&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;I was relieved when I switched to C++ and these kinds of bugs were a thing of the past. [Note that I never switch my coding style to use something like "&lt;CODE&gt;1 == i&lt;/CODE&gt;" in order to avoid these errors.]&lt;/P&gt;
&lt;P&gt;Fortunately, in C# you don't have a choice about whether or not this compiles (it doesn't).&lt;/P&gt;
&lt;P&gt;I like to think of enabling all of the Code Analysis rules in a similar fashion. In other words, I want the compiler to tell me whenever I am doing something potentially wrong, because then I can spend just a little bit of time fixing my code to do it right. By forcing the Code Analysis warnings as errors, I don't have a choice -- meaning I have to fix them before check-in.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915654" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="Core Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Core+Development/default.aspx" /><category term="Visual Studio" scheme="http://blogs.msdn.com/jjameson/archive/tags/Visual+Studio/default.aspx" /></entry><entry><title>Recommended Check-In Policies for Team Foundation Server</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/31/recommended-check-in-policies-for-team-foundation-server.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/31/recommended-check-in-policies-for-team-foundation-server.aspx</id><published>2009-10-31T12:14:00Z</published><updated>2009-10-31T12:14:00Z</updated><content type="html">&lt;P&gt;I love using Team Foundation Server (TFS). There's just an amazing amount of "goodness" for software development that comes out-of-the-box; and there's even more available from Microsoft and other sources in the form of add-ons (many of which are free).&lt;/P&gt;
&lt;P&gt;From a source control perspective, one of my favorite features is check-in policies. Anything that improves the quality of software development with minimal effort is really a "&lt;A href="http://wordnetweb.princeton.edu/perl/webwn?s=no-brainer" mce_href="http://wordnetweb.princeton.edu/perl/webwn?s=no-brainer"&gt;no-brainer&lt;/A&gt;" in my opinion.&lt;/P&gt;
&lt;P&gt;The check-in policies that I prefer to have configured on all TFS projects are listed in the following table.&lt;/P&gt;
&lt;TABLE class=accent1 cellSpacing=0 class="accent1"&gt;
&lt;CAPTION&gt;Recommended TFS Check-In Policies&lt;/CAPTION&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH&gt;Policy Type&lt;/TH&gt;
&lt;TH&gt;Description&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Builds&lt;/TD&gt;
&lt;TD&gt;This policy requires that any code changes have been compiled and the last build was successful.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Work Items&lt;/TD&gt;
&lt;TD&gt;This policy requires that one or more work items be associated with every check-in.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Changeset Comments Policy&lt;/TD&gt;
&lt;TD&gt;Reminds users to add meaningful comments to their check-ins.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Code Analysis&lt;/TD&gt;
&lt;TD&gt;This policy requires that Code Analysis is run with a defined set of rules before check-in.&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Testing Policy&lt;/TD&gt;
&lt;TD&gt;Ensures that tests from specific test lists are successfully executed before checking in.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;The first two check-in policies are virtually painless and can be applied to any existing project at any time. These policies ship with Visual Studio Team System 2008, and assuming your developers have good software development discipline already, there's absolutely no reason not to enable these policies.&lt;/P&gt;
&lt;P&gt;After all, why would any developer want to check-in code that hasn't been verified to at least compile? Similarly, why would a developer make a code change that isn't specifically related to a work item (even if that work item is simply something like "Refactor X" or "Code cleanup (M5)")?&lt;/P&gt;
&lt;P&gt;However, the last three policies in the table above require a little more effort.&lt;/P&gt;
&lt;P&gt;The Changeset Comments Policy is included in the &lt;A href="http://msdn.microsoft.com/en-us/teamsystem/bb980963.aspx" mce_href="http://msdn.microsoft.com/en-us/teamsystem/bb980963.aspx"&gt;Team Foundation Server Power Tools&lt;/A&gt;, which means that every member of the Development team will need to download and install this in order to use it. (Note that if you don't have the Power Tools installed, you can still override the check-in policy in order to avoid being blocked.)&lt;/P&gt;
&lt;P&gt;The Code Analysis policy can definitely cause a little heartburn for your Development team, depending on how many code analysis rules you enable and whether or not you treat these warnings as errors. I'll talk more about Code Analysis in a separate post.&lt;/P&gt;
&lt;P&gt;The Testing Policy is not one that I consider essential for all projects. For projects in which you have a good set of Build Verification Tests (BVTs) that give you a signficant amount of code coverage and don't take very long to execute, then enabling this policy just makes sense. However, keep in mind that you should definitely be running BVTs as part of your automated build, so if these tests require a substantial amount of time to execute (for example, they require signficant setup or teardown), then forcing developers to run these tests before every check-in could definitely impede their productivity.&lt;/P&gt;
&lt;P&gt;Of course, you can always separate your tests into "quick tests" and "long running tests" like I've mentioned in a previous &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/03/19/argumentnullexception-with-optional-publishingpage-description-property-with-some-thoughts-on-breaking-the-build-too.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/03/19/argumentnullexception-with-optional-publishingpage-description-property-with-some-thoughts-on-breaking-the-build-too.aspx"&gt;post&lt;/A&gt;, and consequently only require the "quick tests" to be executed before check-in.&lt;/P&gt;
&lt;P&gt;If you are fortunate enough to be using TFS on your project, I hope you are reaping the benefits of check-in policies.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915639" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="Core Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Core+Development/default.aspx" /><category term="TFS" scheme="http://blogs.msdn.com/jjameson/archive/tags/TFS/default.aspx" /></entry><entry><title>Latest Version of Opera Ignores Hosts File</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/29/latest-version-of-opera-ignores-hosts-file.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/29/latest-version-of-opera-ignores-hosts-file.aspx</id><published>2009-10-29T13:17:00Z</published><updated>2009-10-29T13:17:00Z</updated><content type="html">&lt;P&gt;As I mentioned in my &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/29/troubleshooting-layout-problems-with-safari.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/29/troubleshooting-layout-problems-with-safari.aspx"&gt;previous post&lt;/A&gt;, I discovered a rather nasty UI bug last week with the new portal we are building for a customer. Unfortunately, the layout issue only occurred in the Safari browser.&lt;/P&gt;
&lt;P&gt;Since I couldn't repro the issue in Internet Explorer or Firefox, I decided to see if Opera exhibited the same problem as Safari. Consequently, I downloaded and installed the latest version of Opera (note that I've rebuilt both my desktop and development VM since the last time I used Opera).&lt;/P&gt;
&lt;P&gt;Unfortunately. I discovered there's a known bug with Opera version 10 that causes it to ignore your local hosts file (e.g. %SystemRoot%\drivers\etc\hosts).&lt;/P&gt;
&lt;P&gt;Oh c'mon, Opera Team, you've got to be kidding!&lt;/P&gt;
&lt;P&gt;How can you expect a developer to even try your browser if he can't browse to a site in his local development environment using a fully qualified domain name (e.g. http://www-local.fabrikam.com)?&lt;/P&gt;
&lt;P&gt;Needless to say, I didn't spend much time trying to workaround the issue. My prediction: Opera is all but extinct in another year or two.&lt;/P&gt;
&lt;P&gt;That's too bad. From what I remember, Opera used to be a pretty good browser -- and maybe it still is, aside from the bug with the hosts file. It was certainly years ahead of IE6 in terms of Web standards compliance.&lt;/P&gt;
&lt;P&gt;Does anyone know the current browser stats? It wouldn't surprise me if Opera was surpassed by Safari some time ago.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9914696" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Web Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Web+Development/default.aspx" /></entry><entry><title>Troubleshooting Layout Problems with Safari</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/29/troubleshooting-layout-problems-with-safari.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/29/troubleshooting-layout-problems-with-safari.aspx</id><published>2009-10-29T12:57:00Z</published><updated>2009-10-29T12:57:00Z</updated><content type="html">&lt;P&gt;I discovered a rather nasty UI bug last week with the new portal we are building for a customer. Unfortunately, the layout issue only occurred in the Safari browser. Even worse, I discovered it only a day before the CEO of customer discovered it himself on his Mac! Ouch.&lt;/P&gt;
&lt;P&gt;Note that I typically test Web sites using Internet Explorer and Firefox. In fact, that's what our statement of work contractually obligates for this project (and not IE6, thankfully, but rather IE7 and IE8).&lt;/P&gt;
&lt;P&gt;I've occasionally tested with Opera and Safari in the past, but in general I've found this to be unnecessary because most of these browsers have strong support for modern &lt;A href="http://en.wikipedia.org/wiki/Web_standards" mce_href="http://en.wikipedia.org/wiki/Web_standards"&gt;Web standards&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;However, this week I discovered that a page that looks good in Internet Explorer and Firefox doesn't necessarily look good in Safari.&lt;/P&gt;
&lt;P&gt;Since I didn't have access to my faithful Firebug or Internet Explorer Developer Tools, I was initially stumped on troubleshooting the problem. However, a little bit of searching uncovered the following gem:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;Firebug For Safari&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="http://vision-media.ca/resources/misc/firefox-for-safari" mce_href="http://vision-media.ca/resources/misc/firefox-for-safari"&gt;http://vision-media.ca/resources/misc/firefox-for-safari&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Unlike many of the other search results that I looked at, this one doesn't actually discuss using Firebug in Safari (which I was reluctant to try because, from what I read, all of the CSS rules are read-only when you use Firebug with Safari). Rather, this page shows the similar set of tools that Apple provides with their browser. It also shows how to easily enable the Safari developer tools without hacking a preferences file (which I initially tried locating on my Windows VM using instructions based on a Mac, but I quickly gave up on that effort).&lt;/P&gt;
&lt;P&gt;After spending about 45 minutes with the Safari developer tools, I was finally able to track down the &lt;CODE&gt;float&lt;/CODE&gt; CSS rule that was causing my Login Form Web Part to be displayed &lt;EM&gt;behind&lt;/EM&gt; the &lt;CODE&gt;&amp;lt;h1&amp;gt;&lt;/CODE&gt; heading for the main content of the page in Safari.&lt;/P&gt;
&lt;P&gt;A few minutes later and I had my fix checked-in to TFS. Whew!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9914686" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Web Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Web+Development/default.aspx" /></entry><entry><title>DataNavigateUrlFormatString Does Not Allow "javascript:"</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/26/datanavigateurlformatstring-does-not-allow-javascript.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/26/datanavigateurlformatstring-does-not-allow-javascript.aspx</id><published>2009-10-26T14:49:00Z</published><updated>2009-10-26T14:49:00Z</updated><content type="html">&lt;P&gt;I encountered an interesting bug last Friday with the ASP.NET &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.aspx"&gt;HyperLinkField&lt;/A&gt; control. To understand the scenario, think of the typical "view detail" feature when showing summary data in a table. In other words, you want to provide users the ability to click a cell in a table (e.g. a &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx"&gt;GridView&lt;/A&gt; control) in order to see more information.&lt;/P&gt;
&lt;P&gt;I've implemented this scenario before, so I was a stumped when I couldn't get it to work right away. However, this time the scenario was a little different because we want to display a popup window to an external site. Also note that several visual properties of the popup window need to be specified for our application -- such as the width and height of the window, as well as hiding the menu bar, status bar, etc.&lt;/P&gt;
&lt;P&gt;In other words, we need the links in the table to actually call a JavaScript function instead of specifying a simple URL.&lt;/P&gt;
&lt;P&gt;My initial attempt was to specify something like :&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="summaryGrid"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #ff0000"&gt;AutoGenerateColumns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="False"
    ...&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;...
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Columns&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HyperLinkField&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;DataNavigateUrlFields&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Id"
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DataNavigateUrlFormatString&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="javascript:ShowItemDetail({0})"
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DataTextField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CreateTime"
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DataTextFormatString&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="{0:ddd MMM dd HH:mm}"
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;HeaderStyle-CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="dateColumn"
           &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;HeaderText&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Date"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;&lt;/SPAN&gt;  
       &lt;SPAN style="COLOR: #0000ff"&gt;...
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Columns&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Note that &lt;CODE&gt;ShowItemDetail&lt;/CODE&gt; is a JavaScript function that simply calls &lt;CODE&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms536651(VS.85).aspx"&gt;window.open&lt;/A&gt;&lt;/CODE&gt; (specifying the URL as well as additional "feature" parameters such as the window width and height).&lt;/P&gt;
&lt;P&gt;Unfortunately, if you specify something like &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;"javascript:ShowItemDetail({0});"&lt;/SPAN&gt;&lt;/CODE&gt; in &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.datanavigateurlformatstring.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.datanavigateurlformatstring.aspx"&gt;DataNavigateUrlFormatString&lt;/A&gt;, you will find that ASP.NET renders an anchor element with no &lt;CODE&gt;href&lt;/CODE&gt; attribute (e.g. &lt;CODE&gt;&amp;lt;a&amp;gt;Mon Oct 26 08:23&amp;lt;/a&amp;gt;&lt;/CODE&gt;) -- which obviously doesn't work. This appears to be "by design" -- in order to "mitigate against cross-site scripting attacks."&lt;BR&gt;&lt;BR&gt;Refer to the following for more detail:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;asp:GridView does not render HyperLinkField when a colon (:) is included in the DataNavigateUrlFormatString. 2007-06-05.&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102300" mce_href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102300"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102300&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;To workaround this, use a &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatefield.aspx"&gt;TemplateField&lt;/A&gt; instead:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="summaryGrid"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #ff0000"&gt;AutoGenerateColumns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="False"
    ...&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;...&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Columns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&lt;/SPAN&gt;        &amp;lt;%&lt;SPAN style="COLOR: #008000"&gt;-- HACK: Ideally, we would just use an asp:HyperLinkField,
        but there's a bug when specifying "javascript:" in the
        DataNavigateUrlFormatString:

        https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102300

        As a workaround, use a TemplateField instead. --&lt;/SPAN&gt;%&amp;gt;
        &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
           &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;Date&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
           &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HeaderStyle&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="dateColumn"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;
           &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&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: #a31515"&gt;a&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;href&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;='javascript:&lt;SPAN style="COLOR: #0000ff"&gt;ShowItemDetail&lt;/SPAN&gt;(&lt;/SPAN&gt;&amp;lt;%# Eval("Id")%&amp;gt;&lt;SPAN style="COLOR: #0000ff"&gt;)'&amp;gt;
           &lt;/SPAN&gt;        &amp;lt;%&lt;SPAN style="COLOR: #0000ff"&gt;# &lt;/SPAN&gt;Eval(&lt;SPAN style="COLOR: #a31515"&gt;"CreateTime"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"{0:ddd MMM dd HH:mm}"&lt;/SPAN&gt;) %&amp;gt;
&lt;SPAN style="COLOR: #0000ff"&gt;           &lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;a&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
           &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&lt;/SPAN&gt;        ...&lt;SPAN style="COLOR: #0000ff"&gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Columns&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Or, if you are really paranoid about the performance impact of using reflection in the DataBinder.Eval method, you can use strongly typed objects instead:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="summaryGrid"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;runat&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="server"
&lt;/SPAN&gt;   &lt;SPAN style="COLOR: #ff0000"&gt;AutoGenerateColumns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="False"
   ...&amp;gt;
   ...&lt;/SPAN&gt;
&lt;/SPAN&gt;   &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Columns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&lt;/SPAN&gt;      &amp;lt;%&lt;SPAN style="COLOR: #008000"&gt;-- HACK: Ideally, we would just use an asp:HyperLinkField,
      but there's a bug when specifying "javascript:" in the
      DataNavigateUrlFormatString:
        
      https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=102300
        
      As a workaround, use a TemplateField instead.
      --&lt;/SPAN&gt;%&amp;gt;
   &lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateField&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
         &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;Date&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HeaderTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &lt;SPAN style="COLOR: #008000"&gt;   &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;HeaderStyle&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;CssClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="dateColumn"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;/&amp;gt;
      &lt;SPAN style="COLOR: #008000"&gt;   &lt;/SPAN&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &lt;SPAN style="COLOR: #008000"&gt;   &lt;/SPAN&gt;&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;a&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;href&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;='javascript:&lt;SPAN style="COLOR: #0000ff"&gt;ShowItemDetail&lt;/SPAN&gt;(&lt;/SPAN&gt;&amp;lt;%# ((Fabrikam.Demo.Integration.Incident)Container.DataItem).Id %&amp;gt;&lt;SPAN style="COLOR: #0000ff"&gt;)'&amp;gt;
      &lt;SPAN style="COLOR: #008000"&gt;   &lt;/SPAN&gt;&lt;/SPAN&gt;        &amp;lt;%&lt;SPAN style="COLOR: #0000ff"&gt;#&lt;/SPAN&gt; ((Fabrikam.Demo.Integration.&lt;SPAN style="COLOR: #2b91af"&gt;Incident&lt;/SPAN&gt;)Container.DataItem).CreateTime.ToString(&lt;SPAN style="COLOR: #a31515"&gt;"ddd MMM dd HH:mm"&lt;/SPAN&gt;) %&amp;gt;
&lt;SPAN style="COLOR: #0000ff"&gt;      &lt;SPAN style="COLOR: #008000"&gt;   &lt;/SPAN&gt;&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;a&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &lt;SPAN style="COLOR: #008000"&gt;   &lt;/SPAN&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ItemTemplate&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;TemplateField&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: #a31515"&gt;Columns&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: #a31515"&gt;asp&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;:&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;GridView&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Of course, if you choose to go the strongly-typed route, you will need to reference the assembly containing your custom business objects. For example:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;%&lt;SPAN style="COLOR: #0000ff"&gt;@&lt;/SPAN&gt; &lt;SPAN style="COLOR: #a31515"&gt;Assembly&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Fabrikam.Demo.Integration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=786f58ca4a6e3f60"&lt;/SPAN&gt; %&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9912949" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Web Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Web+Development/default.aspx" /></entry><entry><title>Essential Add-Ins for Team Foundation Server</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/25/essential-add-ins-for-team-foundation-server.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/25/essential-add-ins-for-team-foundation-server.aspx</id><published>2009-10-25T15:32:00Z</published><updated>2009-10-25T15:32:00Z</updated><content type="html">&lt;P&gt;In a &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/03/24/diffmerge-a-better-differencing-tool.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/03/24/diffmerge-a-better-differencing-tool.aspx"&gt;previous post&lt;/A&gt;, I mentioned how I use SourceGear's DiffMerge instead of the out-of-the-box tool that comes with Team Foundation Server (which is also called DiffMerge). If you haven't at least evaluated the SourceGear alternative, I definitely advise you to take a look.&lt;/P&gt;
&lt;P&gt;The other "add-in" for TFS that I consider to be essential is the &lt;A href="http://www.acorns.com.au/projects/vsaddins/" mce_href="http://www.acorns.com.au/projects/vsaddins/"&gt;TFS Quick Search Plugin&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;If you have Web access to your TFS instance (via &lt;A href="http://msdn.microsoft.com/en-us/teamsystem/bb980951.aspx" mce_href="http://msdn.microsoft.com/en-us/teamsystem/bb980951.aspx"&gt;Team System Web Access&lt;/A&gt;), then quickly locating work items by keywords is actually pretty easy. However if you either don't have access to Team System Web Access or you would simply rather prefer to search for a work item without leaving Visual Studio, then the TFS Quick Search Plugin is definitely the way to go.&lt;/P&gt;
&lt;P&gt;Note that it doesn't search all of the fields in all work items, but rather searches the work items currently displayed within Visual Studio. However, if you know a keyword that appears in the title of a work item, this can make it very easy to locate the desired work item.&lt;/P&gt;
&lt;P&gt;I tend to use the TFS Quick Search Plugin a lot for the scenario where I am trying to find a duplicate bug and I remember a couple of keywords in the title of the previous bug. It is certainly much faster than scrolling through a few hundred work items in order to find something, or trying to build a query on-the-fly in order to locate a work item.&lt;/P&gt;
&lt;P&gt;I am really interested to see the improvements in Visual Studio 2010 and Team Foundation Server 2010, but honestly it's probably going to be a while before I'm able to use that in my day-to-day work. Nevertheless, I hope this kind of work item "quick search" comes out-of-the-box in the next release (as well as a better DiffMerge tool). [I did do some hands-on labs back in February that cover the new branching visualization features in TFS 2010, and I have to say that I absolutely love what I've seen so far.]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9912619" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Visual Studio" scheme="http://blogs.msdn.com/jjameson/archive/tags/Visual+Studio/default.aspx" /><category term="TFS" scheme="http://blogs.msdn.com/jjameson/archive/tags/TFS/default.aspx" /></entry><entry><title>Is AutoCorrect making me stupid or just plain lazy?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/25/is-autocorrect-making-me-stupid-or-just-plain-lazy.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/25/is-autocorrect-making-me-stupid-or-just-plain-lazy.aspx</id><published>2009-10-25T15:03:00Z</published><updated>2009-10-25T15:03:00Z</updated><content type="html">&lt;P&gt;&lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/24/the-original-jameson-datacenter.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/24/the-original-jameson-datacenter.aspx"&gt;Yesterday's post&lt;/A&gt; got me thinking about something.&lt;/P&gt;
&lt;P&gt;Do you find yourself occasionally typing one word when you are actually thinking of a different word that sounds the same? A faint recollection from one or more of my English classes long ago suggested that these words are called &lt;EM&gt;homonyms&lt;/EM&gt;. However, a quick search just now on Wikipedia indicates these are actually &lt;A href="http://en.wikipedia.org/wiki/Homophone" mce_href="http://en.wikipedia.org/wiki/Homophone"&gt;&lt;EM&gt;homophones&lt;/EM&gt;&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;For example, have you ever typed the word "do" when you meant "due", or similarly "overdo" when you meant "overdue"? Surely you know the difference between the two, yet somehow in the time that it takes your fingers to turn your thoughts into characters, then words, and eventually sentences on the screen, something goes terribly wrong.&lt;/P&gt;
&lt;P&gt;I honestly can't ever remember doing this as child, although it undoubtedly happened more than a few times as my vocabulary grew at a faster pace than my ability to spell. I definitely don't remember it happening in high school or college. This made me wonder if this infliction is somehow related to typing -- or more specifically, my typing speed (which has vastly increased since my college days). This got me thinking that perhaps it's not actually related to my skills as a typist, but somehow related to the fact many of the applications I use on a daily basis have some sort of "auto-correct" feature.&lt;/P&gt;
&lt;P&gt;Consider the AutoCorrect feature in Microsoft Word -- and Outlook -- as an example. I have to wonder if the fact that this has been fixing my typing and spelling errors for almost fifteen years has somehow made me just a little too dependent on this feature. I can honestly say that I don't do as much proofreading today as I used to a few years ago, and this really isn't a good thing.&lt;/P&gt;
&lt;P&gt;It's probably overkill to proofread every single e-mail message before sending it out, but at the same time, isn't it embarrassing to send a message that uses the word "to" when it should be "too"?&lt;/P&gt;
&lt;P&gt;Of course, I'm not saying that these errors are the fault of software features like AutoCorrect. Surely I'm the one that bears ultimate responsibility for the words I write. Perhaps I just need to consider disabling the AutoCorrect feature in Word and Outlook for a while -- or better yet, maybe I should look for an old &lt;A href="http://en.wikipedia.org/wiki/IBM_Selectric_typewriter" mce_href="http://en.wikipedia.org/wiki/IBM_Selectric_typewriter"&gt;IBM Selectric&lt;/A&gt; on ebay and subject myself to some exercises on that for a little while. Without a doubt, a few dozen pages on that -- and a couple of bottles of Liquid Paper, of course -- would cure whatever ailment I seem to have contracted in the last few years.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9912609" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Personal" scheme="http://blogs.msdn.com/jjameson/archive/tags/Personal/default.aspx" /></entry><entry><title>The Original "Jameson Datacenter"</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/24/the-original-jameson-datacenter.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/24/the-original-jameson-datacenter.aspx</id><published>2009-10-24T13:18:00Z</published><updated>2009-10-24T13:18:00Z</updated><content type="html">&lt;P&gt;This morning I was doing some cleanup of my documents folder and I stumbled across a rather old Visio document that showed the beginnings of&amp;nbsp;what I now refer to as the &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/14/the-jameson-datacenter.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/14/the-jameson-datacenter.aspx"&gt;"Jameson Datacenter"&lt;/A&gt; (a.k.a. my home lab). For some geeky reason, seeing this again brought a smile to my face and a sense of nostalgia. It also caused me to recall two things:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;That old Greatful Dead song "Truckin'" -- specifically the line&lt;BR&gt;&lt;BR&gt;&lt;Q class=directQuote&gt;Lately it occurs to me: What a long, strange trip it's been.&lt;/Q&gt; 
&lt;BLOCKQUOTE class=note&gt;
&lt;DIV class=noteTitle&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;Doh! You would think a guy with a Master of Science degree in Mechanical Engineering could spell "Grateful Dead" correctly! I suppose that I really should do more proofreading before clicking that &lt;STRONG&gt;Publish &lt;/STRONG&gt;button ;-)&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/LI&gt;
&lt;LI&gt;An article I read about a year ago describing the origin of Google that also included some photos of the original Google infrastructure in the Stanford University computer lab.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Now, please don't misunderstand -- I most certainly am not claiming that the Jameson Datacenter will ever amount to even the most miniscule fraction of what Google grew into in less than a decade. All I'm saying is that in the incredible way the neurons are wired together in the human brain, things that we see very often trigger distant memories with amazing clarity.&lt;/P&gt;
&lt;P&gt;For those of you that may not have seen the original Google server farm, I did a quick search this morning and managed to find the following:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;Google Stanford Hardware&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="http://geektechnique.org/media/google/googlehardware.html" mce_href="http://geektechnique.org/media/google/googlehardware.html"&gt;http://geektechnique.org/media/google/googlehardware.html&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;If you haven't seen this, take a quick peek. It will surely bring a smile -- if not a burst of laughter.&lt;/P&gt;
&lt;P&gt;After enjoying the nostalgia for a moment, I almost deleted the Visio diagram and continued my cleanup effort. However, then I decided that I might as well "archive" this on my blog. It definitely won't help your efforts of deploying Microsoft technology, but I think it's okay for a blog to wander a little every now and then -- perhaps for no other reason than to keep you guessing as to what may come next on the Random Musings of Jeremy Jameson.&lt;/P&gt;
&lt;P&gt;Here's the physical architecture of what I now refer to as the "Old Jameson Datacenter":&lt;/P&gt;
&lt;DIV class=image&gt;&lt;IMG title="" alt="" src="http://blogs.msdn.com/photos/jjameson/images/9912445/489x375.aspx" width=489 height=375 mce_src="http://blogs.msdn.com/photos/jjameson/images/9912445/489x375.aspx"&gt; 
&lt;DIV class=caption&gt;Figure 1: Old Jameson Datacenter - Physical Architecture&lt;/DIV&gt;
&lt;DIV class=imageLink&gt;&lt;A href="http://blogs.msdn.com/photos/jjameson/images/9912445/original.aspx" target=_blank mce_href="http://blogs.msdn.com/photos/jjameson/images/9912445/original.aspx"&gt;See full-sized image.&lt;/A&gt; &lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Apparently the last time I updated this Visio diagram, I still hadn't decided what to do with all of the Dell servers I had procured through various channels (primarily the Dell Outlet and ebay). Hence the Dell PowerEdge 4300 with the "??" next to it. As I mentioned in my original post on the Jameson Datacenter, this server was the original BEAST (which is now my "Production" database server). However, it has since been replaced with a home-built server.&lt;/P&gt;
&lt;P&gt;From the previous figure, you can start to see why I've consolidated these servers in recent years by leveraging virtualization. The power consumption by all of these servers was really rather ridiculous when you consider what I was using these servers for.&lt;/P&gt;
&lt;P&gt;Notice that I use to run a back-to-back firewall configuration with a perimeter network (a.k.a. DMZ):&lt;/P&gt;
&lt;DIV class=image&gt;&lt;IMG title="" alt="" src="http://blogs.msdn.com/photos/jjameson/images/9912446/477x375.aspx" width=477 height=375 mce_src="http://blogs.msdn.com/photos/jjameson/images/9912446/477x375.aspx"&gt; 
&lt;DIV class=caption&gt;Figure 2: Old Jameson Datacenter - TCP/IP Configuration&lt;/DIV&gt;
&lt;DIV class=imageLink&gt;&lt;A href="http://blogs.msdn.com/photos/jjameson/images/9912446/original.aspx" target=_blank mce_href="http://blogs.msdn.com/photos/jjameson/images/9912446/original.aspx"&gt;See full-sized image.&lt;/A&gt; &lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;This is because I had one server with a public (static) IP address and therefore ran a couple of Web sites on the old "ICEMAN" server -- hence the name "ICEMAN", because it was my "IIS" server. Get it? Yeah, I know...more geekiness.&lt;/P&gt;
&lt;P&gt;The naming convention was such that the names corresponding to &lt;A href="http://en.wikipedia.org/wiki/X-Men" mce_href="http://en.wikipedia.org/wiki/X-Men"&gt;X-Men&lt;/A&gt; heroes were all members of the TECHTOOLBOX domain, whereas servers corresponding to X-Men villains were considered "dangerous" and thus not members of the domain. Egad! Does the geekness ever end?! [I wonder if someday when my daughter is much older, she'll ever bother to read this and seriously start to question her father's sanity.]&lt;/P&gt;
&lt;P&gt;Anyway, here's the DNS and DHCP configuration for the original farm:&lt;/P&gt;
&lt;DIV class=image&gt;&lt;IMG title="" alt="" src="http://blogs.msdn.com/photos/jjameson/images/9912447/500x155.aspx" width=500 height=155 mce_src="http://blogs.msdn.com/photos/jjameson/images/9912447/500x155.aspx"&gt; 
&lt;DIV class=caption&gt;Figure 1: Old Jameson Datacenter - DNS/DHCP Configuration&lt;/DIV&gt;
&lt;DIV class=imageLink&gt;&lt;A href="http://blogs.msdn.com/photos/jjameson/images/9912447/original.aspx" target=_blank mce_href="http://blogs.msdn.com/photos/jjameson/images/9912447/original.aspx"&gt;See full-sized image.&lt;/A&gt; &lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;There's nothing really too interesting about that, I suppose.&lt;/P&gt;
&lt;P&gt;Perhaps the most laughable aspect of the Old Jameson Datacenter -- at least when compared to today -- was the storage infrastructure:&lt;/P&gt;
&lt;DIV class=image&gt;&lt;IMG title="" alt="" src="http://blogs.msdn.com/photos/jjameson/images/9912448/474x375.aspx" width=474 height=375 mce_src="http://blogs.msdn.com/photos/jjameson/images/9912448/474x375.aspx"&gt; 
&lt;DIV class=caption&gt;Figure 1: Old Jameson Datacenter - Disk Configuration&lt;/DIV&gt;
&lt;DIV class=imageLink&gt;&lt;A href="http://blogs.msdn.com/photos/jjameson/images/9912448/original.aspx" target=_blank mce_href="http://blogs.msdn.com/photos/jjameson/images/9912448/original.aspx"&gt;See full-sized image.&lt;/A&gt; &lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;I can still remember when I thought the 18 GB of RAID1 and 72 GB of RAID5 on that Dell 4300 was &lt;A href="http://www.urbandictionary.com/define.php?term=fashizzle" mce_href="http://www.urbandictionary.com/define.php?term=fashizzle"&gt;fashizzle&lt;/A&gt; ;-) [Of course, that was long before I was even aware of the term "fashizzle", but you get my point.]&lt;/P&gt;
&lt;P&gt;Anyway, I hope you enjoyed this brief diversion down Memory Lane. Perhaps it invoked some distant memories of your own experiences in the world of technology.&lt;/P&gt;
&lt;P&gt;Personally, as I'm wrapping up this post, my head is spinning with thoughts of my father's original Apple II+ (which was the first computer I ever "programmed" on) as well as my very own Commodore 64 and all those late nights my dear friend &lt;A href="http://www.imediaconnection.com/profiles/iMedia_PC_Bio.aspx?ID=2928" mce_href="http://www.imediaconnection.com/profiles/iMedia_PC_Bio.aspx?ID=2928"&gt;Chris Gatewood&lt;/A&gt; and I sat in front of it typing in hundreds of lines of code from a magazine just so we could try to play some silly game based on "sprites." [Note that the games almost never worked due to some error or another, but nevertheless we kept trying anyway.]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9912449" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="Personal" scheme="http://blogs.msdn.com/jjameson/archive/tags/Personal/default.aspx" /><category term="Infrastructure" scheme="http://blogs.msdn.com/jjameson/archive/tags/Infrastructure/default.aspx" /></entry><entry><title>Configure IntelliMirror Using Group Policy</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/21/configure-intellimirror-using-group-policy.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/21/configure-intellimirror-using-group-policy.aspx</id><published>2009-10-21T12:57:00Z</published><updated>2009-10-21T12:57:00Z</updated><content type="html">&lt;P&gt;Yet another Group Policy object that I use in the &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/14/the-jameson-datacenter.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/14/the-jameson-datacenter.aspx"&gt;"Jameson Datacenter"&lt;/A&gt; (a.k.a. my home lab) is one to automatically configure roaming profiles and redirect the Desktop and Documents folders to a server(a.k.a. "IntelliMirror").&lt;/P&gt;
&lt;P&gt;Even though I don't have many users in my Active Directory domain -- it's not like I have eight kids, just one -- I still want to keep user data centrally managed on a server that I backup regularly. Besides, I find it really frustrating to have some items on your desktop on one computer, but a different set of desktop items on another computer (or VM).&lt;/P&gt;
&lt;P&gt;To automatically configure this in the "Jameson Datacenter", I defined a Group Policy (named &lt;STRONG&gt;Default User Data and Settings Policy&lt;/STRONG&gt;) with the following settings:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;User Configuration&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Policies&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Windows Settings&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Folder Redirection&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN class=sectionTitle tabIndex=0&gt;&lt;STRONG&gt;AppData(Roaming)&lt;/STRONG&gt;&lt;/SPAN&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN class=sectionTitle tabIndex=0&gt;&lt;STRONG&gt;Setting: Basic (Redirect everyone's folder to the same location)&lt;/STRONG&gt;&lt;/SPAN&gt; 
&lt;UL&gt;
&lt;LI&gt;Path: \\beast\Users$\%USERNAME%\Application Data&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Options&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;Grant user exclusive rights to AppData(Roaming): Enabled&lt;/LI&gt;
&lt;LI&gt;Move the contents of AppData(Roaming) to the new location: Enabled&lt;/LI&gt;
&lt;LI&gt;Also apply redirection policy to Windows 2000, Windows 2000 server, Windows XP, and Windows Server 2003 operating systems: Enabled&lt;/LI&gt;
&lt;LI&gt;Policy Removal Behavior: Leave contents&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class=sectionTitle tabIndex=0&gt;&lt;STRONG&gt;Desktop&lt;/STRONG&gt;&lt;/SPAN&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN class=sectionTitle tabIndex=0&gt;&lt;STRONG&gt;Setting: Basic (Redirect everyone's folder to the same location)&lt;/STRONG&gt;&lt;/SPAN&gt; 
&lt;UL&gt;
&lt;LI&gt;Path: \\beast\Users$\%USERNAME%\Desktop&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Options&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;Grant user exclusive rights to Desktop: Enabled&lt;/LI&gt;
&lt;LI&gt;Move the contents of Desktop to the new location: Enabled&lt;/LI&gt;
&lt;LI&gt;Also apply redirection policy to Windows 2000, Windows 2000 server, Windows XP, and Windows Server 2003 operating systems: Enabled&lt;/LI&gt;
&lt;LI&gt;Policy Removal Behavior: Leave contents&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN class=sectionTitle tabIndex=0&gt;&lt;STRONG&gt;Documents&lt;/STRONG&gt;&lt;/SPAN&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN class=sectionTitle tabIndex=0&gt;&lt;STRONG&gt;Setting: Basic (Redirect everyone's folder to the same location)&lt;/STRONG&gt;&lt;/SPAN&gt; 
&lt;UL&gt;
&lt;LI&gt;Path: \\beast\Users$\%USERNAME%\Documents&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Options&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;Grant user exclusive rights to Documents: Enabled&lt;/LI&gt;
&lt;LI&gt;Move the contents of Documentsto the new location: Enabled&lt;/LI&gt;
&lt;LI&gt;Also apply redirection policy to Windows 2000, Windows 2000 server, Windows XP, and Windows Server 2003 operating systems: Enabled&lt;/LI&gt;
&lt;LI&gt;Policy Removal Behavior: Leave contents&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Music&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;Setting: Follow the Documents folder&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Pictures&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;Setting: Follow the Documents folder&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Videos&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;Setting: Follow the Documents folder&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE class=note&gt;
&lt;DIV class=noteTitle&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;Those of you that have a very keen eye (and also a photographic memory) might recall that in a previous post, I listed BEAST as a database server (it is currently running SQL Server 2005). Yes, it's true, I'm breaking one of my own cardinal sins by having a SQL Server also serve as a file server. I don't recommend doing this unless, like me, you are trying to go as cheap as possible -- and, even then, only for a lab environment like mine.&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In order to allow users access to create their own folders on \\BEAST\Users$, I have configured the following permissions on C:\BackedUp\Users:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Domain Users 
&lt;UL&gt;
&lt;LI&gt;Apply onto: This folder only&lt;/LI&gt;
&lt;LI&gt;Permissions 
&lt;UL&gt;
&lt;LI&gt;List Folder / Read Data&lt;/LI&gt;
&lt;LI&gt;Create Folders / Append Data&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;CREATOR OWNER 
&lt;UL&gt;
&lt;LI&gt;Apply onto: Subfolders and files only&lt;/LI&gt;
&lt;LI&gt;Permissions 
&lt;UL&gt;
&lt;LI&gt;Full Control&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I also created a hidden share for the C:\BackedUp\Users folder and granted &lt;STRONG&gt;Full Control &lt;/STRONG&gt;to &lt;STRONG&gt;Authenticated Users &lt;/STRONG&gt;(since the NTFS permissions above ultimately determine the level of access for all users).&lt;/P&gt;
&lt;P&gt;Thus when a new user logs in for the first time, a corresponding folder is created on the server and all of the user's files are stored on the server.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910544" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="Simplify" scheme="http://blogs.msdn.com/jjameson/archive/tags/Simplify/default.aspx" /><category term="Windows Server" scheme="http://blogs.msdn.com/jjameson/archive/tags/Windows+Server/default.aspx" /><category term="Infrastructure" scheme="http://blogs.msdn.com/jjameson/archive/tags/Infrastructure/default.aspx" /></entry><entry><title>Eliminate MBSA Warnings Using Default Security Settings Policy</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/21/eliminate-mbsa-warnings-using-default-security-settings-policy.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/21/eliminate-mbsa-warnings-using-default-security-settings-policy.aspx</id><published>2009-10-21T11:57:00Z</published><updated>2009-10-21T11:57:00Z</updated><content type="html">&lt;P&gt;Another Group Policy object that I use in the &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/14/the-jameson-datacenter.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/14/the-jameson-datacenter.aspx"&gt;"Jameson Datacenter"&lt;/A&gt; (a.k.a. my home lab) is one that I created a couple of years ago in order to eliminate various warnings from the &lt;A href="http://technet.microsoft.com/en-us/security/cc184924.aspx" mce_href="http://technet.microsoft.com/en-us/security/cc184924.aspx"&gt;Microsoft Baseline Security Advisor&lt;/A&gt; (MBSA).&lt;/P&gt;
&lt;P&gt;To automatically change the default security settings in the "Jameson Datacenter", I defined a Group Policy (named &lt;STRONG&gt;Default Security Settings Policy&lt;/STRONG&gt;) with the following settings:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Computer Configuration&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Policies&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Windows Settings&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Security Settings&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Account Policies&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Password Policy&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Maximum password age: 60 days&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Minimum password age: 1 day&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Minimum password length: 8 characters&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Local Policies&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Security Options&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Network security: LAN Manager authentication level: Send NTLMv2 response only. Refuse LM &amp;amp; NTLM&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;System Services&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;TlntSvr&lt;/STRONG&gt; 
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Startup Mode: Disabled&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I don't know about you, but I haven't used Telnet in almost fifteen years -- back when I used to work on Unix systems ;-)&lt;/P&gt;
&lt;P&gt;This Group Policy is linked it to the entire domain (i.e. &lt;STRONG&gt;corp.technologytoolbox.com&lt;/STRONG&gt;).&lt;/P&gt;
&lt;P&gt;Note that I still use the &lt;STRONG&gt;Default Domain Controllers Policy&lt;/STRONG&gt; to configure the security settings on the domain controllers (and thus domain accounts). In other words, the settings noted above only affect local accounts (e.g. COLOSSUS\Administrator, not TECHTOOLBOX\jjameson).&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910517" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="Simplify" scheme="http://blogs.msdn.com/jjameson/archive/tags/Simplify/default.aspx" /><category term="Windows Server" scheme="http://blogs.msdn.com/jjameson/archive/tags/Windows+Server/default.aspx" /><category term="Infrastructure" scheme="http://blogs.msdn.com/jjameson/archive/tags/Infrastructure/default.aspx" /></entry><entry><title>New MSDN Theme on My Blog</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/21/new-msdn-theme-on-my-blog.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/21/new-msdn-theme-on-my-blog.aspx</id><published>2009-10-21T11:12:00Z</published><updated>2009-10-21T11:12:00Z</updated><content type="html">&lt;P&gt;I noticed this morning that the new color scheme released this past week on &lt;A href="http://msdn.microsoft.com/" mce_href="http://msdn.microsoft.com"&gt;MSDN&lt;/A&gt; has made its way into our Community Server template (and thus onto my blog, since I'm currently using the default "skin").&lt;/P&gt;
&lt;P&gt;I'm still not sure how I feel about the combination of purple (&lt;CODE style="BACKGROUND: #36295e; COLOR: #fff"&gt;&amp;nbsp; #36295E&amp;nbsp; &lt;/CODE&gt;) and this particular shade of blue (&lt;CODE style="BACKGROUND: #4ea5d2; COLOR: #fff"&gt;&amp;nbsp; #4EA5D2&amp;nbsp; &lt;/CODE&gt;). I certainly like each color by itself, it's just that when you put the two together, my stomach starts to feel a little queasy. Oh well, I'm sure I'll get used to it.&lt;/P&gt;
&lt;P&gt;Personally, I would have chosen one of the &lt;A href="http://www.hanselman.com/blog/MSDNUpdatesAndRFCForYou.aspx" mce_href="http://www.hanselman.com/blog/MSDNUpdatesAndRFCForYou.aspx"&gt;other color schemes proposed for the overhaul of MSDN&lt;/A&gt;. Nevertheless, this is what the Visual Studio marketing team has chosen for their two primary colors for the 2010 release, so -- like I said before -- I'll get used to it.&lt;/P&gt;
&lt;P&gt;In the meantime, I've updated some of my custom style elements to match the new color scheme.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910495" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="Personal" scheme="http://blogs.msdn.com/jjameson/archive/tags/Personal/default.aspx" /></entry><entry><title>Add Rooler to Your Web Development Toolbox</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/21/add-rooler-to-your-web-development-toolbox.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/21/add-rooler-to-your-web-development-toolbox.aspx</id><published>2009-10-21T10:19:00Z</published><updated>2009-10-21T10:19:00Z</updated><content type="html">&lt;P&gt;This past May, one of my colleagues notified me of a new tool called "Rooler" that allows you to easily measure anything displayed on your screen.&lt;/P&gt;
&lt;P&gt;I definitely consider this tool a "must have" for anyone out there doing Web development. While tools like Firebug and the new developer tools in Internet Explorer 8 are great for analyzing the layout of Web pages, I often find myself using Rooler when tweaking CSS rules in order to achieve that "pixel perfect" design. For example, yesterday I was working on styling the new customer service portal that I'm working on and I wanted to match the customer's current .com site. Rooler enabled me to identify the dimensions of the header and margins of various elements with almost no effort whatsoever.&lt;/P&gt;
&lt;P&gt;If you haven't already discovered &lt;A href="http://blois.us/Rooler/" mce_href="http://blois.us/Rooler/"&gt;Rooler&lt;/A&gt;, I strongly recommend you download it today.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910478" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="Web Development" scheme="http://blogs.msdn.com/jjameson/archive/tags/Web+Development/default.aspx" /></entry><entry><title>Introducing the SharePointSmtpHelper Class</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/18/introducing-the-sharepointsmtphelper-class.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/18/introducing-the-sharepointsmtphelper-class.aspx</id><published>2009-10-18T14:29:00Z</published><updated>2009-10-18T14:29:00Z</updated><content type="html">&lt;P&gt;Continuing in the spirit of my previous posts for the &lt;CODE&gt;&lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/09/introducing-the-sharepointpublishinghelper-class.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/09/introducing-the-sharepointpublishinghelper-class.aspx"&gt;SharePointPublishingHelper&lt;/A&gt;&lt;/CODE&gt; class and &lt;CODE&gt;&lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/17/introducing-the-sharepointwebparthelper-class.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/17/introducing-the-sharepointwebparthelper-class.aspx"&gt;SharePointWebPartHelper&lt;/A&gt;&lt;/CODE&gt; class, I'd like to introduce another helper class that you may find useful when building solutions for Windows SharePoint Services (WSS) v3 and Microsoft Office SharePoint Server (MOSS) 2007.&lt;/P&gt;
&lt;P&gt;Consider the scenario where you need to send an e-mail message from a SharePoint application. Perhaps an unexpected error occurred and you want to notify the operations team, or perhaps you just want to send a confirmation message to a user who has just submitted some important information.&lt;/P&gt;
&lt;P&gt;Whatever the case, you'd like to send an e-mail message using the SMTP server configured in SharePoint Central Administration for the farm. &lt;CODE&gt;SharePointSmtpHelper&lt;/CODE&gt; makes it really easy to do this.&lt;/P&gt;
&lt;P&gt;Note that there's really not much code to the &lt;CODE&gt;SharePointSmtpHelper&lt;/CODE&gt; class -- thanks to the classes provided by the .NET Framework in the &lt;A href="http://msdn.microsoft.com/en-us/library/system.net.mail.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.net.mail.aspx"&gt;System.Net.Mail&lt;/A&gt; namespace. It may look like more code than you might expect, but that's just because of all the overloads of the &lt;CODE&gt;SendMessage&lt;/CODE&gt; method that I provide.&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Net.Mail;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint.Administration;

&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Demo.CoreServices.SharePoint
{
    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Exposes static methods for sending e-mail messages from a SharePoint
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Web application using the Simple Mail Transfer Protocol (SMTP). The
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; SMTP server must be configured in SharePoint Central Administration.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; This class cannot be inherited.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;remarks&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; All methods of the &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;SharePointSmtpHelper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; class are static and
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; can therefore be called without creating an instance of the class.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/remarks&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;sealed&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SharePointSmtpHelper
&lt;/SPAN&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;object&lt;/SPAN&gt; lockObject = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&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;string&lt;/SPAN&gt; smtpServer;
        &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;string&lt;/SPAN&gt; defaultFromAddress;
        
        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; SharePointSmtpHelper( ) { } &lt;SPAN style="COLOR: #008000"&gt;// all members are static

&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Sends an e-mail message using the outbound SMTP server and
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "From address" configured in SharePoint Central Administration.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="toRecipients"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The recipients of the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; In other words, the addresses on the To line of the e-mail.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="subject"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The subject line for the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="body"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The e-mail message body.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;void&lt;/SPAN&gt; SendMessage(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; toRecipients,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; subject,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; body)
        {
            SendMessage(
                toRecipients,
                subject,
                body,
                &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
        }

        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Sends an e-mail message using the outbound SMTP server and
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "From address" configured in SharePoint Central Administration,
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; specifying whether the body of the message is formatted using HTML.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="toRecipients"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The recipients of the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; In other words, the addresses on the To line of the e-mail.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="subject"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The subject line for the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="body"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The e-mail message body.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="isBodyHtml"&amp;gt;&amp;lt;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;true&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; if the mail message body is
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; formatted using HTML markup. &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; if the message is simply
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; plain text.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;void&lt;/SPAN&gt; SendMessage(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; toRecipients,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; subject,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; body,
            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isBodyHtml)
        {
            SendMessage(
                toRecipients,
                subject,
                body,
                isBodyHtml,
                &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
        }

        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Sends an e-mail message using the outbound SMTP server and
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "From address" configured in SharePoint Central Administration,
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; specifying whether the body of the message is formatted using HTML
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; and also including carbon copy (CC) recipients.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="toRecipients"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The recipients of the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; In other words, the addresses on the To line of the e-mail.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="subject"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The subject line for the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="body"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The e-mail message body.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;        
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="isBodyHtml"&amp;gt;&amp;lt;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;true&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; if the mail message body is
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; formatted using HTML markup. &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; if the message is simply
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; plain text.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="ccRecipients"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The carbon copy (CC) recipients of the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; e-mail message.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;void&lt;/SPAN&gt; SendMessage(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; toRecipients,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; subject,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; body,
            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isBodyHtml,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ccRecipients)
        {
            SendMessage(
                toRecipients,
                subject,
                body,
                isBodyHtml,
                ccRecipients,
                &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
        }

        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Sends an e-mail message using the outbound SMTP server configured
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; in SharePoint Central Administration for the farm.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="toRecipients"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The recipients of the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; In other words, the addresses on the To line of the e-mail.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="subject"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The subject line for the e-mail message.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="body"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The e-mail message body.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;        
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="isBodyHtml"&amp;gt;&amp;lt;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;true&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; if the mail message body is
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; formatted using HTML markup. &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;false&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; if the message is simply
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; plain text.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="ccRecipients"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The carbon copy (CC) recipients of the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; e-mail message.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="from"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The e-mail address of the sender.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;void&lt;/SPAN&gt; SendMessage(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; toRecipients,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; subject,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; body,
            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isBodyHtml,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ccRecipients,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; from)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(toRecipients) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"toRecipients"&lt;/SPAN&gt;);
            }

            toRecipients = toRecipients.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(toRecipients) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"In order to send an e-mail message, "
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" at least one recipient must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"toRecipients"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(subject) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"subject"&lt;/SPAN&gt;);
            }

            subject = subject.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(subject) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"In order to send an e-mail message, "
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" the subject must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"subject"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(body) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"body"&lt;/SPAN&gt;);
            }

            body = body.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(body) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"In order to send an e-mail message, "
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" the message body must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"body"&lt;/SPAN&gt;);
            }

            EnsureSmtpSettings();

            &lt;SPAN style="COLOR: #008000"&gt;// If the "from" address is not specified, default to the address
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// configured in SharePoint Central Administration.
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(from) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                from = defaultFromAddress;
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;SmtpClient&lt;/SPAN&gt; smtpClient = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SmtpClient&lt;/SPAN&gt;(smtpServer);

            &lt;SPAN style="COLOR: #2b91af"&gt;MailMessage&lt;/SPAN&gt; message = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;MailMessage&lt;/SPAN&gt;(
                from,
                toRecipients,
                subject,
                body);

            message.IsBodyHtml = isBodyHtml;

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(ccRecipients) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
            {
                message.CC.Add(ccRecipients);
            }

            smtpClient.Send(message);
        }

        &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;void&lt;/SPAN&gt; EnsureSmtpSettings()
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(smtpServer) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;SPContext&lt;/SPAN&gt;.Current == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;InvalidOperationException&lt;/SPAN&gt;(
                        &lt;SPAN style="COLOR: #a31515"&gt;"SharePointSmtpClient can only be called from within"
&lt;/SPAN&gt;                            + &lt;SPAN style="COLOR: #a31515"&gt;" a SharePoint site (SPContext.Current is null)."&lt;/SPAN&gt;);
                }

                &lt;SPAN style="COLOR: #0000ff"&gt;lock&lt;/SPAN&gt; (lockObject)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(smtpServer) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
                    {
                        &lt;SPAN style="COLOR: #2b91af"&gt;SPWebApplication&lt;/SPAN&gt; webApp =
                            &lt;SPAN style="COLOR: #2b91af"&gt;SPContext&lt;/SPAN&gt;.Current.Site.WebApplication;

                        &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webApp.OutboundMailServiceInstance != &lt;SPAN style="COLOR: #0000ff"&gt;null
&lt;/SPAN&gt;                            &amp;amp;&amp;amp; webApp.OutboundMailServiceInstance.Server != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
                        {
                            smtpServer =
                                webApp.OutboundMailServiceInstance.Server.Address;
                        }

                        &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(smtpServer) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)                            
                        {
                            &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;InvalidOperationException&lt;/SPAN&gt;(
                                &lt;SPAN style="COLOR: #a31515"&gt;"The outbound SMTP server is not specified in"
&lt;/SPAN&gt;                                + &lt;SPAN style="COLOR: #a31515"&gt;" SharePoint Central Administration."&lt;/SPAN&gt;);
                        }

                        defaultFromAddress = webApp.OutboundMailSenderAddress;
                    }
                }
            }
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Note that I use static members in order to only read the SMTP server configuration from SharePoint Central Administration one time.&lt;/P&gt;
&lt;P&gt;Assuming you just want to send a simple message using the default "From address" specified in SharePoint Central Administration, you only need a single line of code that passes three parameters:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;            &lt;SPAN style="COLOR: #2b91af"&gt;SharePointSmtpHelper&lt;/SPAN&gt;.SendMessage(
                &lt;SPAN style="COLOR: #a31515"&gt;"jeremy_jameson@fabrikam.com"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #a31515"&gt;"Test message"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #a31515"&gt;"Testing the SharePointSmtpHelper class"&lt;/SPAN&gt;);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9908769" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="MOSS 2007" scheme="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx" /><category term="WSS v3" scheme="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx" /></entry><entry><title>Introducing the SharePointWebPartHelper Class</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/jjameson/archive/2009/10/17/introducing-the-sharepointwebparthelper-class.aspx" /><id>http://blogs.msdn.com/jjameson/archive/2009/10/17/introducing-the-sharepointwebparthelper-class.aspx</id><published>2009-10-17T12:54:00Z</published><updated>2009-10-17T12:54:00Z</updated><content type="html">&lt;P&gt;In a previous post, I introduced the &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/03/31/introducing-the-dr-dada-approach-to-sharepoint-development.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/03/31/introducing-the-dr-dada-approach-to-sharepoint-development.aspx"&gt;DR.DADA approach to SharePoint development&lt;/A&gt; and how I typically use the concept of a &lt;A href="http://blogs.msdn.com/jjameson/archive/2007/03/22/what-s-in-a-name-defaultfeaturereceiver-vs-featureconfigurator.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2007/03/22/what-s-in-a-name-defaultfeaturereceiver-vs-featureconfigurator.aspx"&gt;FeatureConfigurator&lt;/A&gt; to automatically configure one or more aspects of a SharePoint site when activating my feature.&lt;/P&gt;
&lt;P&gt;For example, on my latest project, we needed a login page as well as a legal disclaimer page for a customer service portal based on Microsoft Office SharePoint Server (MOSS) 2007. Thus I created a "PublicSiteConfiguration" feature that, upon activation:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Automatically creates the &lt;STRONG&gt;/Public &lt;/STRONG&gt;site&lt;/LI&gt;
&lt;LI&gt;Populates the page content on the /Public/Pages/default.aspx page and adds an instance of a custom Login Form Web Part to the page&lt;/LI&gt;
&lt;LI&gt;Creates the /Public/Pages/Disclaimer.aspx page and populates its default content&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;I've already introduced the &lt;CODE&gt;&lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/09/introducing-the-sharepointpublishinghelper-class.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/09/introducing-the-sharepointpublishinghelper-class.aspx"&gt;SharePointPublishingHelper&lt;/A&gt;&lt;/CODE&gt; class that performs the bulk of the work in creating and configuring publishing pages. In this post, I want to cover the &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; class. Like the &lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; class, the &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; class is simply a collection of helper methods for the SharePoint API.&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; makes it really easy to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Attempt to retrieve a reference to a Web Part by specifying an &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.splimitedwebpartmanager.aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.splimitedwebpartmanager.aspx"&gt;SPLimitedWebPartManager&lt;/A&gt; for a specific page and the title of the Web Part you are trying to find&lt;/LI&gt;
&lt;LI&gt;Ensure a Web Part exists on a page (creating a new Web Part as necessary)&lt;/LI&gt;
&lt;LI&gt;Ensuring a &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.contenteditorwebpart.aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.contenteditorwebpart.aspx"&gt;ContentEditorWebPart&lt;/A&gt; exists on a page and that it is configured with the specified HTML content and title (as well as removing the "chrome", since -- at least in my experience -- you don't want to show this to users for this type of Web Part)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Note that one could argue that the stuff specific to the Content Editor Web Part doesn't really belong in this class, but nevertheless that's where it ended up after refactoring the code a few years ago on the Agilent Technologies project. [Actually, I believe it originally ended up in an even more generic &lt;CODE&gt;SharePointHelper&lt;/CODE&gt; class, but I've since refactored it even further into the &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; class.]&lt;/P&gt;
&lt;P&gt;Anyway, here's the code for the &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; class:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Diagnostics;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Globalization;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.IO;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Security.Permissions;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Web.UI.WebControls.WebParts;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Xml;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint.Security;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; SPWebPartPages = Microsoft.SharePoint.WebPartPages;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.CoreServices.Logging;

&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Demo.CoreServices.SharePoint
{
    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Exposes static methods for commonly used helper functions for
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; SharePoint Web Parts. This class cannot be inherited.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;remarks&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; All methods of the &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;SharePointWebPartHelper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; class are static and
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; can therefore be called without creating an instance of the class.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/remarks&amp;gt;
&lt;/SPAN&gt;    [&lt;SPAN style="COLOR: #2b91af"&gt;CLSCompliant&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)]
    [&lt;SPAN style="COLOR: #2b91af"&gt;SharePointPermission&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;SecurityAction&lt;/SPAN&gt;.LinkDemand, ObjectModel = &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;sealed&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SharePointWebPartHelper
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; SharePointWebPartHelper() { } &lt;SPAN style="COLOR: #008000"&gt;// all members are static

&lt;/SPAN&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: #2b91af"&gt;WebPart&lt;/SPAN&gt; CreateWebPart(
            SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;SPLimitedWebPartManager&lt;/SPAN&gt; wpm,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartId,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartFilename,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; zoneId,
            &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; zoneIndex)
        {
            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(wpm != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartId) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);
            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartFilename) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);
            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(zoneId) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Creating Web Part ({0}) on page ({1})..."&lt;/SPAN&gt;,
                webPartId,
                wpm.ServerRelativeUrl);

            &lt;SPAN style="COLOR: #2b91af"&gt;WebPart&lt;/SPAN&gt; webPart = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #2b91af"&gt;SPFile&lt;/SPAN&gt; wpFile = GetWebPartFileFromGallery(
                wpm.Web.Site,
                webPartFilename);

            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(wpFile != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; errorMessage = &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Empty;

            &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;Stream&lt;/SPAN&gt; stream = wpFile.OpenBinaryStream())
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;/SPAN&gt; reader = &lt;SPAN style="COLOR: #2b91af"&gt;XmlReader&lt;/SPAN&gt;.Create(stream);
                webPart = wpm.ImportWebPart(reader, &lt;SPAN style="COLOR: #0000ff"&gt;out&lt;/SPAN&gt; errorMessage);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(errorMessage) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; message =
                    &lt;SPAN style="COLOR: #a31515"&gt;"Error importing Web Part ("
&lt;/SPAN&gt;                        + webPartFilename + &lt;SPAN style="COLOR: #a31515"&gt;"): "
&lt;/SPAN&gt;                        + errorMessage;

                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;WebPartPageUserException&lt;/SPAN&gt;(message);
            }

            webPart.ID = webPartId;
            wpm.AddWebPart(webPart, zoneId, zoneIndex);

            &lt;SPAN style="COLOR: #008000"&gt;// HACK: When adding the first, second, third, and fourth Web Parts
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// to a zone:
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;//
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;//    SPLimitedWebPartManager.AddWebPart(webPart, zoneId, zoneIndex)
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;//
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// behaves as expected, meaning that
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// (webPart.ZoneIndex == zoneIndex).
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;//
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// However, when adding the fifth and sixth Web Parts to a zone,
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// then (webPart.ZoneIndex == zoneIndex + 1).
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPart.ZoneIndex &amp;gt; zoneIndex)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(zoneIndex &amp;gt;= 4);

                &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                    &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                    &lt;SPAN style="COLOR: #a31515"&gt;"HACK: webPart.ZoneIndex ({0})"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" is greater than zoneIndex ({1})."
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" Setting zoneIndex to {0}..."&lt;/SPAN&gt;,
                    webPart.ZoneIndex,
                    zoneIndex);

                zoneIndex = webPart.ZoneIndex;
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(webPart.ZoneIndex == zoneIndex);
            zoneIndex++;
            
            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogInfo(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Successfully created Web Part ({0}) on page ({1})."&lt;/SPAN&gt;,
                webPartId,
                wpm.ServerRelativeUrl);

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; webPart;
        }

        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Ensures that a specific Web Part exists on a page.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="wpm"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The Web Part manager for the page.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="webPartId"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The unique identifier for the Web Part.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="webPartFileName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The .dwp or .webpart file in the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Web Part gallery (used to import the Web Part if it does not exist).
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="zoneId"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The zone the Web Part should reside in.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="zoneIndex"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The index of the Web Part relative to other
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Web Parts in the zone. If the Web Part is created, the index is
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; incremented.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The new or existing Web Part on the page.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/returns&amp;gt;
&lt;/SPAN&gt;        [System.Diagnostics.CodeAnalysis.&lt;SPAN style="COLOR: #2b91af"&gt;SuppressMessage&lt;/SPAN&gt;(
            &lt;SPAN style="COLOR: #a31515"&gt;"Microsoft.Design"&lt;/SPAN&gt;,
            &lt;SPAN style="COLOR: #a31515"&gt;"CA1045:DoNotPassTypesByReference"&lt;/SPAN&gt;,
            Justification = &lt;SPAN style="COLOR: #a31515"&gt;"The zoneIndex is incremented when the Web Part is"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" added."&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: #2b91af"&gt;WebPart&lt;/SPAN&gt; EnsureWebPart(
            SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;SPLimitedWebPartManager&lt;/SPAN&gt; wpm,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartId,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartFileName,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; zoneId,
            &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; zoneIndex)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (wpm == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"wpm"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartId) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part Id must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"webPartId"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartFileName) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part file name must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"webPartFileName"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(zoneId) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part zone must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"zoneId"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;WebPart&lt;/SPAN&gt; webPart = wpm.WebParts[webPartId];

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPart == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                webPart = CreateWebPart(wpm, webPartId, webPartFileName,
                    zoneId, &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else
&lt;/SPAN&gt;            {
                &lt;SPAN style="COLOR: #008000"&gt;// HACK: webPart.Zone appears to always be null (SharePoint bug?)
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPart.Zone == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
                {
                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Unable to check zone for Web Part ({0})"
&lt;/SPAN&gt;                            + &lt;SPAN style="COLOR: #a31515"&gt;" because webPart.Zone is null."&lt;/SPAN&gt;,
                        webPartId);
                }
                &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPart.Zone.ID != zoneId)
                {
                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Moving Web Part ({0}) to zone ({1})..."&lt;/SPAN&gt;,
                        webPartId,
                        zoneId);

                    wpm.MoveWebPart(webPart, zoneId, zoneIndex);
                    wpm.SaveChanges(webPart);

                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogInfo(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Successfully moved Web Part ({0}) to zone ({1})."&lt;/SPAN&gt;,
                        webPartId,
                        zoneId);
                }
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; webPart;
        }

        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Finds the first Web Part with the specified title.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;remarks&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; This is useful in cases where the Web Part ID is not specified
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; when it was added to the collection of Web Parts (thus generating
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; a random identifier and making SPLimitedWebPartCollection[id]
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; effectively useless).
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/remarks&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="wpm"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The Web Part manager for the page.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="webPartTitle"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The title of the Web Part to find.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;A Web Part object (if one is found), otherwise null.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&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: #2b91af"&gt;WebPart&lt;/SPAN&gt; FindWebPartByTitle(
            SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;SPLimitedWebPartManager&lt;/SPAN&gt; wpm,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartTitle)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (wpm == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"wpm"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartTitle) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part title must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"webPartTitle"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Attemping to find Web Part ({0}) on page ({1})..."&lt;/SPAN&gt;,
                webPartTitle,
                wpm.ServerRelativeUrl);

            &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; wpm.WebParts.Count; i++)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;WebPart&lt;/SPAN&gt; webPart = wpm.WebParts[i];

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Compare(
                        webPart.Title,
                        webPartTitle,
                        &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                {
                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Found Web Part ({0}) on page ({1})."&lt;/SPAN&gt;,
                        webPartTitle,
                        wpm.ServerRelativeUrl);

                    &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; webPart;
                }
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Unable to find Web Part ({0}) on page ({1})."&lt;/SPAN&gt;,
                webPartTitle,
                wpm.ServerRelativeUrl);

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&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: #2b91af"&gt;SPFile&lt;/SPAN&gt; GetWebPartFileFromGallery(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPSite&lt;/SPAN&gt; site,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartFilename)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (site == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"site"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPartFilename == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"webPartFilename"&lt;/SPAN&gt;);
            }

            webPartFilename = webPartFilename.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartFilename))
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part filename must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"webPartFilename"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Getting Web Part file ({0}) from site ({1}) gallery..."&lt;/SPAN&gt;,
                webPartFilename,
                site.Url);

            &lt;SPAN style="COLOR: #2b91af"&gt;SPList&lt;/SPAN&gt; wpGallery = site.GetCatalog(&lt;SPAN style="COLOR: #2b91af"&gt;SPListTemplateType&lt;/SPAN&gt;.WebPartCatalog);

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; camlQuery = &lt;SPAN style="COLOR: #a31515"&gt;"&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name=\"FileLeafRef\" /&amp;gt;"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;"&amp;lt;Value Type=\"File\"&amp;gt;"&lt;/SPAN&gt; + webPartFilename + &lt;SPAN style="COLOR: #a31515"&gt;"&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt;"&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #2b91af"&gt;SPQuery&lt;/SPAN&gt; query = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SPQuery&lt;/SPAN&gt;();
            query.Query = camlQuery;

            &lt;SPAN style="COLOR: #2b91af"&gt;SPListItemCollection&lt;/SPAN&gt; webParts = wpGallery.GetItems(query);
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webParts.Count == 0)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; message = &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Format(
                    &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Web Part ({0}) was not found in the Web Part Gallery."&lt;/SPAN&gt;,
                    webPartFilename);
                
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    message,
                    &lt;SPAN style="COLOR: #a31515"&gt;"webPartFilename"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Found Web Part file ({0}) in site ({1}) gallery."&lt;/SPAN&gt;,
                webPartFilename,
                site.Url);

            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(webParts.Count == 1);
            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; webParts[0].File;
        }

        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Ensures that a Content Editor Web Part exists on a page
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; and is configured with the specified settings.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="wpm"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The Web Part manager for the page.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="webPartId"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The unique identifier for the Web Part.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="zoneId"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The zone the Web Part should reside in.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="zoneIndex"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The index of the Web Part relative to other
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Web Parts in the zone. If the Web Part is created, the index is
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; incremented.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="htmlContent"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The content to display within the Web
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Part.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;param name="title"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The title of the Web Part.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The new or existing Web Part on the page.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/returns&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;        
&lt;/SPAN&gt;        [System.Diagnostics.CodeAnalysis.&lt;SPAN style="COLOR: #2b91af"&gt;SuppressMessage&lt;/SPAN&gt;(
            &lt;SPAN style="COLOR: #a31515"&gt;"Microsoft.Design"&lt;/SPAN&gt;,
            &lt;SPAN style="COLOR: #a31515"&gt;"CA1045:DoNotPassTypesByReference"&lt;/SPAN&gt;,
            Justification=&lt;SPAN style="COLOR: #a31515"&gt;"The zoneIndex is incremented when the Web Part is"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" added."&lt;/SPAN&gt;)]
        &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;ContentEditorWebPart
&lt;/SPAN&gt;            EnsureContentEditorWebPart(
                SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;SPLimitedWebPartManager&lt;/SPAN&gt; wpm,
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webPartId,
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; zoneId,
                &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; zoneIndex,
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; htmlContent,
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; title)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (wpm == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"wpm"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPartId == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"webPartId"&lt;/SPAN&gt;);
            }

            webPartId = webPartId.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(webPartId))
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part ID must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"webPartId"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (zoneId == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"zoneId"&lt;/SPAN&gt;);
            }

            zoneId = zoneId.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(zoneId))
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Web Part zone must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"zoneId"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (htmlContent == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"htmlContent"&lt;/SPAN&gt;);
            }

            htmlContent = htmlContent.Trim();
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(htmlContent))
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentException&lt;/SPAN&gt;(
                    &lt;SPAN style="COLOR: #a31515"&gt;"The HTML content must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"htmlContent"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #008000"&gt;// Note: title is optional

&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                &lt;SPAN style="COLOR: #a31515"&gt;"Ensuring Content Editor Web Part ({0}) on page ({1})..."&lt;/SPAN&gt;,
                webPartId,
                wpm.ServerRelativeUrl);

            SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;ContentEditorWebPart&lt;/SPAN&gt; webPart =
                (SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;ContentEditorWebPart&lt;/SPAN&gt;) EnsureWebPart(
                    wpm,
                    webPartId,
                    &lt;SPAN style="COLOR: #a31515"&gt;"MSContentEditor.dwp"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (webPart.Content == &lt;SPAN style="COLOR: #0000ff"&gt;null
&lt;/SPAN&gt;                || webPart.Content.InnerText != htmlContent
                || webPart.Title != title
                || webPart.ChromeType != &lt;SPAN style="COLOR: #2b91af"&gt;PartChromeType&lt;/SPAN&gt;.None)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                    &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Updating properties of Content Editor Web Part ({0}) on"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" page ({1})..."&lt;/SPAN&gt;,
                    webPartId,
                    wpm.ServerRelativeUrl);

                &lt;SPAN style="COLOR: #008000"&gt;// To bring content into the Content Editor Web Part,
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #008000"&gt;// we need to use an XML Document
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #2b91af"&gt;XmlDocument&lt;/SPAN&gt; xmlDoc = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;XmlDocument&lt;/SPAN&gt;();
                &lt;SPAN style="COLOR: #2b91af"&gt;XmlElement&lt;/SPAN&gt; xmlElement = xmlDoc.CreateElement(&lt;SPAN style="COLOR: #a31515"&gt;"HtmlContent"&lt;/SPAN&gt;);
                xmlElement.InnerText = htmlContent;
                webPart.Content = xmlElement;

                webPart.Title = title;
                webPart.ChromeType = &lt;SPAN style="COLOR: #2b91af"&gt;PartChromeType&lt;/SPAN&gt;.None;

                wpm.SaveChanges(webPart);

                &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogInfo(
                    &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Successfully updated properties of Content Editor Web Part"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" ({0}) on page ({1})."&lt;/SPAN&gt;,
                    webPartId,
                    wpm.ServerRelativeUrl);
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else
&lt;/SPAN&gt;            {
                &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogDebug(
                    &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                    &lt;SPAN style="COLOR: #a31515"&gt;"The Content Editor Web Part ({0}) on page ({1}) is already"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" configured with the expected settings."&lt;/SPAN&gt;,
                    webPartId,
                    wpm.ServerRelativeUrl);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; webPart;
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Most of the code in the &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; class is very straightforward. The most interesting hack -- er, I mean &lt;EM&gt;workaround&lt;/EM&gt; -- in the code is to handle the scenario where the &lt;CODE&gt;zoneIndex&lt;/CODE&gt; is sometimes mysteriously incremented by more than one, but you can read more about this in a &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/06/05/splimitedwebpartmanager-addwebpart-mysteriously-increments-zoneindex.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/06/05/splimitedwebpartmanager-addwebpart-mysteriously-increments-zoneindex.aspx"&gt;previous post&lt;/A&gt; -- if you are really interested.&lt;/P&gt;
&lt;P&gt;Using the &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; class couldn't be easier. For a simple example, consider the scenario that I mentioned earlier about adding a Login Form Web Part to a page:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;            &lt;SPAN style="COLOR: #008000"&gt;// Configure Web Parts
&lt;/SPAN&gt;            SPWebPartPages.&lt;SPAN style="COLOR: #2b91af"&gt;SPLimitedWebPartManager&lt;/SPAN&gt; wpm =
                publicWeb.GetLimitedWebPartManager(
                    page.Url,
                    &lt;SPAN style="COLOR: #2b91af"&gt;PersonalizationScope&lt;/SPAN&gt;.Shared);

            &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (wpm)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; zoneId = &lt;SPAN style="COLOR: #a31515"&gt;"LeftColumnZone"&lt;/SPAN&gt;;
                &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; zoneIndex = 0;

                &lt;SPAN style="COLOR: #2b91af"&gt;LoginFormWebPart&lt;/SPAN&gt; loginForm =
                    (&lt;SPAN style="COLOR: #2b91af"&gt;LoginFormWebPart&lt;/SPAN&gt;) &lt;SPAN style="COLOR: #2b91af"&gt;SharePointWebPartHelper&lt;/SPAN&gt;.EnsureWebPart(
                        wpm,
                        &lt;SPAN style="COLOR: #a31515"&gt;"LoginForm"&lt;/SPAN&gt;,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Fabrikam_LoginForm.webpart"&lt;/SPAN&gt;,
                        zoneId,
                        &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                loginForm.DisplayRememberMe = &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
                wpm.SaveChanges(loginForm);

                &lt;SPAN style="COLOR: #008000"&gt;// HACK: Avoid memory leak in SPLimitedWebPartManager
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (wpm.Web != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
                {
                    wpm.Web.Dispose();
                }
            }&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Just be sure to avoid &lt;A href="http://blogs.msdn.com/jjameson/archive/2008/04/09/memory-leak-in-splimitedwebpartmanager-a-k-a-idisposables-containing-idisposables.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2008/04/09/memory-leak-in-splimitedwebpartmanager-a-k-a-idisposables-containing-idisposables.aspx"&gt;the memory leak in SPLimitedWebPartManager&lt;/A&gt;, like I show in the code example above.&lt;/P&gt;
&lt;P&gt;Here's another code example where I configured a bunch of Web Parts on a search results page:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Web.Search.Configuration
{
    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;summary&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; Exposes static methods for configuring the &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;Fabrikam.Web.Search&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/b&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; feature. This class cannot be inherited.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/summary&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;remarks&amp;gt;
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; All methods of the &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;FeatureConfigurator&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/b&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; class are static and can
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; therefore be called without creating an instance of the class.
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/remarks&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;  
&lt;/SPAN&gt;    [CLSCompliant(&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)]
    [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = &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;sealed&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;FeatureConfigurator
&lt;/SPAN&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;void&lt;/SPAN&gt; ConfigureSearchResultsPageWebParts(
            SPWeb searchWeb,
            PublishingPage searchResultsPage,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; defaultSearchResultsPageUrl,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; scopeName,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; additionalQueryTerms,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; contextualScopeUrl)
        {
            SPWebPartPages.SPLimitedWebPartManager wpm =
                searchWeb.GetLimitedWebPartManager(
                    searchResultsPage.Url, PersonalizationScope.Shared);

            &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (wpm)
            {
&lt;SPAN style="COLOR: #0000ff"&gt;                #region&lt;/SPAN&gt; Zone1

                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; zoneId = &lt;SPAN style="COLOR: #a31515"&gt;"Zone1"&lt;/SPAN&gt;;
                &lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; zoneIndex = 0;

                SharePointWebPartHelper.EnsureContentEditorWebPart(
                    wpm,
                    &lt;SPAN style="COLOR: #a31515"&gt;"startNewSearchHeading"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex,
                    &lt;SPAN style="COLOR: #a31515"&gt;"&amp;lt;h2 class='accent3'&amp;gt;Start a new search&amp;lt;/h2&amp;gt;"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Start New Search Heading"&lt;/SPAN&gt;);

                SearchBoxEx searchBox =
                    (SearchBoxEx)SharePointWebPartHelper.EnsureWebPart(
                        wpm,
                        &lt;SPAN style="COLOR: #a31515"&gt;"searchBox"&lt;/SPAN&gt;,
                        &lt;SPAN style="COLOR: #a31515"&gt;"SearchBox.dwp"&lt;/SPAN&gt;,
                        zoneId,
                        &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                searchBox.DropDownModeEx = DropDownModesEx.HideScopeDD;
                searchBox.SearchResultPageURL = defaultSearchResultsPageUrl;
                searchBox.Width = &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Empty;

                wpm.SaveChanges(searchBox);

                SharePointWebPartHelper.EnsureContentEditorWebPart(
                    wpm,
                    &lt;SPAN style="COLOR: #a31515"&gt;"refineSearchHeading"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex,
                    &lt;SPAN style="COLOR: #a31515"&gt;"&amp;lt;h2 class='accent3'&amp;gt;Refine your search&amp;lt;/h2&amp;gt;"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Refine Search Heading"&lt;/SPAN&gt;);

                FabrikamSearchBoxWebPart searchScopeOptions =
                    (FabrikamSearchBoxWebPart)SharePointWebPartHelper.EnsureWebPart(
                        wpm,
                        &lt;SPAN style="COLOR: #a31515"&gt;"searchScopeOptions"&lt;/SPAN&gt;,
                        &lt;SPAN style="COLOR: #a31515"&gt;"FabrikamSearchBox.webpart"&lt;/SPAN&gt;,
                        zoneId,
                        &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                searchScopeOptions.ShowSearchBox = &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
                wpm.SaveChanges(searchScopeOptions);

                ConfigureFacetedSearchWebParts(
                    wpm,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex,
                    scopeName);

&lt;SPAN style="COLOR: #0000ff"&gt;                #endregion
&lt;/SPAN&gt;                
&lt;SPAN style="COLOR: #0000ff"&gt;                #region&lt;/SPAN&gt; Zone2

                zoneId = &lt;SPAN style="COLOR: #a31515"&gt;"Zone2"&lt;/SPAN&gt;;
                zoneIndex = 0;

                SharePointWebPartHelper.EnsureWebPart(
                    wpm,
                    &lt;SPAN style="COLOR: #a31515"&gt;"searchTabs"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"FabrikamListBoundTabStrip.webpart"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                SharePointWebPartHelper.EnsureWebPart(
                    wpm,
                    &lt;SPAN style="COLOR: #a31515"&gt;"searchSummary"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"SearchSummary.dwp"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; showBestBetsWebPart = &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Compare(
                    searchResultsPage.Name,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Results.aspx"&lt;/SPAN&gt;,
                    StringComparison.OrdinalIgnoreCase) == 0)
                {
                    showBestBetsWebPart = &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&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;string&lt;/SPAN&gt;.Compare(
                    searchResultsPage.Name,
                    &lt;SPAN style="COLOR: #a31515"&gt;"AllSitesResults.aspx"&lt;/SPAN&gt;,
                    StringComparison.OrdinalIgnoreCase) == 0)
                {
                    showBestBetsWebPart = &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;
                }

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (showBestBetsWebPart == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
                {
                    ConfigureBestBetsWebPartForSiteSearch(
                        wpm,
                        zoneId,
                        &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);
                }

                SearchStatsWebPart searchStats =
                    (SearchStatsWebPart) SharePointWebPartHelper.EnsureWebPart(
                        wpm,
                        &lt;SPAN style="COLOR: #a31515"&gt;"searchStats"&lt;/SPAN&gt;,
                        &lt;SPAN style="COLOR: #a31515"&gt;"searchStats.dwp"&lt;/SPAN&gt;,
                        zoneId,
                        &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                searchStats.DisplayResponseTime = &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
                wpm.SaveChanges(searchStats);
                
                SharePointWebPartHelper.EnsureWebPart(
                    wpm,
                    &lt;SPAN style="COLOR: #a31515"&gt;"searchPaging1"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"SearchPaging.dwp"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                ConfigureCoreResultsWebPartsForSiteSearch(
                    wpm,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex,
                    scopeName);

                SharePointWebPartHelper.EnsureWebPart(
                    wpm,
                    &lt;SPAN style="COLOR: #a31515"&gt;"searchPaging2"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"SearchPaging.dwp"&lt;/SPAN&gt;,
                    zoneId,
                    &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (additionalQueryTerms != &lt;SPAN style="COLOR: #0000ff"&gt;null
&lt;/SPAN&gt;                    || contextualScopeUrl != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
                {
                    ConfigureCoreResultsExtensionWebPart(
                        wpm,
                        additionalQueryTerms,
                        contextualScopeUrl,
                        zoneId,
                        &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; zoneIndex);
                }

&lt;SPAN style="COLOR: #0000ff"&gt;                #endregion
&lt;/SPAN&gt;                
                &lt;SPAN style="COLOR: #008000"&gt;// HACK: Avoid memory leak in SPLimitedWebPartManager
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (wpm.Web != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
                {
                    wpm.Web.Dispose();
                }
            }
        }
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Even though I didn't add any comments to this (rather lengthy) method, I think you'll find it is actually very easy to understand simply by reading the method names and parameters -- or at least that's what I hope for the people that are actually maintaining this code from my previous project ;-)&lt;/P&gt;
&lt;P&gt;I hope you find the &lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; and &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt; classes as useful as I have over the past several years.&lt;/P&gt;
&lt;P&gt;Be sure to stay tuned, because there are more SharePoint helper classes to come, but my daughter just woke up and now I need to go make some pancakes!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9908548" width="1" height="1"&gt;</content><author><name>jjameson</name><uri>http://blogs.msdn.com/members/jjameson.aspx</uri></author><category term="My System" scheme="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx" /><category term="MOSS 2007" scheme="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx" /><category term="WSS v3" scheme="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx" /></entry></feed>