<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Random Musings of Jeremy Jameson : MOSS 2007</title><link>http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx</link><description>Tags: MOSS 2007</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Database Default Locations in SQL Server</title><link>http://blogs.msdn.com/jjameson/archive/2009/12/03/database-default-locations-in-sql-server.aspx</link><pubDate>Thu, 03 Dec 2009 13:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9931948</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9931948.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9931948</wfw:commentRss><description>&lt;P&gt;I've mentioned before the importance of using multiple "spindles" when working with large SQL Server databases.&lt;/P&gt;
&lt;P&gt;Generally speaking, the recommendation is to use different RAID 1+0 arrays for data and log files -- and depending on the size and load of your database, you may also need to isolate data files on individual RAID 1+0 arrays.&lt;/P&gt;
&lt;P&gt;For really large OLTP databases that require lots of &lt;A href="http://en.wikipedia.org/wiki/IOPS" mce_href="http://en.wikipedia.org/wiki/IOPS"&gt;IOPS&lt;/A&gt;, additional arrays might also be required to split the log files (although, honestly, I haven't worked on any projects where this has been necessary).&lt;/P&gt;
&lt;P&gt;One of the configuration steps that I always recommend for any Production SQL Server environment is to configure the default database locations to ensure your "data I/O" is isolated from your "log I/O" (both of which should be isolated from other I/O -- specifically, the paging file).&lt;/P&gt;
&lt;P&gt;For example, suppose you have the following disk configuration on your SQL Server cluster:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;C: (Local Disk) - RAID 1 array for operating system files, program files, and paging file&lt;/LI&gt;
&lt;LI&gt;D: (DATA01) - RAID 1+0 array for data files&lt;/LI&gt;
&lt;LI&gt;L: (LOG01) - RAID 1+0 array for log files&lt;/LI&gt;
&lt;LI&gt;Q: (Quorum)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In this simplistic example, the D:, L:, and Q: drives are LUNs on the backend SAN, whereas the C: drive is DAS (Direct Attached Storage). Hopefully, the Storage team responsible for managing your SAN provides dedicated physical drives for D: and L: -- although, honestly, I've seen several enterprise organizations that don't dedicate these drives and subsequently experience performance issues later on.&lt;/P&gt;
&lt;P&gt;Given the above disk configuration, SQL Server Management Studio should be used to configure the default database locations similar to the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Server Properties 
&lt;UL&gt;
&lt;LI&gt;Database Settings 
&lt;UL&gt;
&lt;LI&gt;Default database locations 
&lt;UL&gt;
&lt;LI&gt;Data: D:\NotBackedUp\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA&lt;/LI&gt;
&lt;LI&gt;Log: L:\NotBackedUp\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA&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;You certainly don't have to use the &lt;A href="http://blogs.msdn.com/jjameson/archive/2007/03/22/backedup-and-notbackedup.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2007/03/22/backedup-and-notbackedup.aspx"&gt;NotBackedUp&lt;/A&gt; folder if you don't want to (that's just the standard that I've been using for years).&lt;/P&gt;
&lt;P&gt;Once you've configured the default database locations, anytime you create a new database -- for example, when you create a new Web application or content database in Microsoft Office SharePoint Server (MOSS) 2007 -- the data and log files will be placed on the desired drives (i.e. D: and L:, respectively).&lt;/P&gt;
&lt;P&gt;Of course, when creating MOSS 2007 databases for a Production (or Test) environment, you still need to resize them appropriately in order to avoid having them simply auto-grow from a very small initial size (in order to avoid fragmentation and optimize performance).&lt;/P&gt;
&lt;P&gt;Suppose you need to determine the default database locations through SQL (perhaps because you are scripting the process to create your databases). If you fire up SQL Server Profiler and start a new trace (the default trace options are fine), you will find that SQL Server Management Studio executes the following SQL statements when viewing the &lt;STRONG&gt;Database Settings &lt;/STRONG&gt;page in the &lt;STRONG&gt;Server Properties &lt;/STRONG&gt;window:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;declare&lt;/SPAN&gt; @RegPathParams &lt;SPAN style="COLOR: #0000ff"&gt;sysname
declare&lt;/SPAN&gt; @Arg &lt;SPAN style="COLOR: #0000ff"&gt;sysname
declare&lt;/SPAN&gt; @Param &lt;SPAN style="COLOR: #0000ff"&gt;sysname
declare&lt;/SPAN&gt; @MasterPath &lt;SPAN style="COLOR: #0000ff"&gt;nvarchar&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;512&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;declare&lt;/SPAN&gt; @LogPath &lt;SPAN style="COLOR: #0000ff"&gt;nvarchar&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;512&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;declare&lt;/SPAN&gt; @ErrorLogPath &lt;SPAN style="COLOR: #0000ff"&gt;nvarchar&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;512&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;declare&lt;/SPAN&gt; @n &lt;SPAN style="COLOR: #0000ff"&gt;int

select&lt;/SPAN&gt; @n&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;0
&lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @RegPathParams&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;N'Software\Microsoft\MSSQLServer\MSSQLServer'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;+&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;'\Parameters'
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @Param&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;'dummy'
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;while&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(not&lt;/SPAN&gt; @Param &lt;SPAN style="COLOR: #808080"&gt;is&lt;/SPAN&gt; &lt;SPAN style="COLOR: #808080"&gt;null)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;begin
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @Param&lt;SPAN style="COLOR: #808080"&gt;=null
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @Arg&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;'SqlArg'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;+&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;convert&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;nvarchar&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt;@n&lt;SPAN style="COLOR: #808080"&gt;)

&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;exec&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;master&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;.&lt;/SPAN&gt;dbo&lt;SPAN style="COLOR: #808080"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;xp_instance_regread
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;N'HKEY_LOCAL_MACHINE'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;        @RegPathParams&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;        @Arg&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;        @Param &lt;SPAN style="COLOR: #0000ff"&gt;OUTPUT
&lt;/SPAN&gt;        
    &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param &lt;SPAN style="COLOR: #808080"&gt;like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;'-d%'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;begin
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @Param&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; 3&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; 255&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @MasterPath&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(
&lt;/SPAN&gt;            @Param&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;            1&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff00ff"&gt;len&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR: #808080"&gt;-&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;charindex&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;'\'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;reverse&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;)))&lt;/SPAN&gt;            
    &lt;SPAN style="COLOR: #0000ff"&gt;end
&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: #808080"&gt;(&lt;/SPAN&gt;@Param &lt;SPAN style="COLOR: #808080"&gt;like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;'-l%'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;begin
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @Param&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; 3&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; 255&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @LogPath&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(
&lt;/SPAN&gt;            @Param&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;            1&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff00ff"&gt;len&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR: #808080"&gt;-&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;charindex&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;'\'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;reverse&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;)))
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;end
&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: #808080"&gt;(&lt;/SPAN&gt;@Param &lt;SPAN style="COLOR: #808080"&gt;like&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;'-e%'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;begin
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @Param&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; 3&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; 255&lt;SPAN style="COLOR: #808080"&gt;)
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @ErrorLogPath&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff00ff"&gt;substring&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(
&lt;/SPAN&gt;            @Param&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;            1&lt;SPAN style="COLOR: #808080"&gt;,
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #ff00ff"&gt;len&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR: #808080"&gt;-&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;charindex&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;'\'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;reverse&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;(&lt;/SPAN&gt;@Param&lt;SPAN style="COLOR: #808080"&gt;)))
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;end
&lt;/SPAN&gt;    
    &lt;SPAN style="COLOR: #0000ff"&gt;select&lt;/SPAN&gt; @n&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;@n&lt;SPAN style="COLOR: #808080"&gt;+&lt;/SPAN&gt;1
&lt;SPAN style="COLOR: #0000ff"&gt;end
&lt;/SPAN&gt;            
&lt;SPAN style="COLOR: #0000ff"&gt;print&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;'LogPath = '&lt;/SPAN&gt; &lt;SPAN style="COLOR: #808080"&gt;+&lt;/SPAN&gt; @LogPath
&lt;SPAN style="COLOR: #0000ff"&gt;print&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;'MasterPath = '&lt;/SPAN&gt; &lt;SPAN style="COLOR: #808080"&gt;+&lt;/SPAN&gt; @MasterPath&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Note that I truncated the actual SQL batch and added the &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;print&lt;/SPAN&gt; &lt;/CODE&gt;statements.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9931948" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/SQL+Server/default.aspx">SQL Server</category></item><item><title>Bug with Duplicate Field Names in MOSS 2007</title><link>http://blogs.msdn.com/jjameson/archive/2009/12/01/bug-with-duplicate-field-names-in-moss-2007.aspx</link><pubDate>Tue, 01 Dec 2009 16:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9930835</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9930835.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9930835</wfw:commentRss><description>&lt;P&gt;I encountered a rather nasty bug in Microsoft Office SharePoint Server (MOSS) 2007 yesterday that occurs when a custom field (i.e. site column) has the same name as an existing field. Note that this issue will also occur in Windows SharePoint Services (WSS) v3.&lt;/P&gt;
&lt;P&gt;I initially created the following Fields.xml file:&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;xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;1.0&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;utf-8&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; ?&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{11F7E97D-6282-44b1-8222-2E6E377BCDFC}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;AnnouncementEndDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Custom Columns&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement End Date&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{9D1F7E52-EFBF-431e-9331-7DCA31D9CB7A}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;AnnouncementStartDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Custom Columns&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Start Date&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&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;Next, I created the ContentTypes.xml file:&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;xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;1.0&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;utf-8&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; ?&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentType
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D400EF37EB6F40C54a21A3872B1E6CA5BC0A&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Page&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Page is a custom content type ...&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Content Types&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{9D1F7E52-EFBF-431e-9331-7DCA31D9CB7A}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;AnnouncementStartDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{11F7E97D-6282-44b1-8222-2E6E377BCDFC}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;AnnouncementEndDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DocumentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;TargetName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;/_layouts/CreatePage.aspx&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;BLOCKQUOTE class=note&gt;
&lt;DIV class=noteTitle&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;The really long ContentType ID above specifies that Announcement Page inherits from the out-of-the-box Welcome Page. I vaguely recall reading somebody's blog where he or she stated that you shouldn't inherit from the OOTB page types. However, I don't recall the justification -- if there even was one. I haven't encountered any problems with this approach and thus haven't seen any compelling reason to stop doing so.&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then I created a page layout for the new Announcement Page content type.&lt;/P&gt;
&lt;P&gt;After building and deploying the corresponding WSP -- and activating the feature -- I verified that I could create a new Announcement Page and specify field values, including Announcement Start Date and Announcement End Date. Consequently I checked in my changes to TFS.&lt;/P&gt;
&lt;P&gt;At that point, I started thinking that perhaps AnnouncementStartDate should simply be StartDate and AnnouncementEndDate should simply be EndDate (thinking that we might want to use these fields for more than just announcements at some point in the future). Consequently, I changed the Fields.xml file as follows:&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;xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;1.0&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;utf-8&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; ?&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{11F7E97D-6282-44b1-8222-2E6E377BCDFC}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;EndDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Custom Columns&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;End Date&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{9D1F7E52-EFBF-431e-9331-7DCA31D9CB7A}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;StartDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Custom Columns&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Start Date&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&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;I propagated the changes to the ContentTypes.xml file:&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;xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;1.0&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;utf-8&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; ?&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentType
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D400EF37EB6F40C54a21A3872B1E6CA5BC0A&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Page&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Page is a custom content type ...&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Content Types&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{9D1F7E52-EFBF-431e-9331-7DCA31D9CB7A}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;StartDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{11F7E97D-6282-44b1-8222-2E6E377BCDFC}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;EndDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DocumentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;TargetName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;/_layouts/CreatePage.aspx&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&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;After rebuilding my Web application, adding and deploying the updated WSP, and activating the feature, I discovered that the Announcement Page content type did not have the Start Date and End Date fields.&lt;/P&gt;
&lt;P&gt;Since there were no errors deploying the WSP or activating the feature, I was rather baffled by the issue. Then I discovered that by renaming AnnouncementStartDate to StartDate, I introduced a duplicate field name. Note the following field definition from the OOTB fieldswss.xml file:&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;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{64cd368d-2f95-4bfc-a1f9-8d4324ecb007}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;StartDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;SourceID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/v3&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;StaticName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;StartDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;$Resources:Base_Columns&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;$Resources:core,Start_Date;&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&amp;lt;!--&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; _locID@DisplayName="camlidT6" _locComment=" " &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;--&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Default&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;[today]&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Default&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&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;Similarly, my custom EndDate field conflicted with the OOTB EndDate field.&lt;/P&gt;
&lt;P&gt;My memory might be incorrect, but I vaguely recall getting an error a few years ago when trying to define a second field with the same name as an existing field. Obviously that was long before MOSS 2007 Service Pack 2 (which I am currently running) so it's possible the behavior has changed. [Honestly, while I &lt;EM&gt;could&lt;/EM&gt; try to repro this using the MOSS 2007 RTM version, I'm not going to bother. It would take me about an hour to build out a vanilla MOSS 2007 RTM environment, and that is far longer than I am willing to invest in this issue. It's also possible that I am simply remembering a slightly different issue -- perhaps a duplicate content type name.]&lt;/P&gt;
&lt;P&gt;Regardless of whether this is a new problem, or has been around since the original MOSS 2007 release isn't the point. What is important is that you get no warnings or errors when your custom feature mistakenly attempts to define new StartDate and EndDate fields.&lt;/P&gt;
&lt;P&gt;Once I identified the crux of the issue, I decided to simply rip out my custom StartDate and EndDate fields and instead use the OOTB fields. After all, as my old mantra goes, always try to use something out-of-the-box instead of customization whenever possible.&lt;/P&gt;
&lt;P&gt;In other words, I updated my ContentTypes.xml file to the following:&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;xml&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;1.0&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;encoding&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;utf-8&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; ?&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;xmlns&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentType
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D400EF37EB6F40C54a21A3872B1E6CA5BC0A&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Page&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Announcement Page is a custom content type ...&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam Content Types&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{&lt;SPAN style="COLOR: #0000ff"&gt;64cd368d-2f95-4bfc-a1f9-8d4324ecb007&lt;/SPAN&gt;}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;StartDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{2684F9F2-54BE-429f-BA06-76754FC056BF}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;EndDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;DocumentTemplate&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;TargetName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;/_layouts/CreatePage.aspx&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ContentType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Elements&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;Unfortunately, I then discovered that the OOTB EndDate field does not parallel the definition of the OOTB StartDate field:&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;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{2684F9F2-54BE-429f-BA06-76754FC056BF}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;EndDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;$Resources:core,End_Time;&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;FromBaseType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;TRUE&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;_Hidden&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;SourceID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/v3/fields&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;StaticName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;EndDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &amp;gt;&amp;lt;!--&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;DisplayName=$Resources:camlid3;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;--&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
            &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRef&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{7D95D1F4-F5FD-4a70-90CD-B35ABC9B5BC8}&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;fAllDayEvent&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;RefType&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;AllDayEvent&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
        &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;FieldRefs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Default&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;[today]&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Default&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&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;Notice that with EndDate, &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"&lt;/CODE&gt; whereas with StartDate, &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;"&lt;/CODE&gt;. Also note that the display name (in English - U.S.) is "End Time" -- instead of the expected "End Date". So much for consistency ;-)&lt;/P&gt;
&lt;P&gt;Lastly, note that the OOTB fieldswss.xml also contains the following:&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;Field&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;{8A121252-85A9-443d-8217-A1B57020FADF}&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;_EndDate&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Group&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;$Resources:Base_Columns&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;DisplayName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;$Resources:End_Date&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateTime&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;SourceID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;http://schemas.microsoft.com/sharepoint/v3/fields&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;StaticName&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;_EndDate&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Default&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;[today]&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Default&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Field&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;Unfortunately, this field definition doesn't specify &lt;CODE&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Format&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;DateOnly&lt;/SPAN&gt;" &lt;/CODE&gt;either -- otherwise I would have just used it instead.&lt;/P&gt;
&lt;P&gt;Thus I reverted back to using my original AnnouncementStartDate and AnnouncementEndDate custom fields. It's not ideal, but it works.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9930835" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>Building SharePoint WSPs with Team Foundation Build</title><link>http://blogs.msdn.com/jjameson/archive/2009/11/18/building-sharepoint-wsps-with-team-foundation-build.aspx</link><pubDate>Wed, 18 Nov 2009 13:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9924271</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9924271.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9924271</wfw:commentRss><description>&lt;P&gt;As I noted in my &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/11/18/the-copy-local-bug-in-visual-studio.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/11/18/the-copy-local-bug-in-visual-studio.aspx"&gt;previous post&lt;/A&gt;, I recently discovered that &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/28/sample-walkthrough-of-the-dr-dada-approach-to-sharepoint.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/28/sample-walkthrough-of-the-dr-dada-approach-to-sharepoint.aspx"&gt;my approach for building Web Solution Packages (WSPs)&lt;/A&gt; in Microsoft Office SharePoint Server (MOSS) 2007 isn't compatible with Team Foundation Build.&lt;/P&gt;
&lt;P&gt;I'm actually a little embarrassed to say this, but when I created the original &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 for MOSS 2007&lt;/A&gt; development back on the Agilent Technologies project, we were using Visual SourceSafe -- not Team Foundation Server (TFS) -- and a "manual" build process.&lt;/P&gt;
&lt;P&gt;I'd used VSS and automated builds on other projects before (using NAnt), but never got around to automating our MOSS 2007 builds on the Agilent project because, honestly, there were just too many other higher priority items. Besides, each build only required a couple of minutes of actual human effort because most of the build was scripted.&lt;/P&gt;
&lt;P&gt;Still, an automated daily build (and deployment to DEV) is a &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/26/best-practices-for-scm-and-the-daily-build-process.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/26/best-practices-for-scm-and-the-daily-build-process.aspx"&gt;really, really good thing to have&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I've been fortunate to be on a few projects since then that have leveraged TFS.&lt;/P&gt;
&lt;P&gt;However, up until about a month ago, I hadn't used Team Foundation Build (outside of 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;, of course) due to the fact that we are leveraging the extranet TFS instance hosted by Microsoft.&lt;/P&gt;
&lt;P&gt;Note that Microsoft IT makes it very easy for us to provision new TFS projects on either the extranet or one of several internal TFS instances. Configuring builds using Team Foundation Build on one of the intranet TFS instances is very easy (from what I hear), but I strongly prefer working off the extranet TFS instance because then I don't have to VPN into CorpNet in order to have access to source control.&lt;/P&gt;
&lt;P&gt;However, choosing the extranet TFS instance also means we can't configure builds using the out-of-the-box functionality in Team Foundation Server (at least not without setting up a build server on the extranet). Fortunately, I've found a way to schedule "manual" builds that look a lot like automated builds performed using Team Foundation Build.&lt;/P&gt;
&lt;P&gt;So, if you are building SharePoint WSPs -- regardless of whether you use the real Team Foundation Build or my "imitation Team Foundation Build" -- you need a way to build the WSPs without referring to referenced assemblies using relative paths.&lt;/P&gt;
&lt;P&gt;As I first mentioned in my previous post, relative paths work just fine when compiling from within Visual Studio or using MSBuild from the command line. However, they don't work at all when queuing the builds through Team Foundation Build.&lt;/P&gt;
&lt;P&gt;The problem with relative paths is that Team Foundation Build uses a different folder structure when compiling your projects. Specifically, it changes the output folder for all compiled items to be under a new &lt;STRONG&gt;Binaries &lt;/STRONG&gt;folder -- not the location specified in the project settings within Visual Studio.&lt;/P&gt;
&lt;P&gt;In other words, if you refer to a referenced assembly using something like:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;..\..\..\CoreServices\bin\%BUILD_CONFIGURATION%\Fabrikam.Demo.CoreServices.dll&lt;/BLOCKQUOTE&gt;
&lt;P&gt;then you will find that this works just fine when building through Visual Studio -- or even when compiling using TFSBuild.proj from the command line (a.k.a. a "Desktop Build"). However, if you then queue the build through Team Foundation Server, you'll find your build fails because the referenced assembly was actually output to a different folder.&lt;/P&gt;
&lt;P&gt;If you dive into the log file for the build, you will find that Team Foundation Build modifies the &lt;STRONG&gt;OutDir &lt;/STRONG&gt;variable and sets it to something like:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;C:\Users\svc-build\AppData\Local\Temp\Demo\Daily Build - Main\Binaries\Debug\&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So the trick to building WSPs with Team Foundation Build is to leverage the &lt;STRONG&gt;OutDir &lt;/STRONG&gt;variable instead of relying on relative paths to referenced assemblies.&lt;/P&gt;
&lt;P&gt;Here is the updated DDF file based on &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/28/sample-walkthrough-of-the-dr-dada-approach-to-sharepoint.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/28/sample-walkthrough-of-the-dr-dada-approach-to-sharepoint.aspx"&gt;my earlier sample&lt;/A&gt;:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;;
; This ddf specifies the structure of the .wsp solution cab file.
;
; HACK: OPTION EXPLICIT cannot be used when specifying a variable with the /D option,
; otherwise MakeCAB aborts with an error similar to the following:
;
;        ERROR: Option Explicit and variable not defined: OUT_DIR
;
;.OPTION EXPLICIT    ; Generate errors for undefined variables

.Set CabinetNameTemplate=Fabrikam.Demo.Publishing.wsp

; The following variable must be set when calling MakeCAB (using the /D option)
;.Define OUT_DIR=

.Set DiskDirectoryTemplate=CDROM    ; All cabinets go in a single directory
.Set CompressionType=MSZIP            ; All files are compressed in cabinet files
.Set UniqueFiles=ON
.Set Cabinet=ON
.Set DiskDirectory1=%OUT_DIR%\Package

DeploymentFiles\PackageFiles\manifest.xml

.Set SourceDir=%OUT_DIR%            ; Copy assemblies from %OUT_DIR% folder

Fabrikam.Demo.Publishing.dll
Fabrikam.Demo.CoreServices.dll

.Set SourceDir=                    ; Copy files relative to project folder

.Set DestinationDir=Fabrikam.Demo.Publishing.DefaultSiteConfiguration
DefaultSiteConfiguration\FeatureFiles\Feature.xml

.Set DestinationDir=Fabrikam.Demo.Publishing.Layouts
Layouts\FeatureFiles\Feature.xml
Layouts\FeatureFiles\ProvisionedFiles.xml

.Set DestinationDir=Fabrikam.Demo.Publishing.Layouts\MasterPages
Layouts\MasterPages\FabrikamMinimal.master

;.Set DestinationDir=Fabrikam.Demo.Publishing.Layouts\PageLayouts
;Layouts\PageLayouts\MinimalPage.aspx

.Set DestinationDir=Fabrikam.Demo.Publishing.Layouts\Images
Layouts\Images\FabrikamLogo_32x32.png

.Set DestinationDir=Fabrikam.Demo.Publishing.Layouts\Themes\Theme1
Layouts\Themes\Theme1\BreadcrumbBullet.gif
Layouts\Themes\Theme1\FauxColumn-Fixed-2Col.png
Layouts\Themes\Theme1\FauxColumn-Fixed-3Col.png
Layouts\Themes\Theme1\Fabrikam-Basic.css
Layouts\Themes\Theme1\Fabrikam-Core.css
Layouts\Themes\Theme1\Fabrikam-FixedLayout.css
Layouts\Themes\Theme1\Fabrikam-IE.css
Layouts\Themes\Theme1\Fabrikam-IE6.css
Layouts\Themes\Theme1\Fabrikam-QuirksMode.css
Layouts\Themes\Theme1\Tab-LeftSide.jpg
Layouts\Themes\Theme1\Tab-RightSide.jpg

.Set DestinationDir=ControlTemplates\Fabrikam\Demo\Publishing\Layouts
Layouts\Web\UI\WebControls\GlobalNavigation.ascx
Layouts\Web\UI\WebControls\StyleDeclarations.ascx

.Set DestinationDir=Layouts\Fabrikam
Layouts\MasterPages\FabrikamMinimal.master&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Note how I've replaced the BUILD_CONFIGURATION variable with the OUT_DIR variable. Not surprisingly, the OUT_DIR variable in the DDF is specified similar to how BUILD_CONFIGURATION was previously specified when calling makecab.exe. However, unlike the build configuration the OutDir variable will likely contain spaces as well as a trailing slash (which makecab.exe apparently doesn't like). Therefore we must quote the OutDir variable and append with "." if a trailing slash is found.&lt;/P&gt;
&lt;P&gt;Here is the corresponding update to the project file:&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;PropertyGroup&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;BuildDependsOn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&lt;/SPAN&gt;      $(BuildDependsOn);
      CreateSharePointSolutionPackage
&lt;SPAN style="COLOR: #0000ff"&gt;    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;BuildDependsOn&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;QuotedOutDir&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;"$(OutDir)"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;QuotedOutDir&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;QuotedOutDir&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Condition&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;HasTrailingSlash($(OutDir))&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;"$(OutDir)."&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;QuotedOutDir&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;PropertyGroup&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Target&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;CreateSharePointSolutionPackage&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Inputs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;@(None);@(Content);$(OutDir)$(TargetFileName);&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Outputs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;$(ProjectDir)$(OutDir)Package\Fabrikam.Demo.Publishing.wsp&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Message&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Creating SharePoint solution package...&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Exec&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Command&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;makecab /D OUT_DIR=$(QuotedOutDir) /F &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;&amp;amp;quot;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;$(ProjectDir)DeploymentFiles\PackageFiles\wsp_structure.ddf&lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;&amp;amp;quot;&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Target&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;With these changes, the SharePoint WSP is successfully built regardless of whether it is compiled through Visual Studio, from the command line using MSBuild and the TFSBuild.proj file, or as an automated build using a Team Foundation Build server.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9924271" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx">My System</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/Simplify/default.aspx">Simplify</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/TFS/default.aspx">TFS</category></item><item><title>The "Copy Local" Bug in Visual Studio</title><link>http://blogs.msdn.com/jjameson/archive/2009/11/18/the-copy-local-bug-in-visual-studio.aspx</link><pubDate>Wed, 18 Nov 2009 12:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9924246</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9924246.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9924246</wfw:commentRss><description>&lt;P&gt;If you've ever worked with me on a Microsoft Office SharePoint Server (MOSS) 2007 project -- or if you've read my &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/09/28/sample-walkthrough-of-the-dr-dada-approach-to-sharepoint.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/09/28/sample-walkthrough-of-the-dr-dada-approach-to-sharepoint.aspx"&gt;Sample Walkthrough of the DR.DADA Approach to SharePoint&lt;/A&gt; -- then you've probably seen the following comment:&lt;/P&gt;
&lt;BLOCKQUOTE class=directQuote&gt;
&lt;P&gt;Note: Referenced assemblies must be specified with a path corresponding to the build configuration. If the path is not specified to the referenced assembly, then the build works fine as long as the referenced assembly is not in the GAC.&lt;/P&gt;
&lt;P&gt;However, when the referenced assembly is in the GAC (i.e. after a deployment) then MakeCAB will not be able to find the referenced assembly (since it is no longer copied to the current project's bin\Debug or bin\Release folder).&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It turns out that I was using a rather elaborate workaround for a problem that is actually much easier to solve.&lt;/P&gt;
&lt;P&gt;To workaround the "Copy Local" bug and force a referenced assembly to always be copied to the output folder (regardless of whether the referenced assembly is in the GAC):&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Solution Explorer &lt;/STRONG&gt;window in Visual Studio, expand the &lt;STRONG&gt;References&lt;/STRONG&gt; folder for the project and then select the referenced assembly.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Properties &lt;/STRONG&gt;window, change the value of &lt;STRONG&gt;Copy Local &lt;/STRONG&gt;to &lt;STRONG&gt;False&lt;/STRONG&gt;, and then change it back to &lt;STRONG&gt;True&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Following these two simple steps explicitly adds &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;True&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt; to the project file, as shown in the following example:&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;ProjectReference&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;Include&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;..\CoreServices\CoreServices.csproj&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Project&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;{01C58D27-9818-45D6-A0B6-8EF765CA9397}&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Project&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;CoreServices %28CoreServices\CoreServices%29&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;True&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;ProjectReference&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;When you add a referenced assembly in Visual Studio using a project reference, &lt;STRONG&gt;Copy Local &lt;/STRONG&gt;defaults to &lt;STRONG&gt;True&lt;/STRONG&gt;, but Visual Studio doesn't explicitly state this in the MSBuild project file. Toggling the value of &lt;STRONG&gt;Copy Local &lt;/STRONG&gt;forces this element to be added to the project file and consequently you no longer need any hacks to reference the assembly in its original output folder.&lt;/P&gt;
&lt;P&gt;At this point, you might be wondering why do I bring this up after all this time? After all, hasn't the hack I came up with for building SharePoint Web Solution Packages (WSPs) been working for several years? Well, yes, in most cases it works just fine.&lt;/P&gt;
&lt;P&gt;However, there's one fundamental problem that I only recently discovered back in early October: you can't use Team Foundation Build to build the WSP when specifying relative paths to assemblies in the DDF file.&lt;/P&gt;
&lt;P&gt;I'll cover this in &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/11/18/building-sharepoint-wsps-with-team-foundation-build.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/11/18/building-sharepoint-wsps-with-team-foundation-build.aspx"&gt;my next post&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9924246" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/Core+Development/default.aspx">Core Development</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item><item><title>SharePoint Web Part to Redirect from HTTP to HTTPS</title><link>http://blogs.msdn.com/jjameson/archive/2009/11/10/sharepoint-web-part-to-redirect-from-http-to-https.aspx</link><pubDate>Tue, 10 Nov 2009 13:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9920123</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9920123.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9920123</wfw:commentRss><description>&lt;P&gt;Yesterday, I detailed the &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/11/09/configuring-ssl-on-sharepoint-sites.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/11/09/configuring-ssl-on-sharepoint-sites.aspx"&gt;steps I recommend for configuring SSL&lt;/A&gt; on sites built on Microsoft Office SharePoint Server (MOSS) 2007. I also mentioned that users won't automatically be redirected from HTTP to HTTPS, and how I've previously used a little bit of code to automatically perform this redirection.&lt;/P&gt;
&lt;P&gt;Here is a base class that contains the core logic for detecting when a redirect from HTTP to HTTPS is required and automatically redirecting as necessary:&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.Text;
&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.WebParts;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint.WebControls;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.CoreServices.Logging;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.Web.Properties;

&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Demo.Web.UI.WebControls
{
    &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; Base class for Web Parts that require secure communication (i.e. HTTPS).
&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: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;abstract&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SslRequiredWebPart&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #2b91af"&gt;WebPart
&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; Redirect from HTTP to HTTPS (if required).
&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="e"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;An &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;see cref="System.EventArgs" /&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; object that
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; contains the event data.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;override&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; OnInit(
            &lt;SPAN style="COLOR: #2b91af"&gt;EventArgs&lt;/SPAN&gt; e)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;base&lt;/SPAN&gt;.OnInit(e);

            &lt;SPAN style="COLOR: #2b91af"&gt;HttpContext&lt;/SPAN&gt; context = &lt;SPAN style="COLOR: #2b91af"&gt;HttpContext&lt;/SPAN&gt;.Current;

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (context == &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;"HttpContext.Current is null."&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;HttpContextWrapper&lt;/SPAN&gt; contextWrapper = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;HttpContextWrapper&lt;/SPAN&gt;(context);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; forceRedirect = IsSslRedirectRequired(contextWrapper);
            
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (forceRedirect == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;HttpRequest&lt;/SPAN&gt; request = context.Request;

            &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;"SslRequiredWebPart - Redirecting from HTTP to HTTPS"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;" for URL ({0})..."&lt;/SPAN&gt;,
                request.RawUrl);

            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(request.RawUrl.StartsWith(
                &lt;SPAN style="COLOR: #a31515"&gt;"/"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #2b91af"&gt;StringBuilder&lt;/SPAN&gt; urlBuilder = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;StringBuilder&lt;/SPAN&gt;();

            urlBuilder.Append(&lt;SPAN style="COLOR: #2b91af"&gt;Uri&lt;/SPAN&gt;.UriSchemeHttps);
            urlBuilder.Append(&lt;SPAN style="COLOR: #2b91af"&gt;Uri&lt;/SPAN&gt;.SchemeDelimiter);
            urlBuilder.Append(request.Url.Host);
            urlBuilder.Append(request.RawUrl);

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; redirectUrl = urlBuilder.ToString();

            &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;"SslRequiredWebPart - Redirecting to URL ({0})..."&lt;/SPAN&gt;,
                redirectUrl);

            context.Response.Redirect(redirectUrl, &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);
            context.ApplicationInstance.CompleteRequest();
        }

        &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; Determines if an SSL redirect is required.
&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="context"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;Context information representing an individual
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; HTTP request.&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;&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 a redirect from HTTP to HTTPS is required,
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; otherwise &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;.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/returns&amp;gt;
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;protected&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;virtual&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; IsSslRedirectRequired(
            &lt;SPAN style="COLOR: #2b91af"&gt;HttpContextBase&lt;/SPAN&gt; context)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (context == &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;"context"&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;"SslRequiredWebPart - RedirectToHttpsWhenSslRequired = {0}"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #2b91af"&gt;Settings&lt;/SPAN&gt;.Default.RedirectToHttpsWhenSslRequired);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;Settings&lt;/SPAN&gt;.Default.RedirectToHttpsWhenSslRequired == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;HttpRequestBase&lt;/SPAN&gt; request = context.Request;

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (request.IsSecureConnection == &lt;SPAN style="COLOR: #0000ff"&gt;true&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;"SslRequiredWebPart - The connection is secure."&lt;/SPAN&gt;,
                   request.RawUrl);

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (request.Url.Host.Contains(&lt;SPAN style="COLOR: #a31515"&gt;"."&lt;/SPAN&gt;) == &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;"SslRequiredWebPart - The hostname is not a fully-qualified"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" domain name."&lt;/SPAN&gt;);

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (request.Url.Host.Contains(&lt;SPAN style="COLOR: #a31515"&gt;"-local."&lt;/SPAN&gt;) == &lt;SPAN style="COLOR: #0000ff"&gt;true
&lt;/SPAN&gt;                || request.Url.Host.Contains(&lt;SPAN style="COLOR: #a31515"&gt;"-dev."&lt;/SPAN&gt;) == &lt;SPAN style="COLOR: #0000ff"&gt;true&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;"SslRequiredWebPart - LOCAL or DEV environment detected."&lt;/SPAN&gt;);

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&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: #2b91af"&gt;SPControlMode&lt;/SPAN&gt; formMode = &lt;SPAN style="COLOR: #2b91af"&gt;SPContext&lt;/SPAN&gt;.Current.FormContext.FormMode;

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (formMode == &lt;SPAN style="COLOR: #2b91af"&gt;SPControlMode&lt;/SPAN&gt;.Edit
                    || formMode == &lt;SPAN style="COLOR: #2b91af"&gt;SPControlMode&lt;/SPAN&gt;.New)
                {
                    &lt;SPAN style="COLOR: #008000"&gt;// Never redirect when editing a page                
&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;"SslRequiredWebPart - SSL redirect is not required"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" because the page is being edited."&lt;/SPAN&gt;);

                    &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
                }
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Using this approach, users can browse the anonymous areas of your site using HTTP. However, as soon as they browse to a page that contains a Web Part that requires secure communication, they are automatically redirected from HTTP to HTTPS.&lt;/P&gt;
&lt;P&gt;Note how I use a custom application setting (&lt;CODE&gt;RedirectToHttpsWhenSslRequired&lt;/CODE&gt;) to allow this feature to be turned off. The default value is &lt;CODE&gt;True&lt;/CODE&gt; (meaning the feature is turned on). However, by changing the property setting to &lt;CODE&gt;False&lt;/CODE&gt; in the Web.config file, the feature can be disabled as necessary for a particular environment or server (for troubleshooting purposes):&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;configuration&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;configSections&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;sectionGroup&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #ff0000"&gt;      name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;applicationSettings&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;
      &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;section&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Fabrikam.Demo.Web.Properties.Settings&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;type&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&lt;/SPAN&gt;"
&lt;SPAN style="COLOR: #0000ff"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;requirePermission&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; /&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;sectionGroup&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;configSections&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;applicationSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;Fabrikam.Demo.Web.Properties.Settings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;setting&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;RedirectToHttpsWhenSslRequired&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;serializeAs&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;String&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;False&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;setting&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
    &amp;lt;/&lt;SPAN style="COLOR: #a31515"&gt;Fabrikam.Demo&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;.Web.Properties.Settings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;applicationSettings&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;configuration&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;Also note that there are several scenarios in which a redirect is avoided:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When the connection is already secure (well, duh...we obviously don't want to cause an endless redirect loop)&lt;/LI&gt;
&lt;LI&gt;When the request URL does not specify a fully qualified domain name, but rather an intranet URL (e.g. http://fabrikam). In this scenario, user are expected to be authenticated using Windows Authentication, which does not send credentials in clear text and therefore does not require SSL.&lt;/LI&gt;
&lt;LI&gt;In LOCAL developer environments (e.g. http://www-local.fabrikam.com) and the Development Integration environment (DEV) -- e.g. http://www-dev.fabrikam.com -- since these environments don't typically have SSL certificates installed. This is an example of why a standard &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/06/09/environment-naming-conventions.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/06/09/environment-naming-conventions.aspx"&gt;environment naming convention&lt;/A&gt; is important.&lt;/LI&gt;
&lt;LI&gt;When the page where the Web Part resides is being edited (because we don't want to force a redirect immediately after someone adds the Web Part to a page). This scenario is not expected to occur, since content managers will typically use the intranet URL (e.g. http://fabrikam) for creating and editing pages. However, it is covered just in case the scenario is ever encountered.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Assuming the &lt;CODE&gt;IsSslRedirectRequired&lt;/CODE&gt; method returns &lt;CODE&gt;true&lt;/CODE&gt;, the Web Part redirects to an HTTPS connection while preserving all of the query string parameters specified in the original request. Note that this simple approach only supports an HTTP GET on the original request. In other words, HTTP POST requests are "not supported" (however they are not expected to occur either). This is because any form parameters specified in the body of an HTTP POST request would be dropped in the redirect.&lt;/P&gt;
&lt;P&gt;Similar code can also be used in a page (e.g. /_layouts/Fabrikam/Login.aspx) if you prefer that approach instead of creating some kind of "Login" Web Part.&lt;/P&gt;
&lt;P&gt;Lastly, note that I allow the &lt;CODE&gt;IsSslRedirectRequired&lt;/CODE&gt; method to be overridden in Web Parts that inherit from &lt;CODE&gt;SslRequiredWebPart&lt;/CODE&gt; (e.g. &lt;CODE&gt;LoginFormWebPart&lt;/CODE&gt;). I haven't yet found this to be necessary, but it's there just in case.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9920123" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>Configuring SSL on SharePoint Sites</title><link>http://blogs.msdn.com/jjameson/archive/2009/11/09/configuring-ssl-on-sharepoint-sites.aspx</link><pubDate>Mon, 09 Nov 2009 15:24:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9919556</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9919556.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9919556</wfw:commentRss><description>&lt;P&gt;If you are using Basic Authentication or Forms-Based Authentication (FBA) with Microsoft Office SharePoint Server (MOSS) 2007 -- or any Web site, for that matter -- then you must configure secure communication (HTTPS) using SSL certificates.&lt;/P&gt;
&lt;P&gt;However, you probably didn't select to enable SSL when you originally created your Web application (after all, you most likely don't want to use Basic Auth or FBA exclusively, but rather only for users accessing the site externally). If you followed the process I recommend for customers deploying MOSS solutions, you created the Web application using an intranet URL (e.g. &lt;A href="http://fabrikam/" mce_href="http://fabrikam"&gt;http://fabrikam&lt;/A&gt;) and subsequently extended the Web application to the &lt;STRONG&gt;Internet&lt;/STRONG&gt; zone (e.g. &lt;A href="http://www.fabrikam.com/" mce_href="http://www.fabrikam.com"&gt;http://www.fabrikam.com&lt;/A&gt;) or &lt;STRONG&gt;Extranet&lt;/STRONG&gt; zone (e.g. &lt;A href="http://extranet.fabrikam.com/" mce_href="http://extranet.fabrikam.com"&gt;http://extranet.fabrikam.com&lt;/A&gt;) -- utilizing the SharePoint alternate access mappings feature.&lt;/P&gt;
&lt;P&gt;Now that you need to enable secure communication, you might once again consider extending the Web application -- say to the &lt;STRONG&gt;Custom&lt;/STRONG&gt; zone -- and select the option to use SSL (e.g. &lt;A href="https://www.fabrikam.com/" mce_href="https://www.fabrikam.com"&gt;https://www.fabrikam.com&lt;/A&gt;). After all, this is the recommendation in the following TechNet article:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;Update a Web application URL and IIS bindings (Windows SharePoint Services). (Updated 2009-04-23).&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="http://technet.microsoft.com/en-us/library/cc298636.aspx" mce_href="http://technet.microsoft.com/en-us/library/cc298636.aspx"&gt;http://technet.microsoft.com/en-us/library/cc298636.aspx&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Specifically, here is the text that I am referring to:&lt;/P&gt;
&lt;BLOCKQUOTE class=directQuote&gt;We do not recommend reusing the same IIS Web site for your HTTP and SSL hosting. Instead, extend a dedicated HTTP and a dedicated SSL Web site, each assigned to its own alternate access mapping zone and URLs.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Wait a minute...let me see if I've got this right...you want me to extend my Web application -- thereby creating yet another copy of my Web.config files -- just to enable SSL? That doesn't seem like a good idea.&lt;/P&gt;
&lt;P&gt;After all, managing the multitude of Web.config files across multiple Web application and Web servers in a farm seems to be one of the most challenging aspects for the Release Management and Operations teams (at least in my experience during the past several years). [I can't tell you how many times I've compared Web.config files during the process of troubleshooting various issues and found discrepancies due to manual changes not getting applied consistently. Sure, the risk of this is drastically reduced if you leverage the &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebconfigmodification.aspx"&gt;&lt;CODE&gt;SPWebConfigModification&lt;/CODE&gt;&lt;/A&gt; infrastructure, but there are still rare occasions when a little manual "tweaking" is necessary -- and these often lead to inconsistent Web.config files.]&lt;/P&gt;
&lt;P&gt;Therefore, one of my goals with any SharePoint solution is to minimize the number of Web.config files that are used. It seems reasonable to expect two different Web.config files to be used for a site that uses Windows Authentication internally and Forms Authentication externally, since this is configured using the &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;authentication&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt; element.&lt;/P&gt;
&lt;P&gt;For example, in the &lt;STRONG&gt;Default&lt;/STRONG&gt; zone you probably want to specify:&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;authentication&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;mode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Windows&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;Whereas in the &lt;STRONG&gt;Internet&lt;/STRONG&gt; zone you instead need something like this:&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;authentication&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;mode&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;Forms&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;forms&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;loginUrl&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt;/Public/Pages/default.aspx&lt;/SPAN&gt;"&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;defaultUrl&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;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;authentication&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;Okay, so if we want to avoid creating a new Web application -- and the corresponding Web.config file(s) -- how can we support both HTTP and HTTPS on the same Web application? It turns out to be rather simple.&lt;/P&gt;
&lt;P&gt;For a starting point, let's assume you've just created your Web application using the default (i.e. intranet) URL -- say, &lt;A href="http://fabrikam/" mce_href="http://fabrikam"&gt;http://fabrikam&lt;/A&gt; -- which uses Windows Authentication. This is the site that your content authors will use to manage the site.&lt;/P&gt;
&lt;P&gt;The first step is to create an alternate access mapping (AAM).&lt;/P&gt;
&lt;P&gt;To configure an alternate access mapping:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;On the SharePoint Central Administration home page, click the &lt;STRONG&gt;Application Management &lt;/STRONG&gt;tab on the top link bar.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;On the &lt;STRONG&gt;Application Management &lt;/STRONG&gt;page, in the &lt;STRONG&gt;SharePoint Web Application Management &lt;/STRONG&gt;section, click &lt;STRONG&gt;Create or extend Web application&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;On the &lt;STRONG&gt;Create or Extend Web Application &lt;/STRONG&gt;page, in the &lt;STRONG&gt;Adding a SharePoint Web Application &lt;/STRONG&gt;section, click &lt;STRONG&gt;Extend an existing Web application&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;On the &lt;STRONG&gt;Extend Web Application to Another IIS Web Site &lt;/STRONG&gt;page: 
&lt;OL&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Web Application &lt;/STRONG&gt;section, select the Web application to extend (e.g. &lt;A href="http://fabrikam/" mce_href="http://fabrikam"&gt;http://fabrikam&lt;/A&gt;).&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;IIS Web Site &lt;/STRONG&gt;section, in the &lt;STRONG&gt;Port &lt;/STRONG&gt;and &lt;STRONG&gt;Host Header &lt;/STRONG&gt;boxes, enter the corresponding values such as &lt;STRONG&gt;80 &lt;/STRONG&gt;and &lt;STRONG&gt;www.fabrikam.com&lt;/STRONG&gt;, respectively.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Security Configuration &lt;/STRONG&gt;section, keep the default options (you can configure forms authentication, anonymous access, and SSL later).&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Load Balanced URL &lt;/STRONG&gt;section, ensure the default value specified in the &lt;STRONG&gt;URL &lt;/STRONG&gt;box is correct (e.g. &lt;STRONG&gt;http://www.fabrikam.com:80&lt;/STRONG&gt;) and in &lt;STRONG&gt;Zone &lt;/STRONG&gt;dropdown list, select &lt;STRONG&gt;Internet&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;OK&lt;/STRONG&gt;.&lt;BR&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The next step is to install your SSL certificate on the site. Once you've procured your certificate and installed it through Internet Information Services (IIS) Manager, you then need to add a public URL in SharePoint for HTTPS and add an HTTPS binding in IIS.&lt;/P&gt;
&lt;P&gt;To add a public URL to HTTPS:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&amp;nbsp;On the SharePoint Central Administration home page, click the &lt;STRONG&gt;Operations&lt;/STRONG&gt; tab on the top link bar.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;On the &lt;STRONG&gt;Operations&lt;/STRONG&gt; page, in the &lt;STRONG&gt;Global Configuration &lt;/STRONG&gt;section, click &lt;STRONG&gt;Alternate access mappings&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;On the &lt;STRONG&gt;Alternate Access Mappings&lt;/STRONG&gt; page, click &lt;STRONG&gt;Edit Public URLs&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;&amp;nbsp;On the &lt;STRONG&gt;Edit Public Zone URLs&lt;/STRONG&gt; page: 
&lt;OL&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Alternate Access Mapping Collection&lt;/STRONG&gt; section, select the Web application (e.g. &lt;A href="http://fabrikam/" mce_href="http://fabrikam"&gt;http://fabrikam&lt;/A&gt;).&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Public URLs &lt;/STRONG&gt;section, copy the URL from the &lt;STRONG&gt;Internet &lt;/STRONG&gt;box to the &lt;STRONG&gt;Custom &lt;/STRONG&gt;box, and change &lt;STRONG&gt;http://&lt;/STRONG&gt; to &lt;STRONG&gt;https://&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;Save&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;To add an HTTPS binding to the site in IIS:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Click &lt;STRONG&gt;Start&lt;/STRONG&gt;, point to &lt;STRONG&gt;Administrative Tools&lt;/STRONG&gt;, and then click &lt;STRONG&gt;Internet Information Services (IIS) Manager&lt;/STRONG&gt;. &lt;/LI&gt;
&lt;LI&gt;In Internet Information Services (IIS) Manager, click the plus sign (+) next to the server name that contains the Web application, and then click the plus sign next to &lt;STRONG&gt;Sites&lt;/STRONG&gt; to view the Web applications that have been created. &lt;/LI&gt;
&lt;LI&gt;Click the name of the Web application corresponding to the &lt;STRONG&gt;Internet&lt;/STRONG&gt; zone (e.g. &lt;STRONG&gt;SharePoint – www.fabrikam.com80&lt;/STRONG&gt;). In the &lt;STRONG&gt;Actions&lt;/STRONG&gt; section, under the &lt;STRONG&gt;Edit Site &lt;/STRONG&gt;heading, click &lt;STRONG&gt;Bindings…&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Site Bindings &lt;/STRONG&gt;window, click &lt;STRONG&gt;Add&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Add Site Binding &lt;/STRONG&gt;window: 
&lt;OL&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Type:&lt;/STRONG&gt; dropdown, select &lt;STRONG&gt;https&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;SSL Certificate:&lt;/STRONG&gt; dropdown, select the certificate corresponding to the site (e.g. www.fabrikam.com).&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;OK&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Site Bindings &lt;/STRONG&gt;window, click &lt;STRONG&gt;Close&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;At this point, your SharePoint site supports Windows Authentication both internally (via &lt;A href="http://fabrikam/" mce_href="http://fabrikam"&gt;http://fabrikam&lt;/A&gt;) and externally (via &lt;A href="http://www.fabrikam.com/" mce_href="http://www.fabrikam.com"&gt;http://www.fabrikam.com&lt;/A&gt; and &lt;A href="https://www.fabrikam.com/" mce_href="https://www.fabrikam.com"&gt;https://www.fabrikam.com&lt;/A&gt;). The final steps are to enable anonymous access and configure Forms Authentication.&lt;/P&gt;
&lt;P&gt;Note that after configuring Forms Authentication, users will not automatically be redirected from HTTP to HTTPS for the login page. To achieve this user experience, I've used a couple of techniques in the past that are based on the same fundmental concept. The first technique utilized code on the login page to automatically detect HTTP connections and redirect to HTTPS. The second technique was essentially the same logic, but rather than utilizing code embedded in the login page, it is encapsulated in a Login Form Web Part. I'll discuss this redirect code in a follow-up post.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9919556" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category></item><item><title>AutoEventWireup Issue in MOSS 2007</title><link>http://blogs.msdn.com/jjameson/archive/2009/11/08/autoeventwireup-issue-in-moss-2007.aspx</link><pubDate>Mon, 09 Nov 2009 02:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8570172</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/8570172.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=8570172</wfw:commentRss><description>&lt;P&gt;I &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/11/02/analyzing-my-msdn-blog.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/11/02/analyzing-my-msdn-blog.aspx"&gt;recently promised&lt;/A&gt; to finish this blog post that has been sitting in "unpublished" status since June 2008, so here it is...&lt;/P&gt;
&lt;P&gt;Have you ever encountered the following error in Microsoft Office SharePoint Server (MOSS) 2007?&lt;/P&gt;
&lt;BLOCKQUOTE class="directQuote errorMessage"&gt;An error occurred during the processing of . The attribute 'autoeventwireup' is not allowed in this page.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I just &lt;A href="http://www.bing.com/search?q=SharePoint+%22AutoEventWireup+is+not+allowed%22&amp;amp;form=QBRE&amp;amp;qs=n" mce_href="http://www.bing.com/search?q=SharePoint+%22AutoEventWireup+is+not+allowed%22&amp;amp;form=QBRE&amp;amp;qs=n"&gt;searched for this&lt;/A&gt; using Bing and it seems like I'm not the only one who has ever experienced this issue. However, glancing through a few of the top search results, I didn't see any solutions to the error.&lt;/P&gt;
&lt;P&gt;The problem occurs when you have a custom master page which includes code and that master page subsequently becomes unghosted. I believe this happens with custom page layouts that are customized as well.&lt;/P&gt;
&lt;P&gt;I have to admit that I was completely stumped when I first encountered this error a few years ago while working on the Agilent Technologies project. I eventually tracked down the root cause to be unghosted pages, but we were not using SharePoint Designer to create or customize our master pages, so I couldn't understand why we would occasionally encounter this error.&lt;/P&gt;
&lt;P&gt;My speculation is that when the feature/solution containing the custom master page is deactivated, retracted, and deleted (as part of 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" process&lt;/A&gt;), SharePoint has some "smarts" within it that essentially equates to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Hey, this master page (or page layout) is currently in use so removing it could really break the site.&lt;/LI&gt;
&lt;LI&gt;Therefore, I'd better make a copy of it and store it in the database (i.e. unghost it).&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Unfortunately, when we subsequently added, deployed, and activated the solution/feature, SharePoint would still attempt to use the unghosted master page and summarily generate the error stating that "the attribute 'autoeventwireup' is not allowed in this page."&lt;/P&gt;
&lt;P&gt;Note that this is pure speculation on my part as to what was causing the master page to become unghosted.&lt;/P&gt;
&lt;P&gt;However, what I do know for sure is that once I reghosted the master page, the AutoEventWireup error would magically disappear.&lt;/P&gt;
&lt;P&gt;Here are the steps to reghost a master page or page layout:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Browse to &lt;STRONG&gt;Site Settings&lt;/STRONG&gt; page for your site. Note that if your master page is causing the AutoEventWireup error, you can explicitly specify the URL (e.g. http://fabrikam/_layouts/settings.aspx).&lt;/LI&gt;
&lt;LI&gt;On the &lt;STRONG&gt;Site Settings &lt;/STRONG&gt;page, under the &lt;STRONG&gt;Look and Feel &lt;/STRONG&gt;section, click &lt;STRONG&gt;Reset to site definition&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;On the &lt;STRONG&gt;Reset Page to Site Definition Version&lt;/STRONG&gt; page: 
&lt;OL&gt;
&lt;LI&gt;In the &lt;STRONG&gt;Reset to Site Definition &lt;/STRONG&gt;section, ensure the option to &lt;LABEL for=ctl00_PlaceHolderMain_ctl00_ResetOnePage&gt;&lt;STRONG&gt;Reset specific page to site definition version&lt;/STRONG&gt; is selected, and then in t&lt;/LABEL&gt;he &lt;STRONG&gt;Local URL of the page &lt;/STRONG&gt;box, &lt;LABEL for=ctl00_PlaceHolderMain_ctl00_ResetOnePage&gt;typtype the URL of the master page or page layout that you want reset (e.g. http://fabrikam/_catalogs/masterpage/FabrikamMinimal.master).&lt;/LABEL&gt;&lt;/LI&gt;
&lt;LI&gt;Click &lt;STRONG&gt;Reset&lt;/STRONG&gt;.&lt;/LI&gt;
&lt;LI&gt;In the confirmation dialog that appears stating that you will lose all customizations, including web part zones, custom controls, and in-line text, click &lt;STRONG&gt;OK&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Note that in ASP.NET, the default value for the &lt;A href="http://support.microsoft.com/kb/814745" mce_href="http://support.microsoft.com/kb/814745"&gt;&lt;CODE&gt;AutoEventWireup&lt;/CODE&gt;&lt;/A&gt; attribute is true. Therefore you might assume that you could simply remove the attribute from your custom master page in order to avoid the error when the master page is unghosted. After all, the error clearly states that the &lt;CODE&gt;AutoEventWireup&lt;/CODE&gt; attribute is not allowed in this page, right?&lt;/P&gt;
&lt;P&gt;In other words, the solution to the problem would seem to be simply be a matter of changing something like 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;Master&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;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Codebehind&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FabrikamMinimal.master.cs"
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #ff0000"&gt;Inherits&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Fabrikam.Demo.Publishing.Layouts.MasterPages.FabrikamMinimal"&lt;/SPAN&gt; %&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;...to 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;Master&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;Codebehind&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="FabrikamMinimal.master.cs"
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #ff0000"&gt;Inherits&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Fabrikam.Demo.Publishing.Layouts.MasterPages.FabrikamMinimal"&lt;/SPAN&gt; %&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Unfortunately -- at least in my experience -- this doesn't work. It only leads to other errors, such as:&lt;/P&gt;
&lt;BLOCKQUOTE class="directQuote errorMessage"&gt;The event handler 'OnPreRender' is not allowed in this page. &lt;/BLOCKQUOTE&gt;
&lt;P&gt;The above error occurs when the master page contains something like the following:&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;SiteMapPath&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;ID&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="BreadcrumbSiteMapPath"&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;SiteMapProvider&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="CurrentNavSiteMapProviderNoEncode"
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #ff0000"&gt;RenderCurrentNodeAsLink&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="true"
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #ff0000"&gt;SkipLinkText&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;=""
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #ff0000"&gt;OnPreRender&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="BreadcrumbSiteMapPath_OnPreRender"&amp;gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;I attempted to resolve this by converting the &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;BreadcrumbSiteMapPath_OnPreRender&lt;/SPAN&gt;&lt;/CODE&gt; event handler to a method and invoking the method from the &lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;Page_PreRender&lt;/SPAN&gt;&lt;/CODE&gt; event handler instead. However, that only led to yet another error:&lt;/P&gt;
&lt;BLOCKQUOTE class="directQuote errorMessage"&gt;Code blocks are not allowed in this file.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sensing a very deep "rat hole" at this point, I decided it wasn't worth pursuing this issue any further.&lt;/P&gt;
&lt;P&gt;Fortunately, as I've stated before, I don't believe master pages and page layouts deployed through solutions and features should subsequently be customized through SharePoint Designer. In my opinion, these items should be tightly managed through your SCM (software configuration management) process -- in other words, versioned in your source control system and subsequently deployed through a formal change process.&lt;/P&gt;
&lt;P&gt;Of course, if your custom master pages and page layouts are very simple (i.e. no code-behind) then you probably will never encounter this problem.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8570172" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>Supportability Concerns with Custom HTTP Modules in SharePoint</title><link>http://blogs.msdn.com/jjameson/archive/2009/11/07/supportability-concerns-with-custom-http-modules-in-sharepoint.aspx</link><pubDate>Sat, 07 Nov 2009 13:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9919050</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9919050.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9919050</wfw:commentRss><description>&lt;P&gt;I am sure that I'm not the first one to tell you this, but you can't believe everything you read on the Internet these days ;-)&lt;/P&gt;
&lt;P&gt;Case in point...I've seen a number of sources claim that custom HTTP modules are not supported in Microsoft Office SharePoint Server (MOSS) 2007 and Windows SharePoint Services (WSS) v3.&lt;/P&gt;
&lt;P&gt;These statements make it sound like if you add your own custom processing to the pipeline of each page request, you will instantly teleport your Production SharePoint farm into that vast wasteland we generally refer to as "Unsupported" -- where your support calls to Microsoft will be summarily terminated shortly after getting your Service Request (SRX) number.&lt;/P&gt;
&lt;P&gt;Not so -- at least in this particular case.&lt;/P&gt;
&lt;P&gt;Thank goodness, at least for my sake, because I've worked on a number of MCS (Microsoft Consulting Services) projects where we've delivered custom HTTP modules. It's always a little scary that something we deliver as part of an MCS engagement will later be deemed "unsupported."&lt;/P&gt;
&lt;P&gt;In general, we are very good about knowing what is -- and is not -- supported, but there's always a chance that something "creative" we do in order to satisfy the business requirements for our customers will later be considered a problem by Microsoft Customer Service and Support (CSS).&lt;/P&gt;
&lt;P&gt;There are, in fact, lots of things you can do with SharePoint that will thrust you into the dreaded "unsupported" category, but a custom HTTP module isn't one of them.&lt;/P&gt;
&lt;P&gt;How can I say this with such conviction? Well, yesterday I came across the following on MSDN:&lt;/P&gt;
&lt;BLOCKQUOTE class=directQuote&gt;
&lt;H4&gt;Support Details&lt;/H4&gt;
&lt;P&gt;A HTTP module assembly can be installed in the Web application’s \bin directory or in the global assembly cache.&lt;/P&gt;
&lt;P&gt;Because an HTTP module is always called as part of the page processing pipeline, a poorly designed or faulty module can have a detrimental effect on performance or perceived stability of the environment. Thoroughly test each module for performance before deploying it.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want to see it for yourself, you can go straight to the source:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;HTTP Module&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb862635.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb862635.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb862635.aspx&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Obviously you want to be very cautious about using custom HTTP modules, but there are definitely scenarios where this is a good approach.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9919050" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>Introducing the SharePointSmtpHelper Class</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/18/introducing-the-sharepointsmtphelper-class.aspx</link><pubDate>Sun, 18 Oct 2009 14:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9908769</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9908769.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9908769</wfw:commentRss><description>&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;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx">My System</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>Introducing the SharePointWebPartHelper Class</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/17/introducing-the-sharepointwebparthelper-class.aspx</link><pubDate>Sat, 17 Oct 2009 12:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9908548</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9908548.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9908548</wfw:commentRss><description>&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;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx">My System</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>Event ID 10016, KB 920783, and the WSS_WPG Group</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/17/event-id-10016-kb-920783-and-the-wss-wpg-group.aspx</link><pubDate>Sat, 17 Oct 2009 11:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9908545</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9908545.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9908545</wfw:commentRss><description>&lt;P&gt;If you've ever deployed Windows SharePoint Services (WSS) v3 or Microsoft Office SharePoint Server (MOSS) 2007 in a least privilege configuration, you have undoubtedly encountered errors similar to the following in your Windows event log:&lt;/P&gt;
&lt;BLOCKQUOTE class="directQuote errorMessage"&gt;The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID {61738644-F196-11D0-9953-00C04FD919C1} to the user TECHTOOLBOX\svc-sharepoint-dev SID (S-1-5-21-3914637029-2275272621-3670275343-1145) from address LocalHost (Using LRPC). This security permission can be modified using the Component Services administrative tool.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Specifically, I am referring to Event ID 10016 and 10017.&lt;/P&gt;
&lt;P&gt;While these errors are apparently benign, it is still rather annoying to have your event logs flooded with this kind of "noise." [Personally, I very much like to see servers come up "clean" after a reboot (meaning no new errors or warnings in the event log). This is especially true when you use something like &lt;A href="http://www.microsoft.com/systemcenter/operationsmanager/en/us/default.aspx" mce_href="http://www.microsoft.com/systemcenter/operationsmanager/en/us/default.aspx"&gt;Systems Center Operations Manager (SCOM)&lt;/A&gt; to monitor your servers, and one or more members of the Operations team receives notification whenever an error occurs on a Production server.]&lt;/P&gt;
&lt;P&gt;There are lots of sources out on the Internet that provide the steps necessary to resolve these errors (essentially you need to grant the SharePoint service account Local Activation permission to the IIS WAMREG Admin Service).&lt;/P&gt;
&lt;P&gt;This week, I was glad to discover that Microsoft has a KnowledgeBase article (&lt;A href="http://support.microsoft.com/kb/920783" mce_href="http://support.microsoft.com/kb/920783"&gt;KB 920783&lt;/A&gt;) describing the errors and the associated workaround. [This KB article appears to have been published over two years ago, but honestly, I was completely unaware of it until just yesterday when I was building out the Production MOSS 2007 environment on my latest project.]&lt;/P&gt;
&lt;P&gt;However, I see two problems with KB 920783: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;First, it doesn't mention Microsoft Office SharePoint Server (MOSS) 2007 -- which might explain why I never came across this KB before when searching the Internet. Sure, we all know that MOSS 2007 is built on top of WSS v3 and thus KB articles that apply to "Microsoft Windows SharePoint Services 3.0" almost always apply to "Microsoft Office SharePoint Server 2007", but if you don't specifically state that, you shouldn't expect Bing or Google to return the KB article when searching for something like "MOSS 10016" or "Microsoft Office SharePoint Server 10016". Right?&lt;/LI&gt;
&lt;LI&gt;Second, and much more important, the KB article instructs you to:&lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE&gt;&lt;SPAN class=directQuote&gt;"type the domain user account that you specified as the Windows SharePoint Services 3.0 service account"&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I definitely don't recommend doing that -- unless you just like making more work for yourself than necessary. Instead, you should specify the local &lt;STRONG&gt;WSS_WPG &lt;/STRONG&gt;group rather than a specific user. This is what I've been doing for the last couple of years so trust me, it works.&lt;/P&gt;
&lt;P&gt;The reason why I recommend using the "Windows SharePoint Services Worker Process Group" instead of individual users is that you are likely (or at least hopefully) using different service accounts for your SharePoint farm (e.g. TECHTOOLBOX\svc-sharepoint) and for the application pools behind your Web applications (e.g. TECHTOOLBOX\svc-web-fabrikam). Furthermore, if you are doing a large enterprise deployment of SharePoint, you likely have multiple Web applications (e.g. SSP, My Sites, etc.) that each utilize a separate service account.&lt;/P&gt;
&lt;P&gt;Rather than granting the Local Activation permission to each of these service accounts individually, it is much more effective to just grant the permission to the WSS_WPG group instead.&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;When creating a new Web application, SharePoint automatically adds the corresponding service account to the local WSS_WPG group on each SharePoint server in your farm.&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;[Update (2009-10-29):&lt;/P&gt;
&lt;P&gt;Matt McEvoy contacted me last Monday regarding the fact that I didn't specify the &lt;STRONG&gt;WSS_ADMIN_WPG &lt;/STRONG&gt;group -- only the &lt;STRONG&gt;WSS_WPG&lt;/STRONG&gt; group.&lt;/P&gt;
&lt;P&gt;Ugh...that will teach me to try to recall something like this from memory. When I was writing this blog post, I mistakenly thought that the service account for the SharePoint farm was added to both WSS_ADMIN_WPG and WSS_WPG. However, this isn't the case.&lt;/P&gt;
&lt;P&gt;Therefore you need to be sure to apply the steps in &lt;A href="http://support.microsoft.com/kb/920783" mce_href="http://support.microsoft.com/kb/920783"&gt;KB 920783&lt;/A&gt; using both groups if you want to rid your event logs of these errors once and for all. Again, this is assuming you are using least privilege accounts -- which I certainly hope you are.&lt;/P&gt;
&lt;P&gt;Thanks, Matt, for pointing out my omission.]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9908545" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/My+System/default.aspx">My System</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/Simplify/default.aspx">Simplify</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/WSS+v3/default.aspx">WSS v3</category></item><item><title>KB 896861 and "Microsoft Fix it"</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/14/kb-896861-and-microsoft-fix-it.aspx</link><pubDate>Wed, 14 Oct 2009 12:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9907113</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9907113.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9907113</wfw:commentRss><description>&lt;P&gt;A couple of days ago, I rebuilt one of my development VMs for Microsoft Office SharePoint Server (MOSS) 2007. As I've noted in a &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/02/10/issues-with-running-moss-2007-on-windows-server-2008.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/02/10/issues-with-running-moss-2007-on-windows-server-2008.aspx"&gt;previous post&lt;/A&gt;, I've found that I need to apply one of the registry hacks described in the following KnowledgeBase article:&lt;/P&gt;
&lt;DIV class=reference&gt;&lt;CITE&gt;You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or a later version&lt;/CITE&gt; 
&lt;DIV class=referenceLink&gt;&lt;A href="http://support.microsoft.com/kb/896861" mce_href="http://support.microsoft.com/kb/896861"&gt;http://support.microsoft.com/kb/896861&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;When I browsed to KB 896861 this week, I noticed that it has been updated since the last time I saw it. Apparently, this has become such a common issue that Microsoft now provides an automated way to fix the issue:&lt;/P&gt;
&lt;DIV align=center&gt;&lt;A style="WIDTH: 139px; DISPLAY: block; BACKGROUND: url(http://support.microsoft.com/library/images/support/KBGraphics/PUBLIC/cn/FixItButton.jpg) no-repeat 0px 0px; HEIGHT: 56px" title="Microsoft Fix it" href="http://go.microsoft.com/?linkid=9686309" mce_href="http://go.microsoft.com/?linkid=9686309"&gt;&lt;/A&gt;&lt;A title="Microsoft Fix it" href="http://go.microsoft.com/?linkid=9686309" mce_href="http://go.microsoft.com/?linkid=9686309"&gt;Fix this problem&lt;/A&gt; &lt;BR&gt;Microsoft Fix it 50306&lt;/DIV&gt;
&lt;P&gt;This was the first time I've seen a reference to &lt;STRONG&gt;Microsoft Fix it&lt;/STRONG&gt;, and I have to say that I like it -- and for more than just the cute moniker and button image, too!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9907113" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category><category domain="http://blogs.msdn.com/jjameson/archive/tags/Web+Development/default.aspx">Web Development</category></item><item><title>Bug in MOSS 2007 FBA with Insufficient Permissions in SQL Server</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/12/bug-in-moss-2007-fba-with-insufficient-permissions-in-sql-server.aspx</link><pubDate>Mon, 12 Oct 2009 13:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9906127</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9906127.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9906127</wfw:commentRss><description>&lt;P&gt;A couple of weeks ago I was setting up Forms-Based Authentication (FBA) on my new development VM for Microsoft Office SharePoint Server (MOSS) 2007, and I spent a few hours troubleshooting why I couldn't add a custom role ("Authenticated Users") to a SharePoint site.&lt;/P&gt;
&lt;P&gt;Just like I'd done a couple of times before, I meticulously followed Steve Peschka's article on MSDN -- &lt;A href="http://msdn.microsoft.com/en-us/library/bb975136.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb975136.aspx"&gt;Forms Authentication in SharePoint Products and Technologies (Part 1)&lt;/A&gt; -- that provides lots of details with regards to ensuring you have all the right Web.config entries (connection strings, membership element, etc.) necessary to make FBA work.&lt;/P&gt;
&lt;P&gt;I'd also granted the following permissions in SQL Server to the service account for the application pool corresponding to my Web application:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;aspnet_Membership_BasicAccess&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;aspnet_Roles_BasicAccess&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Like I said before, I had previously configured FBA in MOSS 2007 for a couple of previous projects, but this time, in addition to actually authenticating users (i.e. "membership"), I also needed to restrict access to certain areas of the site based on groups of FBA users (i.e. "roles").&lt;/P&gt;
&lt;P&gt;However, when I tried adding my custom &lt;STRONG&gt;Authenticated Users&lt;/STRONG&gt; role to a SharePoint group, the only thing SharePoint would recognize was &lt;STRONG&gt;NT AUTHORITY\authenticated users&lt;/STRONG&gt;. I even tried typing in the fully qualified role name (&lt;STRONG&gt;FabrikamSqlRoleProvider:Authenticated Users&lt;/STRONG&gt;), but SharePoint didn't recognize that either.&lt;/P&gt;
&lt;P&gt;The really frustrating part is that I could add users from my ASP.NET membership database to SharePoint groups, I just couldn't add roles. This certainly made me think that I had the necessary Web.config entries.&lt;/P&gt;
&lt;P&gt;I then fired up SQL Server Profiler to verify that SharePoint was at least &lt;EM&gt;trying&lt;/EM&gt; to query my ASP.NET database when adding a role to a SharePoint group. Sure enough, I saw the following statement in the profiler trace:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;CODE&gt;exec dbo.aspnet_Roles_RoleExists @ApplicationName=N'Fabrikam Portal',@RoleName=N'Authenticated Users'&lt;/CODE&gt;&lt;/DIV&gt;
&lt;P&gt;Hmmm...from this I could tell that SharePoint was definitely attempting to validate the custom role. I then attached the debugger and set it to break on all exceptions (the approach I frequently use when I am completely baffled by something).&lt;/P&gt;
&lt;P&gt;That's when I found the problem, namely a &lt;CODE&gt;SqlException&lt;/CODE&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE class="directQuote errorMessage"&gt;The EXECUTE permission was denied on the object 'aspnet_Roles_RoleExists', database 'FabrikamPortal', schema 'dbo'.&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ugh...it turns out the &lt;STRONG&gt;aspnet_Roles_RoleExists &lt;/STRONG&gt;stored procedure is by default only granted EXECUTE&lt;STRONG&gt; &lt;/STRONG&gt;permission to the &lt;STRONG&gt;aspnet_Roles_ReportingAccess &lt;/STRONG&gt;database role within SQL Server. Unfortunately, SharePoint was simply "swallowing" that &lt;CODE&gt;SqlException &lt;/CODE&gt;and assuming the role simply did not exist. I don't know about you, but I consider a "swallowed exception" like this to be a bug. Others may disagree, but that's my opinion.&lt;/P&gt;
&lt;P&gt;The lesson learned here is that when using Forms-Based Authentication and the out-of-the-box ASP.NET membership and role providers, your service account needs to be added to the following database roles in your ASP.NET database:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;aspnet_Membership_BasicAccess&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;aspnet_Membership_ReportingAccess&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;aspnet_Roles_BasicAccess&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;aspnet_Roles_ReportingAccess&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The reason you should add it the &lt;STRONG&gt;aspnet_Membership_ReportingAccess &lt;/STRONG&gt;database role -- in addition to the &lt;STRONG&gt;aspnet_Roles_ReportingAccess&lt;/STRONG&gt; database role -- is that the sprocs that allow you to do partial matching on user names (e.g. &lt;STRONG&gt;aspnet_Membership_FindUsersByName&lt;/STRONG&gt;) are by default only granted EXECUTE permission to the &lt;STRONG&gt;aspnet_Membership_ReportingAccess &lt;/STRONG&gt;database role (not &lt;STRONG&gt;aspnet_Membership_BasicAccess&lt;/STRONG&gt;).&lt;/P&gt;
&lt;P&gt;In other words, when I said earlier that I could add FBA users to a SharePoint group when my service account was a member of the &lt;STRONG&gt;aspnet_Membership_BasicAccess&lt;/STRONG&gt; database role, that only worked because I typed in the full username -- which gets validated using the &lt;STRONG&gt;aspnet_Membership_GetUserByName&lt;/STRONG&gt; sproc (which &lt;EM&gt;is&lt;/EM&gt; granted EXECUTE permission to the &lt;STRONG&gt;aspnet_Membership_BasicAccess&lt;/STRONG&gt; database role).&lt;/P&gt;
&lt;P&gt;By the way, here's some script to automatically create a user in SQL Server for the service account and add it to the necessary database roles:&lt;/P&gt;
&lt;DIV class=codeBlock&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;SPAN style="COLOR: #0000ff"&gt;USE&lt;/SPAN&gt; [FabrikamPortal]
&lt;SPAN style="COLOR: #0000ff"&gt;GO

CREATE&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff00ff"&gt;USER&lt;/SPAN&gt; [TECHTOOLBOX\svc-web-fabrikam-dev]
&lt;SPAN style="COLOR: #0000ff"&gt;FOR&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;LOGIN&lt;/SPAN&gt; [TECHTOOLBOX\svc-web-fabrikam-dev]
&lt;SPAN style="COLOR: #0000ff"&gt;WITH&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;DEFAULT_SCHEMA&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;=&lt;/SPAN&gt;[dbo]
&lt;SPAN style="COLOR: #0000ff"&gt;GO

EXEC&lt;/SPAN&gt; &lt;SPAN style="COLOR: #800000"&gt;sp_addrolemember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;N'aspnet_Membership_BasicAccess'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;N'TECHTOOLBOX\svc-web-fabrikam-dev'
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO
EXEC&lt;/SPAN&gt; &lt;SPAN style="COLOR: #800000"&gt;sp_addrolemember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;N'aspnet_Membership_ReportingAccess'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;N'TECHTOOLBOX\svc-web-fabrikam-dev'
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO
EXEC&lt;/SPAN&gt; &lt;SPAN style="COLOR: #800000"&gt;sp_addrolemember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;N'aspnet_Roles_BasicAccess'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;N'TECHTOOLBOX\svc-web-fabrikam-dev'
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO
EXEC&lt;/SPAN&gt; &lt;SPAN style="COLOR: #800000"&gt;sp_addrolemember&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #ff0000"&gt;N'aspnet_Roles_ReportingAccess'&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;N'TECHTOOLBOX\svc-web-fabrikam-dev'
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;GO&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;You'll obviously need to replace the name of your ASP.NET database and service account accordingly.&lt;/P&gt;
&lt;P&gt;Isn't it fun conforming to the principle of least privilege?!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9906127" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category></item><item><title>Introducing the SharePointPublishingHelper Class</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/09/introducing-the-sharepointpublishinghelper-class.aspx</link><pubDate>Fri, 09 Oct 2009 15:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9905404</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9905404.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9905404</wfw:commentRss><description>&lt;P&gt;In my &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/08/importing-pages-into-moss-2007-from-an-excel-file.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/08/importing-pages-into-moss-2007-from-an-excel-file.aspx"&gt;previous post&lt;/A&gt;, I described a utility to import pages into Microsoft Office SharePoint Server (MOSS) 2007 from an Excel input file.&lt;/P&gt;
&lt;P&gt;Aside from the code to read data from the input file into a DataSet, the main work is performed by the &lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; class (which was written long before the ImportPages.exe utility). This class is simply a collection of helper methods for the SharePoint publishing API.&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; makes it really easy to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Attempt to retrieve a reference to a &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingpage.aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingpage.aspx"&gt;PublishingPage&lt;/A&gt; by specifying an &lt;A href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.aspx" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.aspx"&gt;SPWeb&lt;/A&gt; and the page URL name (e.g. default.aspx)&lt;/LI&gt;
&lt;LI&gt;Ensure an expected page exists in a site (creating a new page as necessary)&lt;/LI&gt;
&lt;LI&gt;Check if a page is checked out to anyone&lt;/LI&gt;
&lt;LI&gt;Check if a page is checked out by the current user&lt;/LI&gt;
&lt;LI&gt;Ensure a page is checked out to the current user (since you can't make any changes to a page that isn't checked out to you)&lt;/LI&gt;
&lt;LI&gt;Ensure a page is associated with a specific page layout (and corresponding content type)&lt;/LI&gt;
&lt;LI&gt;Publish a page (correctly handling page libraries that are configured for approval as well as those that are not configured for approval)&lt;/LI&gt;
&lt;LI&gt;Delete a page by specifying the page URL name&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Here's the code for the &lt;CODE&gt;SharePointPublishingHelper&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.Security.Permissions;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint.Publishing;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint.Security;

&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 the
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; SharePoint Publishing API. 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;SharePointPublishingHelper&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
&lt;/SPAN&gt;    &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; and 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;SharePointPublishingHelper
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; SharePointPublishingHelper() { } &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; Deletes the specified publishing page in the site (if it exists).
&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="web"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The site containing the publishing 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="pageUrlName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL name of the page (e.g.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "default.aspx").&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;"CA1054:UriParametersShouldNotBeStrings"&lt;/SPAN&gt;,
            Justification = &lt;SPAN style="COLOR: #a31515"&gt;"Page URL name is only the last part of the local"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" path of the page URL."&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; DeletePage(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageUrlName)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (web == &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;"web"&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;.IsNullOrEmpty(pageUrlName) == &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 page URL name must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"pageUrlName"&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;"Deleting page ({0}) from Web ({1})..."&lt;/SPAN&gt;,
                pageUrlName,
                web.Url);

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page = FindPublishingPage(web, pageUrlName);
            
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"The page specified to delete ({0})"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" does not exist in the Web ({1})."&lt;/SPAN&gt;,
                    pageUrlName,
                    web.Url);

            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else
&lt;/SPAN&gt;            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; absolutePageUrl =
                        page.ListItem.Web.Url + &lt;SPAN style="COLOR: #a31515"&gt;'/'&lt;/SPAN&gt; + page.Url;
                
                &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;"Deleting page: {0}..."&lt;/SPAN&gt;,
                    absolutePageUrl);

                page.ListItem.Delete();

                &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 deleted page: {0}."&lt;/SPAN&gt;,
                    absolutePageUrl);
            }
        }

        &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 a page exists and is configured according with the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; 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="web"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The site containing the publishing 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="pageUrlName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL name of the page (e.g.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "default.aspx").&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="pageTitle"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The title of 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="pageLayoutUrl"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL of the page layout for the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; page (e.g. /_catalogs/masterpage/WelcomeLinks.aspx).&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 publishing 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;"CA1054:UriParametersShouldNotBeStrings"&lt;/SPAN&gt;,
            Justification = &lt;SPAN style="COLOR: #a31515"&gt;"Page URL name is only the last part of the local"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" path of the page URL. Page layout URL is a server-relative"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" URL (e.g. /_catalogs/masterpage/WelcomeLinks.aspx)."&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;PublishingPage&lt;/SPAN&gt; EnsurePage(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageUrlName,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageTitle,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageLayoutUrl)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; EnsurePage(
                web,
                pageUrlName,
                pageTitle,
                pageLayoutUrl,
                &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; Ensures a page exists and is configured according with the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; 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="web"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The site containing the publishing 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="pageUrlName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL name of the page (e.g.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "default.aspx").&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="pageTitle"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The title of 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="pageLayoutUrl"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL of the page layout for the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; page (e.g. /_catalogs/masterpage/WelcomeLinks.aspx).&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="pageDescription"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The description of the page (optional).&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 publishing 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;"CA1054:UriParametersShouldNotBeStrings"&lt;/SPAN&gt;,
            Justification = &lt;SPAN style="COLOR: #a31515"&gt;"Page URL name is only the last part of the local"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" path of the page URL. Page layout URL is a server-relative"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" URL (e.g. /_catalogs/masterpage/WelcomeLinks.aspx)."&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;PublishingPage&lt;/SPAN&gt; EnsurePage(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageUrlName,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageTitle,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageLayoutUrl,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageDescription)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (web == &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;"web"&lt;/SPAN&gt;);
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (pageUrlName == &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;"pageUrlName"&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;.IsNullOrEmpty(pageUrlName) == &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 page URL name must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"pageUrlName"&lt;/SPAN&gt;);
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (pageTitle == &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;"pageTitle"&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;.IsNullOrEmpty(pageTitle) == &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 page title must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"pageTitle"&lt;/SPAN&gt;);
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (pageLayoutUrl == &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;"pageLayoutUrl"&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;.IsNullOrEmpty(pageLayoutUrl) == &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 page layout URL must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"pageLayoutUrl"&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 page ({0}) in Web ({1})..."&lt;/SPAN&gt;,
                pageUrlName,
                web.Url);

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingSite&lt;/SPAN&gt; pubSite = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;PublishingSite&lt;/SPAN&gt;(web.Site);
            &lt;SPAN style="COLOR: #2b91af"&gt;PageLayout&lt;/SPAN&gt; layout = pubSite.PageLayouts[pageLayoutUrl];

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (layout == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &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;"Invalid page layout specified ({0})."&lt;/SPAN&gt;,
                    pageLayoutUrl);

                &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;"pageLayoutUrl"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingWeb&lt;/SPAN&gt; pubWeb = &lt;SPAN style="COLOR: #2b91af"&gt;PublishingWeb&lt;/SPAN&gt;.GetPublishingWeb(web);
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPageCollection&lt;/SPAN&gt; pages = pubWeb.GetPublishingPages();

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page =
                pages[pubWeb.PagesListName + &lt;SPAN style="COLOR: #a31515"&gt;"/"&lt;/SPAN&gt; + pageUrlName];

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"Creating page ({0}/{1}/{2})..."&lt;/SPAN&gt;,
                    web.Url,
                    pubWeb.PagesListName,
                    pageUrlName);

                page = pages.Add(pageUrlName, layout);
                page.Title = pageTitle;

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(pageDescription) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
                {
                    page.Description = pageDescription;
                }

                page.ListItem.SystemUpdate(&lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);

                &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 page: {0}/{1}."&lt;/SPAN&gt;,
                    web.Url,
                    page.Url);
            }
            &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 specified page ({0}/{1}) already exists."&lt;/SPAN&gt;,
                    web.Url,
                    page.Url);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; page;
        }

        &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; Ensure the specified page is configured with the specified content
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; type and page layout.
&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="page"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The page to check (and update as necessary).&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="pageLayoutUrl"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL of the page layout for the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; page (e.g. /_catalogs/masterpage/WelcomeLinks.aspx).&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;"CA1054:UriParametersShouldNotBeStrings"&lt;/SPAN&gt;,
            Justification = &lt;SPAN style="COLOR: #a31515"&gt;"Page layout URL is a server-relative"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" URL (e.g. /_catalogs/masterpage/WelcomeLinks.aspx)."&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; EnsurePageContentTypeAndLayout(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageLayoutUrl)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"page"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(pageLayoutUrl) == &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 page layout must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"pageLayoutUrl"&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 type and page layout ({0}) for page"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;" ({1}/{2})..."&lt;/SPAN&gt;,
                pageLayoutUrl,
                page.ListItem.Web.Url,
                page.Url);

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingSite&lt;/SPAN&gt; site = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;PublishingSite&lt;/SPAN&gt;(page.PublishingWeb.Web.Site);
            &lt;SPAN style="COLOR: #2b91af"&gt;PageLayout&lt;/SPAN&gt; layout = site.PageLayouts[pageLayoutUrl];
            
            &lt;SPAN style="COLOR: #2b91af"&gt;SPContentTypeId&lt;/SPAN&gt; contentTypeId = layout.AssociatedContentType.Id;
            
            &lt;SPAN style="COLOR: #008000"&gt;// HACK: The content type associated with each "Pages" library
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// actually gets a unique ContentTypeId (it is appended with a
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// unique identifier for the list -- thus inheriting from the
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #008000"&gt;// content type associated with the page layout).
&lt;/SPAN&gt;            &lt;SPAN style="COLOR: #2b91af"&gt;SPContentType&lt;/SPAN&gt; pageContentType = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
            
            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;SPContentType&lt;/SPAN&gt; listContentType &lt;SPAN style="COLOR: #0000ff"&gt;in
&lt;/SPAN&gt;                page.PublishingWeb.PagesList.ContentTypes)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (listContentType.Parent.Id == contentTypeId)
                {
                    pageContentType = listContentType;
                    &lt;SPAN style="COLOR: #0000ff"&gt;break&lt;/SPAN&gt;;
                }
            }
            
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (pageContentType == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                &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;"The content type ({0}) associated with the page layout"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" ({1}) is not enabled on the list ({2}/{3})."&lt;/SPAN&gt;,
                    layout.AssociatedContentType.Name,
                    pageLayoutUrl,
                    page.ListItem.Web.Url,
                    page.PublishingWeb.PagesListName);

                &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;"pageLayoutUrl"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; ((&lt;SPAN style="COLOR: #2b91af"&gt;SPContentTypeId&lt;/SPAN&gt;)page.ListItem[&lt;SPAN style="COLOR: #a31515"&gt;"ContentTypeId"&lt;/SPAN&gt;] !=
                    pageContentType.Id
                || page.Layout.Name != layout.Name)
            {
                &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 content type and page layout ({0}) for page"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" ({1}/{2})..."&lt;/SPAN&gt;,
                    pageLayoutUrl,
                    page.ListItem.Web.Url,
                    page.Url);

                page.ListItem[&lt;SPAN style="COLOR: #a31515"&gt;"ContentTypeId"&lt;/SPAN&gt;] = pageContentType.Id;
                page.Layout = layout;
                page.Update();

                &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 content type and page layout ({0})"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;"  for page: {1}/{2}."&lt;/SPAN&gt;,
                    pageLayoutUrl,
                    page.ListItem.Web.Url,
                    page.Url);
            }
            &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 page ({0}/{1}) is already configured with the"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" specified content type and page layout ({2})."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.Url,                    
                    pageLayoutUrl);
            }
        }

        &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 the specified page is checked out to the current user.
&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="page"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The publishing page to check out.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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.Naming"&lt;/SPAN&gt;,
            &lt;SPAN style="COLOR: #a31515"&gt;"CA1702:CompoundWordsShouldBeCasedCorrectly"&lt;/SPAN&gt;,
            MessageId = &lt;SPAN style="COLOR: #a31515"&gt;"ToMe"&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; EnsurePageIsCheckedOutToMe(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"page"&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 page ({0}/{1}) is checked out to the current"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;" user..."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isPageCheckedOut = IsPageCheckedOut(page);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (isPageCheckedOut == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isPageCheckedOutToMe = IsPageCheckedOutToMe(page);

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (isPageCheckedOutToMe == &lt;SPAN style="COLOR: #0000ff"&gt;true&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 page ({0}/{1}) is already checked out to the"
&lt;/SPAN&gt;                            + &lt;SPAN style="COLOR: #a31515"&gt;" current user."&lt;/SPAN&gt;,
                        page.ListItem.Web.Url,
                        page.Url);

                    &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;;
                }

                &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;"Cannot check out the page "
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" ({0}/{1}) because it is already checked"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" out to somebody else."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.Url);

                &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;(message);
            }

            &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;"Checking out page ({0}/{1})..."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);

            page.CheckOut();

            &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 checked out page: {0}/{1}."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);
        }

        &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 specified publishing page in the site.
&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="web"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The site containing the publishing 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="pageUrlName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL name of the page (e.g.
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; "default.aspx").&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 specified publishing page, or null if the page does not
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; exist.&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;"CA1054:UriParametersShouldNotBeStrings"&lt;/SPAN&gt;,
            Justification = &lt;SPAN style="COLOR: #a31515"&gt;"Page URL name is only the last part of the local"
&lt;/SPAN&gt;                + &lt;SPAN style="COLOR: #a31515"&gt;" path of the page URL."&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;PublishingPage&lt;/SPAN&gt; FindPublishingPage(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageUrlName)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (web == &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;"web"&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;.IsNullOrEmpty(pageUrlName) == &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 page URL name must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"pageUrlName"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingWeb&lt;/SPAN&gt; pubWeb = &lt;SPAN style="COLOR: #2b91af"&gt;PublishingWeb&lt;/SPAN&gt;.GetPublishingWeb(web);
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPageCollection&lt;/SPAN&gt; pages = pubWeb.GetPublishingPages();

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page = pages[pubWeb.PagesListName + &lt;SPAN style="COLOR: #a31515"&gt;"/"&lt;/SPAN&gt; + pageUrlName];
            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; page;
        }

        &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; Determines if the specified page is approved.
&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="page"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The page to determine the status of.&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;True if the specified page is approved (or if the
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; corresponding library is not configured for approval), otherwise
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; false.&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;"CA1011:ConsiderPassingBaseTypesAsParameters"&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;bool&lt;/SPAN&gt; IsPageApproved(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"page"&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;"Checking if page ({0}/{1}) is approved..."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isApproved = &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page.ListItem.ModerationInformation == &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;"Pages library ({0}/{1}) is not configured for approval."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.PublishingWeb.PagesListName);

                &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(page.ListItem.Versions != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);
                &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(page.ListItem.Versions.Count &amp;gt; 0);

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page.ListItem.Versions[0].Level == &lt;SPAN style="COLOR: #2b91af"&gt;SPFileLevel&lt;/SPAN&gt;.Published)
                {
                    isApproved = &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;
                }
            }
            &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;"Pages library ({0}/{1}) is configured for approval."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.PublishingWeb.PagesListName);

                isApproved =
                    (page.ListItem.ModerationInformation.Status ==
                        &lt;SPAN style="COLOR: #2b91af"&gt;SPModerationStatusType&lt;/SPAN&gt;.Approved);
            }

            &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 page ({0}/{1} is {2}."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url,
                isApproved ? &lt;SPAN style="COLOR: #a31515"&gt;"approved"&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #a31515"&gt;"not approved"&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; isApproved;
        }

        &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; Determines if the specified page is checked out.
&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="page"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The page to determine the status of.&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;True if the specified page is checked out, otherwise false.&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;"CA1011:ConsiderPassingBaseTypesAsParameters"&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;bool&lt;/SPAN&gt; IsPageCheckedOut(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"page"&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;"Checking if page ({0}/{1}) is checked out..."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isCheckedOut =
                (page.ListItem.File.CheckOutStatus != &lt;SPAN style="COLOR: #2b91af"&gt;SPFile&lt;/SPAN&gt;.&lt;SPAN style="COLOR: #2b91af"&gt;SPCheckOutStatus&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;"The page ({0}/{1}) is {2}."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url,
                isCheckedOut ? &lt;SPAN style="COLOR: #a31515"&gt;"checked out"&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #a31515"&gt;"not checked out"&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; isCheckedOut;
        }

        &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; Determines if the specified page is checked out to the current user.
&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="page"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The page to determine the status of.&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;True if the specified page is checked out to the current
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; user, otherwise false.&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;"CA1011:ConsiderPassingBaseTypesAsParameters"&lt;/SPAN&gt;),
        System.Diagnostics.CodeAnalysis.&lt;SPAN style="COLOR: #2b91af"&gt;SuppressMessage&lt;/SPAN&gt;(
            &lt;SPAN style="COLOR: #a31515"&gt;"Microsoft.Naming"&lt;/SPAN&gt;,
            &lt;SPAN style="COLOR: #a31515"&gt;"CA1702:CompoundWordsShouldBeCasedCorrectly"&lt;/SPAN&gt;,
            MessageId = &lt;SPAN style="COLOR: #a31515"&gt;"ToMe"&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;bool&lt;/SPAN&gt; IsPageCheckedOutToMe(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"page"&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;"Checking if page ({0}/{1}) is checked out to current user..."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isCheckedOut = (page.ListItem.File.CheckOutStatus
                != &lt;SPAN style="COLOR: #2b91af"&gt;SPFile&lt;/SPAN&gt;.&lt;SPAN style="COLOR: #2b91af"&gt;SPCheckOutStatus&lt;/SPAN&gt;.None);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (isCheckedOut == &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;"The page ({0}/{1}) is not checked out."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.Url);

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isCheckedOutToMe = (page.ListItem.File.CheckedOutBy.LoginName
                == page.ListItem.Web.CurrentUser.LoginName);

            &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 page ({0}/{1}) is {2} to the current user."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url,
                isCheckedOutToMe ? &lt;SPAN style="COLOR: #a31515"&gt;"checked out"&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #a31515"&gt;"not checked out"&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; isCheckedOutToMe;
        }

        &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; Publishes the specified page (making it generally available for viewing).
&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="page"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The page to publish.&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="comments"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;Comments to associate with the publishing action.&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/param&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;"CA1011:ConsiderPassingBaseTypesAsParameters"&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; PublishPage(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; comments)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page == &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;"page"&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;"Publishing page ({0}/{1})..."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (page.ListItem.ModerationInformation == &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;"Pages library ({0}/{1}) is not configured for approval."
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" Checking in page..."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.PublishingWeb.PagesListName);

                page.ListItem.File.CheckIn(
                    comments,
                    &lt;SPAN style="COLOR: #2b91af"&gt;SPCheckinType&lt;/SPAN&gt;.MajorCheckIn);
            }
            &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;"Pages library ({0}/{1}) is configured for approval."
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" Scheduling page for publication..."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.PublishingWeb.PagesListName);

                page.Schedule(comments);
            }

            &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 published page: {0}/{1}."&lt;/SPAN&gt;,
                page.ListItem.Web.Url,
                page.Url);
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;In addition to the &lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; class, I often rely on several other custom SharePoint "helper" classes, such &lt;CODE&gt;SharePointListHelper&lt;/CODE&gt; and &lt;CODE&gt;SharePointWebPartHelper&lt;/CODE&gt;. These classes evolved over time by refactoring common code that was previously repeated in numerous places. In other words, as Scott Hanselman likes to say...a developer should always try to write DRY code (meaning, don't repeat yourself).&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9905404" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category></item><item><title>Importing Pages into MOSS 2007 from an Excel File</title><link>http://blogs.msdn.com/jjameson/archive/2009/10/08/importing-pages-into-moss-2007-from-an-excel-file.aspx</link><pubDate>Thu, 08 Oct 2009 16:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9904911</guid><dc:creator>Jeremy Jameson</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jjameson/comments/9904911.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jjameson/commentrss.aspx?PostID=9904911</wfw:commentRss><description>&lt;P&gt;In my &lt;A href="http://blogs.msdn.com/jjameson/archive/2009/10/08/web-application-at-could-not-be-found-error-on-moss-2007-x64.aspx" mce_href="http://blogs.msdn.com/jjameson/archive/2009/10/08/web-application-at-could-not-be-found-error-on-moss-2007-x64.aspx"&gt;previous post&lt;/A&gt;, I briefly introduced the concept of a utility to import pages into Microsoft Office SharePoint Server (MOSS) 2007 from an Excel input file. This can be very useful for Development and Test environments (where you frequently rebuild the sites during the development process), as well as when migrating legacy Web sites to a Production environment -- or whenever a "quick and dirty" process is deemed sufficient for the business needs.&lt;/P&gt;
&lt;P&gt;I've done a number of MOSS 2007 migration projects over the last several years and developed a number of tools to migrate content into SharePoint. About a month ago, I utilized some existing code I had previously written to import pages from a simple Excel workbook -- rather than some other data source, such as a legacy database. The Excel workbook simply contains one or more worksheets, where each worksheet represents a particular group of pages with similar columns/fields. Each worksheet must have the following columns:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;WebUrl&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;PageUrlName&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;PageLayout&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Title&lt;/STRONG&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Additional columns (such as &lt;STRONG&gt;Page Content&lt;/STRONG&gt;) can also be specified -- including custom columns for content types that are not included out-of-the-box with MOSS 2007.&lt;/P&gt;
&lt;P&gt;Note that I am not advocating installing the full Microsoft Office suite -- or even just Excel -- on your SharePoint servers just for the sake of importing a few hundred (or perhaps a few thousand) pages into your site. Rather, you would simply need to install the following on one of the servers in your farm:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;STRONG&gt;2007 Office System Driver: Data Connectivity Components&lt;/STRONG&gt;&lt;BR&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?familyid=7554F536-8C28-4598-9B72-EF94E038C891&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?familyid=7554F536-8C28-4598-9B72-EF94E038C891&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?familyid=7554F536-8C28-4598-9B72-EF94E038C891&amp;amp;displaylang=en&lt;/A&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Preferably, you would install this only on a backend "job/index" server that isn't servicing any user requests directly and then run the ImportPages.exe utility on that server -- or at least, that's what I thought originally.&lt;/P&gt;
&lt;P&gt;The problem is that in order to utilize the currently available OLEDB providers (which are 32-bit), you have to force the process to run as 32-bit (by setting the platform target to &lt;STRONG&gt;x86&lt;/STRONG&gt;). However, as noted in my previous post, you can't utilize the SharePoint API from a 32-bit process running on an x64 environment. Quite the paradox indeed.&lt;/P&gt;
&lt;P&gt;The solution that I came up with is to enhance the ImportPages.exe utility to support an Excel input file as well as a simple XML file that contains a serialized DataSet.&lt;/P&gt;
&lt;P&gt;In other words, importing pages from Excel in an x64 environment requires a two-step process:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Convert the Excel input file into a simple XML file that contains a serialized DataSet. Note that this can be done on any environment (i.e. it does not necessarily have to be done on one of the SharePoint servers). In other words, you could have someone create the Excel input file on his or her laptop and then convert it to a DataSet XML file.&lt;/LI&gt;
&lt;LI&gt;Import the pages from the DataSet XML file. Note that this step must be performed on one of the SharePoint servers in the farm.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;To convert an Excel file to a DataSet XML file:&lt;/P&gt;
&lt;DIV class=consoleBlock&gt;&lt;SAMP&gt;ConvertToDataSet.exe Sample.xslx&lt;/SAMP&gt;&lt;/DIV&gt;
&lt;P&gt;To import pages from the generated DataSet XML file:&lt;/P&gt;
&lt;DIV class=consoleBlock&gt;&lt;SAMP&gt;ImportPages.exe &lt;A href="http://fabrikam/" mce_href="http://fabrikam"&gt;http://fabrikam&lt;/A&gt; Sample.xml&lt;/SAMP&gt;&lt;/DIV&gt;
&lt;P&gt;Here is the code for the ConvertToDataSet.exe utility:&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.IO;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.CoreServices;

&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Demo.Tools.ConvertToDataSet
{
    &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; Main class for the ConvertToDataSet.exe utility.
&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: #0000ff"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;Program
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; Program() { } &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: #0000ff"&gt;void&lt;/SPAN&gt; Main(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;[] args)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (args.Length != 1)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Error.WriteLine(
                    &lt;SPAN style="COLOR: #a31515"&gt;"Usage: ConvertToDataSet"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;" {filename}"&lt;/SPAN&gt;);

                &lt;SPAN style="COLOR: #2b91af"&gt;Environment&lt;/SPAN&gt;.Exit(1);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; inputFileName = args[0];

            &lt;SPAN style="COLOR: #0000ff"&gt;try
&lt;/SPAN&gt;            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; fileExtension = &lt;SPAN style="COLOR: #2b91af"&gt;Path&lt;/SPAN&gt;.GetExtension(inputFileName);

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Compare(
                    fileExtension,
                    &lt;SPAN style="COLOR: #a31515"&gt;".xml"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                {
                    &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;"Cannot convert an XML file to a DataSet."&lt;/SPAN&gt;);
                }

                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; outputFileName = &lt;SPAN style="COLOR: #2b91af"&gt;Path&lt;/SPAN&gt;.ChangeExtension(inputFileName, &lt;SPAN style="COLOR: #a31515"&gt;"xml"&lt;/SPAN&gt;);

                &lt;SPAN style="COLOR: #2b91af"&gt;DataSet&lt;/SPAN&gt; data = &lt;SPAN style="COLOR: #2b91af"&gt;DataSetHelper&lt;/SPAN&gt;.LoadFromFile(inputFileName);

                data.WriteXml(outputFileName);

                &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(
                    &lt;SPAN style="COLOR: #a31515"&gt;"DataSet serialized to file: {0}"&lt;/SPAN&gt;,
                    outputFileName);

                &lt;SPAN style="COLOR: #2b91af"&gt;Environment&lt;/SPAN&gt;.Exit(0);
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;catch&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;Exception&lt;/SPAN&gt; ex)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Error.WriteLine(ex.Message);

&lt;SPAN style="COLOR: #0000ff"&gt;#if&lt;/SPAN&gt; DEBUG
                &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Error.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"(stack trace):"&lt;/SPAN&gt;);
                &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.Error.WriteLine(ex.StackTrace);
&lt;SPAN style="COLOR: #0000ff"&gt;#endif

&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #2b91af"&gt;Environment&lt;/SPAN&gt;.Exit(1);
            }
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Note that the bulk of the code has been refactored into my &lt;CODE&gt;DataSetHelper&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.Collections.Generic;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Data;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; System.Data.OleDb;
&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;namespace&lt;/SPAN&gt; Fabrikam.Demo.CoreServices
{
    &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; the &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;see cref="System.Data.DataSet" /&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; class.
&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;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;DataSetHelper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&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: #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;DataSetHelper
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; DataSetHelper() { } &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; Loads a DataSet from the specified file.
&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: #008000"&gt;The input file may be an Excel file (.xls or .xlsx) or a
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; simple CSV file (i.e. comma-separated values).&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="fileName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The filename (including the path) from which
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; to load the data.&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 &lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;see cref="System.Data.DataSet" /&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; containing the data
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; read from the file.&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;DataSet&lt;/SPAN&gt; LoadFromFile(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; fileName)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (fileName == &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;"fileName"&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;.IsNullOrEmpty(fileName) == &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 file name must be specified."&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #a31515"&gt;"fileName"&lt;/SPAN&gt;);
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;FileInfo&lt;/SPAN&gt; inputFileInfo = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;FileInfo&lt;/SPAN&gt;(fileName);

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; connectionString = GetOleDbConnectionString(inputFileInfo);

            &lt;SPAN style="COLOR: #2b91af"&gt;OleDbConnection&lt;/SPAN&gt; connection = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OleDbConnection&lt;/SPAN&gt;(connectionString);
            connection.Open();

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;[] tableNames = GetTableNames(inputFileInfo, connection);

            &lt;SPAN style="COLOR: #2b91af"&gt;DataSet&lt;/SPAN&gt; data = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;DataSet&lt;/SPAN&gt;();
            data.Locale = &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture;

            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; tableName &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; tableNames)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt; table = data.Tables.Add(tableName);

                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; commandText = &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;"SELECT * FROM [{0}]"&lt;/SPAN&gt;,
                    tableName);

                &lt;SPAN style="COLOR: #2b91af"&gt;OleDbCommand&lt;/SPAN&gt; selectCommand = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OleDbCommand&lt;/SPAN&gt;(
                    commandText,
                    connection);

                &lt;SPAN style="COLOR: #2b91af"&gt;OleDbDataAdapter&lt;/SPAN&gt; adapter = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;OleDbDataAdapter&lt;/SPAN&gt;(selectCommand);

                adapter.Fill(table);
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; data;
        }

        &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; GetOleDbConnectionString(
            &lt;SPAN style="COLOR: #2b91af"&gt;FileInfo&lt;/SPAN&gt; inputFileInfo)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; connectionString = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Compare(
                inputFileInfo.Extension,
                &lt;SPAN style="COLOR: #a31515"&gt;".xls"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
            {
                connectionString =
                    &lt;SPAN style="COLOR: #a31515"&gt;@"Provider=Microsoft.Jet.OLEDB.4.0;"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"Data Source="&lt;/SPAN&gt; + inputFileInfo.FullName + &lt;SPAN style="COLOR: #a31515"&gt;";"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"Extended Properties=\"Excel 8.0;HDR=YES;\""&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(
                inputFileInfo.Extension,
                &lt;SPAN style="COLOR: #a31515"&gt;".xlsx"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
            {
                connectionString =
                    &lt;SPAN style="COLOR: #a31515"&gt;@"Provider=Microsoft.ACE.OLEDB.12.0;"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"Data Source="&lt;/SPAN&gt; + inputFileInfo.FullName + &lt;SPAN style="COLOR: #a31515"&gt;";"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"Extended Properties=\"Excel 12.0;HDR=Yes;ReadOnly=true;"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"IMEX=1;\""&lt;/SPAN&gt;;
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else
&lt;/SPAN&gt;            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; folder = inputFileInfo.DirectoryName;

                connectionString =
                    &lt;SPAN style="COLOR: #a31515"&gt;@"Provider=Microsoft.Jet.OLEDB.4.0;"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"Data Source="&lt;/SPAN&gt; + folder + &lt;SPAN style="COLOR: #a31515"&gt;";"
&lt;/SPAN&gt;                    + &lt;SPAN style="COLOR: #a31515"&gt;"Extended Properties=\"text;HDR=YES;FMT=Delimited;\""&lt;/SPAN&gt;;

            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; connectionString;
        }

        &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;[] GetTableNames(
            &lt;SPAN style="COLOR: #2b91af"&gt;FileInfo&lt;/SPAN&gt; inputFileInfo,
            &lt;SPAN style="COLOR: #2b91af"&gt;OleDbConnection&lt;/SPAN&gt; connection)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isExcelFile = &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(
                inputFileInfo.Extension,
                &lt;SPAN style="COLOR: #a31515"&gt;".xls"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
            {
                isExcelFile = &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(
                inputFileInfo.Extension,
                &lt;SPAN style="COLOR: #a31515"&gt;".xlsx"&lt;/SPAN&gt;,
                &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
            {
                isExcelFile = &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (isExcelFile == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #008000"&gt;// Get all of the Table names from the Excel workbook 
&lt;/SPAN&gt;                &lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt; worksheetTables = connection.GetOleDbSchemaTable(
                    &lt;SPAN style="COLOR: #2b91af"&gt;OleDbSchemaGuid&lt;/SPAN&gt;.Tables,
                    &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;);

                &lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&amp;gt; tableNames = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&amp;gt;();

                &lt;SPAN style="COLOR: #0000ff"&gt;for&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt; i = 0; i &amp;lt; worksheetTables.Rows.Count; i++)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; tableName =
                        (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)worksheetTables.Rows[i][&lt;SPAN style="COLOR: #a31515"&gt;"TABLE_NAME"&lt;/SPAN&gt;];

                    &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Compare(
                        tableName,
                        &lt;SPAN style="COLOR: #a31515"&gt;"_xlnm#_FilterDatabase"&lt;/SPAN&gt;,
                        &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                    {
                        &lt;SPAN style="COLOR: #0000ff"&gt;continue&lt;/SPAN&gt;;
                    }

                    tableNames.Add(tableName);
                }

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; tableNames.ToArray();
            }
            &lt;SPAN style="COLOR: #0000ff"&gt;else
&lt;/SPAN&gt;            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;[] tableNames = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;[1];
                tableNames[0] = inputFileInfo.Name;
                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; tableNames;
            }
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;Similarly, the bulk of the code for the ImportPages.exe utility has been refactored into the &lt;CODE&gt;PageImporter&lt;/CODE&gt; and &lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; classes.&lt;/P&gt;
&lt;P&gt;Here's the code for the &lt;CODE&gt;PageImporter&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.Data;
&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; Microsoft.SharePoint;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Microsoft.SharePoint.Publishing;

&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.CoreServices;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.CoreServices.Logging;
&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; Fabrikam.Demo.CoreServices.SharePoint;

&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Fabrikam.Demo.Tools.SharePoint.ImportPages
{
    &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 importing pages into a SharePoint site.
&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;c&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;PageImporter&lt;/SPAN&gt;&lt;SPAN style="COLOR: #808080"&gt;&amp;lt;/c&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;    &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;PageImporter
&lt;/SPAN&gt;    {
        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; PageImporter() { } &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; Imports pages into the specified SharePoint site using data from
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; the specified input file.
&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="siteUrl"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The URL of the SharePoint site.&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="fileName"&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;The filename (including the path) from which
&lt;/SPAN&gt;        &lt;SPAN style="COLOR: #808080"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt; to load the data.&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; Import(
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; siteUrl,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; fileName)
        {
            &lt;SPAN style="COLOR: #2b91af"&gt;DataSet&lt;/SPAN&gt; data = &lt;SPAN style="COLOR: #2b91af"&gt;DataSetHelper&lt;/SPAN&gt;.LoadFromFile(fileName);

            &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;SPSite&lt;/SPAN&gt; site = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SPSite&lt;/SPAN&gt;(siteUrl))
            {
                Import(site, data);
            }
        }

        &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; Import(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPSite&lt;/SPAN&gt; site,
            &lt;SPAN style="COLOR: #2b91af"&gt;DataSet&lt;/SPAN&gt; data)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt; table &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; data.Tables)
            {
                Import(site, table);
            }
        }

        &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; Import(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPSite&lt;/SPAN&gt; site,
            &lt;SPAN style="COLOR: #2b91af"&gt;DataTable&lt;/SPAN&gt; table)
        {
            &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;

            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;DataRow&lt;/SPAN&gt; row &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; table.Rows)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; webUrl = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)row[&lt;SPAN style="COLOR: #a31515"&gt;"WebUrl"&lt;/SPAN&gt;];
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageUrlName = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)row[&lt;SPAN style="COLOR: #a31515"&gt;"PageUrlName"&lt;/SPAN&gt;];

                &lt;SPAN style="COLOR: #0000ff"&gt;try
&lt;/SPAN&gt;                {
                    EnsureReferenceToExpectedWeb(site, &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; web, webUrl);

                    Import(web, row);
                }
                &lt;SPAN style="COLOR: #0000ff"&gt;catch&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;ArgumentNullException&lt;/SPAN&gt; ex)
                {
                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogWarning(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Error importing page ({0}) into Web ({1}) - {2}."&lt;/SPAN&gt;,
                        pageUrlName,
                        webUrl,
                        ex.Message);
                }
                &lt;SPAN style="COLOR: #0000ff"&gt;catch&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;FileNotFoundException&lt;/SPAN&gt; ex)
                {
                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogWarning(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"Error importing page ({0}) into Web ({1}) - {2}."&lt;/SPAN&gt;,
                        pageUrlName,
                        webUrl,
                        ex.Message);
                }
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (web != &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                web.Dispose();
            }
        }

        &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; EnsureReferenceToExpectedWeb(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPSite&lt;/SPAN&gt; site,
            &lt;SPAN style="COLOR: #0000ff"&gt;ref&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web,
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; expectedWebUrl)
        {
            &lt;SPAN style="COLOR: #2b91af"&gt;Debug&lt;/SPAN&gt;.Assert(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(expectedWebUrl) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (web == &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;)
            {
                web = site.OpenWeb(expectedWebUrl);
            }
            &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(
                web.ServerRelativeUrl,
                expectedWebUrl,
                &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) != 0)
            {
                web.Dispose();

                web = site.OpenWeb(expectedWebUrl);
            }
        }

        &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; Import(
            &lt;SPAN style="COLOR: #2b91af"&gt;SPWeb&lt;/SPAN&gt; web,
            &lt;SPAN style="COLOR: #2b91af"&gt;DataRow&lt;/SPAN&gt; row)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageUrlName = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)row[&lt;SPAN style="COLOR: #a31515"&gt;"PageUrlName"&lt;/SPAN&gt;];

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageLayoutUrl =
                &lt;SPAN style="COLOR: #a31515"&gt;"_catalogs/masterpage/"&lt;/SPAN&gt; + (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)row[&lt;SPAN style="COLOR: #a31515"&gt;"PageLayout"&lt;/SPAN&gt;];

            &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; pageTitle = &lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (row.IsNull(&lt;SPAN style="COLOR: #a31515"&gt;"Title"&lt;/SPAN&gt;) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
            {
                pageTitle = (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;)row[&lt;SPAN style="COLOR: #a31515"&gt;"Title"&lt;/SPAN&gt;];

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (pageTitle.Length == 255)
                {
                    &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogWarning(
                        &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                        &lt;SPAN style="COLOR: #a31515"&gt;"The title specified for the page ({0}) may have been"
&lt;/SPAN&gt;                            + &lt;SPAN style="COLOR: #a31515"&gt;" truncated, since it is exactly 255 characters."&lt;/SPAN&gt;,
                        pageUrlName);
                }
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page = &lt;SPAN style="COLOR: #2b91af"&gt;SharePointPublishingHelper&lt;/SPAN&gt;.EnsurePage(
                web,
                pageUrlName,
                pageTitle,
                pageLayoutUrl);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; skipPageConfiguration =
                CheckIfPageImportShouldBeSkipped(
                    page);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (skipPageConfiguration == &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #2b91af"&gt;SharePointPublishingHelper&lt;/SPAN&gt;.EnsurePageIsCheckedOutToMe(
                page);

            page.Title = pageTitle;

            &lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;DataColumn&lt;/SPAN&gt; column &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; row.Table.Columns)
            {
                &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; columnName = column.ColumnName;

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.Compare(
                    columnName,
                    &lt;SPAN style="COLOR: #a31515"&gt;"WebUrl"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;continue&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(
                    columnName,
                    &lt;SPAN style="COLOR: #a31515"&gt;"PageUrlName"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;continue&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(
                    columnName,
                    &lt;SPAN style="COLOR: #a31515"&gt;"PageLayout"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;continue&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(
                    columnName,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Title"&lt;/SPAN&gt;,
                    &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.OrdinalIgnoreCase) == 0)
                {
                    &lt;SPAN style="COLOR: #0000ff"&gt;continue&lt;/SPAN&gt;;
                }

                &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (row.IsNull(columnName) == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
                {
                    page.ListItem[columnName] = row[columnName];
                }
            }

            page.Update();

            &lt;SPAN style="COLOR: #2b91af"&gt;SharePointPublishingHelper&lt;/SPAN&gt;.PublishPage(
                page,
                &lt;SPAN style="COLOR: #a31515"&gt;"Published by Fabrikam.Demo.Tools.ImportPages.PageImporter."&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;bool&lt;/SPAN&gt; CheckIfPageImportShouldBeSkipped(
            &lt;SPAN style="COLOR: #2b91af"&gt;PublishingPage&lt;/SPAN&gt; page)
        {
            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #2b91af"&gt;SharePointPublishingHelper&lt;/SPAN&gt;.IsPageApproved(page))
            {
                &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;"Skipping import of page ({0}/{1}) because the page"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" is approved."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.Url);

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isPageCheckedOut =
                &lt;SPAN style="COLOR: #2b91af"&gt;SharePointPublishingHelper&lt;/SPAN&gt;.IsPageCheckedOut(
                    page);

            &lt;SPAN style="COLOR: #0000ff"&gt;bool&lt;/SPAN&gt; isPageCheckedOutToMe =
                &lt;SPAN style="COLOR: #2b91af"&gt;SharePointPublishingHelper&lt;/SPAN&gt;.IsPageCheckedOutToMe(
                    page);

            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (isPageCheckedOut == &lt;SPAN style="COLOR: #0000ff"&gt;true
&lt;/SPAN&gt;                &amp;amp;&amp;amp; isPageCheckedOutToMe == &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;)
            {
                &lt;SPAN style="COLOR: #2b91af"&gt;Logger&lt;/SPAN&gt;.LogWarning(
                    &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;.InvariantCulture,
                    &lt;SPAN style="COLOR: #a31515"&gt;"Skipping import of page"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" ({0}/{1}) because the page is already checked"
&lt;/SPAN&gt;                        + &lt;SPAN style="COLOR: #a31515"&gt;" out to somebody else."&lt;/SPAN&gt;,
                    page.ListItem.Web.Url,
                    page.Url);

                &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;;
            }

            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;;
        }
    }
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;I'll cover the details of the &lt;CODE&gt;SharePointPublishingHelper&lt;/CODE&gt; class in a &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;separate post&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9904911" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jjameson/archive/tags/MOSS+2007/default.aspx">MOSS 2007</category></item></channel></rss>