<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SPSherm.MyBlog &#187; Programming</title>
	<atom:link href="http://spsherm.uptempoconsulting.com/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://spsherm.uptempoconsulting.com</link>
	<description>SharePoint, of course.</description>
	<lastBuildDate>Mon, 03 Oct 2011 03:01:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Event Receivers</title>
		<link>http://spsherm.uptempoconsulting.com/2010/01/event-receivers/</link>
		<comments>http://spsherm.uptempoconsulting.com/2010/01/event-receivers/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 17:44:13 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>
		<category><![CDATA[Event Receivers]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=164</guid>
		<description><![CDATA[Two excellent resources for ramping up on SharePoint 2007 event receivers. http://blogs.msdn.com/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?ID=69]]></description>
			<content:encoded><![CDATA[<p>Two excellent resources for ramping up on SharePoint 2007 event receivers.</p>
<ul>
<li><a href="http://blogs.msdn.com/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx">http://blogs.msdn.com/brianwilson/archive/2007/03/05/part-1-event-handlers-everything-you-need-to-know-about-microsoft-office-sharepoint-portal-server-moss-event-handlers.aspx</a></li>
<li><a href="http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?ID=69">http://www.davehunter.co.uk/Blog/Lists/Posts/Post.aspx?ID=69</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2010/01/event-receivers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Registering a CSS File in SharePoint</title>
		<link>http://spsherm.uptempoconsulting.com/2008/06/registering-a-css-file-in-sharepoint/</link>
		<comments>http://spsherm.uptempoconsulting.com/2008/06/registering-a-css-file-in-sharepoint/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 00:26:50 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[WCM]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=135</guid>
		<description><![CDATA[I have a custom publishing site definition. It was, of course, based off the default publishing site definition. I re-organized some features around, and added custom versions of required features just so I could control everything a little more to my liking. Anytime we do this, however, we run the risk of &#8220;what did I break?&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I have a custom publishing site definition. It was, of course, based off the default publishing site definition. I re-organized some features around, and added custom versions of required features just so I could control everything a little more to my liking. Anytime we do this, however, we run the risk of &#8220;what did I break?&#8221; syndrome.</p>
<p>One of my clients was using the Content Editor Web Part on one of her page layouts (instead of using a RichHtmlField &#8211; long story). She noted that she could not select the &#8220;Use Predefined Table Format&#8221; in the Table Editor web dialog. Hmmm&#8230; I didn&#8217;t do anything specific to <em>disable</em> that capability, so I needed to do some digging.</p>
<p>Since I was using a custom publishing site definition, I needed to determine if this behaviour was happening with the default Publishing Portal definition. Sure enough, adding a CEWP to the home page of the Publishing Portal yielded the same effect: I could not use the predefined table formats. I then check the Press Releases default page, which does have a RichHtmlField for me to play with. I <em>can</em> use the predefined formats here. I proceeded to add a CEWP to the zone at the bottom of the page, and here I can also use the predefined formats. Interesting&#8230;</p>
<p>I fired up my favourite search engine, and came across this posting from Microsoft: <a title="http://support.microsoft.com/kb/948320" href="http://support.microsoft.com/kb/948320">How to enable the &#8220;Use Predefined Table Format&#8221; setting when you use a Windows SharePoint Services template in SharePoint Server 2007</a>. Cool! But note the location of the CSS: /_LAYOUTS/1033/STYLES/HtmlEditorTableFormats.css. In my case, I have the French language pack installed, which means I have to account for the 1036 LCID also.</p>
<p>I checked the master pages and page layouts that PublishingLayouts feature use, and note that there is <em>not</em> a reference to that CSS. Nor is it in the page layouts found in the PublishingResources feature. What gives? What&#8217;s the correct syntax?</p>
<p>No matter. I&#8217;ll just add a link to the CSS by building out the path to the right LCID folder, using something like System.Threading.Thread.CurrentThread.CurrentUICulture to get the LCID. After some frustrations (which I won&#8217;t get into here), I quickly realized that this would not work in my scenario (Canadian English is not 1033) either.</p>
<p>I looked at the source code for my out-of-the-box publishing portal (the Press Releases page). I noticed that core.css also comes from the LAYOUTS/1033/Styles folder. Some more digging, and I realized that I did not need to specify the full path, like this example taken from BlueBand.master:</p>
<pre class="brush: xml; title: ; notranslate">&lt;SharePoint:CssRegistration name=&quot;&lt;% $SPUrl:~sitecollection/Style Library/~language/Core Styles/controls.css %&gt;&quot; runat=&quot;server&quot;/&gt;</pre>
<p>but instead I needed simply this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;SharePoint:CssRegistration name=&quot;HtmlEditorTableFormats.css&quot; runat=&quot;server&quot; /&gt;</pre>
<p>and SharePoint takes care of the rest, building out the path to the appropriate Styles as required, like this:  </p>
<pre class="brush: xml; title: ; notranslate">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/_layouts/1033/styles/Htmleditortableformats.css?rev=guYGdUBUxQit03E2jhSdvA&quot; /&gt;</pre>
<p><a title="http://blog.mastykarz.nl/tag/rich-text-editor/" href="http://blog.mastykarz.nl/tag/rich-text-editor/">Here is a great post which talks about what&#8217;s going on</a>, and what renders HtmlEditorTableFormats links. It explains why I could not find it in any of the master pages or page layouts: the RichHtmlField web control inserts CSS links to HtmlEditorTableFormats.css and HtmlEditorCustomStyles.css OnLoad() . &lt;groan! /&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2008/06/registering-a-css-file-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ContentTypeID Syntax/Structure</title>
		<link>http://spsherm.uptempoconsulting.com/2008/02/contenttypeid-syntaxstructure/</link>
		<comments>http://spsherm.uptempoconsulting.com/2008/02/contenttypeid-syntaxstructure/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 22:24:16 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>
		<category><![CDATA[ContentTypeID]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=141</guid>
		<description><![CDATA[There is a more efficient way to do content type IDS than we have done in the past: http://msdn2.microsoft.com/en-us/library/aa543822.aspx Say we wanted to inherit from &#8220;Page&#8221;, our content type used to look something this (I&#8217;ve split up the lines so it will display properly): 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900 188024C0FF7F45CFB85EBB43980DACF5 Meaning, inherit from &#8220;Page&#8221; (the red part), include a [...]]]></description>
			<content:encoded><![CDATA[<p>There is a more efficient way to do content type IDS than we have done in the past: <a title="http://msdn2.microsoft.com/en-us/library/aa543822.aspx" href="http://msdn2.microsoft.com/en-us/library/aa543822.aspx" target="_blank">http://msdn2.microsoft.com/en-us/library/aa543822.aspx</a></p>
<p>Say we wanted to inherit from &#8220;Page&#8221;, our content type used to look something this (I&#8217;ve split up the lines so it will display properly):</p>
<pre><span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5</span></pre>
<p>Meaning, inherit from &#8220;Page&#8221; (the red part), include a delimiter (<strong>00</strong>), and then append a GUID.</p>
<p>If we then wanted to extend this content type, we could do this:</p>
<pre><span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #000000;">00</span></strong>DFA39D91C06D48BDBC415E7CE80A95CD</span></pre>
<p>And so on&#8230; You can imagine how hairy-scary the ContentTypeIDs can get if you wanted your inheritance to go a few levels deep.</p>
<p>As per the article, there is a more efficient way; the second ContentTypeID above could become:</p>
<pre><span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">01</span></strong></span></pre>
<p>Where the tail <strong>01 </strong>is the extended content type. Thus, we could have:</p>
<pre><span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">01</span></strong></span>
<span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">02</span></strong></span>
<span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">03</span></strong></span></pre>
<p>etc.</p>
<p>And then to extend from either of these:</p>
<pre><span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">01<span style="color: #00ff00;">01</span></span></strong></span>
<span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">01<span style="color: #00ff00;">02</span></span></strong></span>
<span style="color: #ff0000;">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39</span><strong>00</strong>
<span style="color: #0000ff;">188024C0FF7F45CFB85EBB43980DACF5<strong><span style="color: #ff6600;">02<span style="color: #00ff00;">01</span></span></strong></span></pre>
<p>etc.</p>
<p>IMO, this makes the ContentTypeIDs much easier to work with (and read), and we run less risk of running into URL length issues within SharePoint.</p>
<p>PS. The GUIDs used in the above examples have been changed to protect the coder. Any resemblance to any existing ContentTypeIDs are purely coincidental.</p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2008/02/contenttypeid-syntaxstructure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Web Parts can &#8220;break&#8221; Variations process.</title>
		<link>http://spsherm.uptempoconsulting.com/2007/10/custom-web-parts-can-break-variations-process/</link>
		<comments>http://spsherm.uptempoconsulting.com/2007/10/custom-web-parts-can-break-variations-process/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 19:39:24 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>
		<category><![CDATA[Variations]]></category>
		<category><![CDATA[Web Parts]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=133</guid>
		<description><![CDATA[Ok, the title is vague, but there&#8217;s only so much I can put in a title, right? As per MSDN&#8217;s documentation for the Microsoft.SharePoint.WebPartPages class and Andrew&#8217;s post on v3 web parts, we should now inherit from System.Web.UI.WebControls.WebParts.WebPart when we are building custom web parts, except in the four scenarios he mentions (repeating here for my [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, the title is vague, but there&#8217;s only so much I can put in a title, right? <img src='http://www.uptempoconsulting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>As per MSDN&#8217;s documentation for the <a href="http://msdn2.microsoft.com/en-us/library/ms461685.aspx" target="_blank">Microsoft.SharePoint.WebPartPages</a> class and <a href="http://andrewconnell.com/blog/archive/2006/05/20/3131.aspx" target="_blank">Andrew&#8217;s post on v3 web parts</a>, we should now inherit from <a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpart(VS.80).aspx" target="_blank">System.Web.UI.WebControls.WebParts.WebPart</a> when we are building custom web parts, <em>except </em>in the four scenarios he mentions (repeating here for my own records):</p>
<ol>
<li>Cross page connections</li>
<li>Connections between Web Parts that are outside of a Web Part zone</li>
<li>Client-side connections (Web Part Page Services Component)</li>
<li>A data caching infrastructure that allows caching to the content database</li>
</ol>
<p>However, I came across a situation recently whereby a very simple custom web part (all it did was render a &#8220;Get Adobe Acrobat&#8221; link, essentially) threw a SharePoint error to the screen when used in conjunction with Variations. Here&#8217;s the steps to replicate:</p>
<ol>
<li>
<div>Create your custom web part, inheriting from <code>System.Web.UI.WebControls.WebParts.WebPart</code>. Keep it simple; &#8220;Hello World&#8221; is fine.</div>
</li>
<li>
<div>Build/deploy, etc. Use it in one of your page layouts. Of course, Variations has to be set up/enabled, <strong>but turn off automatic creation of target pages</strong>.</div>
</li>
<li>
<div>Once the new page has been created, select either &#8220;Update Variations&#8221; from the Tools menu.</div>
</li>
<li>
<div>SharePoint will start a long running operation, and then eventually throw an error to the screen.</div>
</li>
<li>
<div>The target variation page is actually created, but this error message is annoying, and probably discomforting to the authors.</div>
</li>
</ol>
<p>It took me a while to figure out what was causing the problem. I finally had a thorough look in the SharePoint logs, and found the message that told me the cause. If you are using <a href="http://www.spsdev.com/ulsreader.aspx" target="_blank">SpsDev&#8217;s ULS Log Reader</a>, filter by Area:CMS, Category:Publishing, or just look for the message &#8220;Unable to cast&#8221;. The relevant part of the message is:</p>
<p><code>Unable to cast object of type '******.Website.SharePoint.WebParts.AdobeLinkWebPart' to type 'Microsoft.SharePoint.WebPartPages.WebPart'</code></p>
<p>Um, what? Why does it want to do that? So&#8230;</p>
<ol>
<li>
<div>Re-write the web part to inherit from <code>Microsoft.SharePoint.WebPartPages.WebPart</code>.</div>
</li>
<li>
<div>Create a new DWP file to match.</div>
</li>
<li>
<div>Deploy, etc; re-test.</div>
</li>
<li>
<div>Of course, it works without the error.</div>
</li>
</ol>
<p>Microsoft&#8217;s own web parts that inherit from <code>System.Web.UI.WebControls.WebParts.WebPart</code> don&#8217;t seem to have the same behaviour. Nevertheless, I believe this to be a bug, but one that you should know about when using custom web parts in conjunction with Variations.</p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2007/10/custom-web-parts-can-break-variations-process/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PortalSiteMapProvider Properties: IncludePages, DynamicChildLimit</title>
		<link>http://spsherm.uptempoconsulting.com/2007/10/portalsitemapprovider-properties-includepages-dynamicchildlimit/</link>
		<comments>http://spsherm.uptempoconsulting.com/2007/10/portalsitemapprovider-properties-includepages-dynamicchildlimit/#comments</comments>
		<pubDate>Tue, 23 Oct 2007 02:51:32 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>
		<category><![CDATA[Navigation]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=127</guid>
		<description><![CDATA[The PortalSiteMapProvider class is the base provider used by the four default &#8220;CMS&#8221; SiteMapProviders: GlobalNavSiteMapProvider CombinedNavSiteMapProvider CurrentNavSiteMapProvider CurrentNavSiteMapProviderNoEncode That is, all of these SiteMapProviders use the same base code to generate a data source, but their &#8220;output&#8221; differs slightly due to the different attributes that are applied. Recently, we wanted to filter out the pages [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://msdn2.microsoft.com/en-us/library/ms582344.aspx" target="_blank">PortalSiteMapProvider</a> class is the base provider used by the four default &#8220;CMS&#8221; SiteMapProviders:</p>
<ul>
<li>GlobalNavSiteMapProvider</li>
<li>CombinedNavSiteMapProvider</li>
<li>CurrentNavSiteMapProvider</li>
<li>CurrentNavSiteMapProviderNoEncode</li>
</ul>
<p>That is, all of these SiteMapProviders use the same base code to generate a data source, but their &#8220;output&#8221; differs slightly due to the different attributes that are applied.</p>
<p>Recently, we wanted to filter out the pages from showing up in our left-navigation. You can do this at the rendering stage, but since the PortalSiteMapProvder gives us an <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.publishing.navigation.portalsitemapprovider.includepages.aspx" target="_blank">IncludePages</a> property, we can simply create a new entry in <code>web.config</code> for our &#8220;custom&#8221; provider, like this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;add name=&quot;CurrentNavNoPagesSiteMapProvider&quot; description=&quot;CMS provider for Current navigation&quot; type=&quot;Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; NavigationType=&quot;Current&quot; EncodeOutput=&quot;true&quot; IncludePages=&quot;Never&quot; /&gt;</pre>
<p>By default, there is also a 50 returned-items limit; we can set the <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.publishing.navigation.portalsitemapprovider.dynamicchildlimit.aspx" target="_blank">DynamicChildLimit</a> to &#8220;0&#8243; to override this.</p>
<pre class="brush: xml; title: ; notranslate">&lt;add name=&quot;CurrentNavNoLimitSiteMapProvider&quot; description=&quot;CMS provider for Current navigation&quot; type=&quot;Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; NavigationType=&quot;Current&quot; EncodeOutput=&quot;true&quot; DynamicChildLimit=&quot;0&quot; /&gt;</pre>
<p>Of course, you can combine the different properties to come up with a combination you need. The next thing we would need to do is reference these new providers, and voila!</p>
<p>And if you haven&#8217;t read Chris Richard&#8217;s series of articles about <a href="http://blogs.msdn.com/ecm/archive/2007/02/10/moss-navigation-deep-dive-part-1.aspx" target="_blank">MOSS Navigation</a> and <a href="http://blogs.msdn.com/ecm/archive/2007/05/23/increased-performance-for-moss-apps-using-the-portalsitemapprovider.aspx" target="_blank">how to get better performance using the PortalSiteMapProvider</a>, you really should&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2007/10/portalsitemapprovider-properties-includepages-dynamicchildlimit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SPFormContext</title>
		<link>http://spsherm.uptempoconsulting.com/2007/08/spformcontext/</link>
		<comments>http://spsherm.uptempoconsulting.com/2007/08/spformcontext/#comments</comments>
		<pubDate>Sat, 18 Aug 2007 11:06:31 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=102</guid>
		<description><![CDATA[Argh, Sezai beat me to this post about SPFormContext and SPControlMode by a few hours! I have to admit my sentiment is the same as his - I&#8217;m super stoked to have found this class. Oftentimes, we need some code to execute, but only in the &#8220;published&#8221; state (old MCMS terminology). We might want a component to run [...]]]></description>
			<content:encoded><![CDATA[<p>Argh, <a title="Sezai's Blog" href="/sezai/" target="Sezai">Sezai</a> beat me to this post about <a title="Sezai: FormContext" href="/sezai/archive/2007/08/29/spcontext-current-formcontext.aspx" target="Sezai">SPFormContext and SPControlMode</a> by a few hours! I have to admit my sentiment is the same as his - I&#8217;m super stoked to have found this <a title="MSDN" href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spformcontext.aspx" target="MSDN">class</a>.</p>
<p>Oftentimes, we need some code to execute, but only in the &#8220;published&#8221; state (old MCMS terminology). We might want a component to run certain logic, but it&#8217;s really only relevant if the page is in a live/published state. In other words, the logic does not matter when we are viewing the page as authors, editors, or administrators &#8211; we either don&#8217;t care, or we just don&#8217;t want the logic to execute. (Could be vice-versa; execute some code only if we&#8217;re NOT in published state.) </p>
<p>For example, my UE developer asked me to hide all mark-up surrounding a publishing site field. After all, if there isn&#8217;t any content to display, then why bother rendering the DIV tags, or possibly some heading (H) tags? By performing a check for content, we can avoid a situation where a &#8220;News&#8221; header appears, but there&#8217;s nothing it. So, I created a control that wraps around all the mark-up that comprises a UI element/section. If there is no content, the control, and its children, will not render. However, we <em>always</em> want it to render in editing mode; otherwise, we can&#8217;t add content back in! </p>
<p>This scenario was fairly simple to solve: write a control that inherits from <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.basefieldcontrol.aspx">Microsoft.SharePoint.WebControls.BaseFieldControl</a>, and only run the code to check for content if we are in published mode:</p>
<pre class="brush: csharp; title: ; notranslate">if (this.ControlMode == SPControlMode.Display)
{
    // do something.
} 
</pre>
<p>This is all fine and well, since BaseFieldControl can be traced back to <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.formcomponent.aspx" target="_blank">Microsoft.SharePoint.WebControls.FormComponent</a>, which is the last point in the hierarchy that has the ControlMode property. If you go further up the tree, <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spcontrol.aspx">Microsoft.SharePoint.WebControls.SPControl</a> <em>does not</em> have the ControlMode property&#8230; I have no idea why not.</p>
<p>Why is this a problem? Well, my UE developer wanted to check <em>multiple</em> fields. I could not inherit from BaseFieldControl any longer, since it is meant to represent a single field, not multiple fields. So I decided to inherit from SPControl instead. (In the end, I probably could have inherited from <span style="text-decoration: underline;">System.Web.UI.WebControls.WebControl</span>, but it seemed to make sense to stick within the SharePoint namespace.)</p>
<p>After much searching, including spending a lot of time in Reflector, specifically searching for <span style="text-decoration: underline;">Microsoft.SharePoint.Publishing.WebControls.PageDisplayMode</span> and <span style="text-decoration: underline;">Microsoft.SharePoint.Publishing.WebControls.SPControlMode</span> (both enums), I <em>finally</em> came across this *internal* and *sealed* class in the <span style="text-decoration: underline;">Microsoft.Office.Server.Utilities</span> namespace: <strong>PageUtility</strong>. But we can&#8217;t use it! However, inside PageUtility is a method called <strong>IsPageCurrentlyInSomeEditMode()</strong> (nice, huh?) and more importantly, a property called <strong>FormContextMode</strong>, which returns an SPControlMode object&#8230; interesting.</p>
<p>Looking closer, I saw a line (similar to) SPContext.Current.FormContext.FormMode (!!). As Sezai pointed out, FormContext is an <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spformcontext.aspx">SPFormContext</a> object, which contains two (potentially) very useful properties: <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spformcontext.formmode.aspx">FormMode</a> and <a href="http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spformcontext.fieldcontrolcollection.aspx">FieldControlCollection</a>: </p>
<ul>
<li>
<div><strong>FormMode</strong> gives us a way to check against the enum SPControlMode to determine what &#8220;state&#8221; we&#8217;re in.</div>
</li>
<li>
<div><strong>FieldControlCollection</strong> returns an ArrayList of field controls (skipping all the other server controls on the page).</div>
</li>
</ul>
<p>Now, I can do a check like this: </p>
<pre class="brush: csharp; title: ; notranslate">if (SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
    // do something.
}</pre>
<p>Also, with <strong>FieldControlCollection</strong>, I can iterate over the list of defined fields for the current page, looking for some specified fields. Nice! SPFormContext is definitely useful, and I&#8217;m surprised there hasn&#8217;t been any postings about it until Sezai came along (try searching for SPFormContext&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2007/08/spformcontext/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SPSite vs. SPWeb</title>
		<link>http://spsherm.uptempoconsulting.com/2007/08/spsite-vs-spweb/</link>
		<comments>http://spsherm.uptempoconsulting.com/2007/08/spsite-vs-spweb/#comments</comments>
		<pubDate>Fri, 17 Aug 2007 12:06:34 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SP2007]]></category>
		<category><![CDATA[Reference]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=72</guid>
		<description><![CDATA[We had a discussion amongst the developers in our group recently: what is an SPSite, what is an SPWeb, and what is the difference? Which once should I work with in my code? Looking at MSDN for the SPSite class, we see this description: SPSite Represents a collection of sites on a virtual server, including [...]]]></description>
			<content:encoded><![CDATA[<p>We had a discussion amongst the developers in our group recently: what is an SPSite, what is an SPWeb, and what is the difference? Which once should I work with in my code? Looking at MSDN for the SPSite class, we see this description:</p>
<p><strong>SPSite</strong> Represents a collection of sites on a virtual server, including a top-level site and all its subsites. Each SPSite object, or site collection, is represented within an SPSiteCollection object that consists of the collection of all site collections on the virtual server.</p>
<p>Mmmmm&#8230; ooo-kay&#8230; what does that mean?</p>
<p>The <strong>SPWeb</strong> class simply says:</p>
<p>Represents a SharePoint Web site.</p>
<p>Wow. Enlightening. Looking back to my first experiences working with the SharePoint object model in WSS2/SPS2003, I must say this was one of the more confusing points for me. And it&#8217;s easy to see why it can be such a confusing/frustrating experience for developers working with the API for the first time. Now that I&#8217;ve worked with WSS3/MOSS code more closely, specifically with Publishing Sites where there are many child &#8220;sites&#8221;, I&#8217;ve come to understand the world of SPSite and SPWeb objects.</p>
<p>The problem lies with the difference in terms used between the SharePoint user-interface and the object model. When we are speaking to end-users, they are familiar with the term &#8220;creating SharePoint team sites&#8221;. However, everytime you create a &#8220;site&#8221; from the UI, an SPWeb object was created.</p>
<p>It doesn&#8217;t help that the MSDN documentation uses the following type of naming conventions in their code samples:</p>
<pre class="brush: csharp; title: ; notranslate">
SPSite mySiteCollection = new SPSite(&quot;http://servername/&quot;);
SPWeb mySite = mySiteCollection.AllWebs[&quot;Site_Name&quot;];
SPWeb myRootSite = mySiteCollection.RootWeb;
</pre>
<p>For me, it would have been much clearer if they wrote something like this instead:</p>
<pre class="brush: csharp; title: ; notranslate">
SPSite mySite = new SPSite(&quot;http://servername/&quot;);
SPWeb myWeb = mySite.AllWebs[&quot;Site_Name&quot;];
SPWeb myRootWeb = mySite.RootWeb;
</pre>
<p>While the description for SPSite may be valid, a typical SharePoint application web site only has one top-level site collection. Therefore, in this url <code>http://servername/site1/site1a/</code>, there are actually three SPWeb objects, and only one SPSite object.</p>
<pre class="brush: csharp; title: ; notranslate">
SPSite site1 = new SPSite(&quot;http://servername/site1/&quot;);
SPSite site1a = new SPSite(&quot;http://servername/site1/site1a/&quot;);
bool sitesAreEqual = site1.Equals(site1a);  // sitesAreEqual should evaluate to true.

SPWeb web1 = site1.OpenWeb();
SPWeb web1a = site1a.OpenWeb();
SPWeb rootWeb = site1.RootWeb; // or site1a.RootWeb; would return same instance.
</pre>
<p>See the <code>SPSite.OpenWeb()</code> method for more examples: <a href="http://msdn2.microsoft.com/en-us/library/ms474633.aspx">http://msdn2.microsoft.com/en-us/library/ms474633.aspx</a>.</p>
<p>SPSite itself is not a &#8220;collection&#8221; in the sense that comes from CollectionBase, for example. In fact, both SPSite and SPWeb inherit directly from System.Object. Therefore, to use a name such as mySiteCollection is confusing/misleading.</p>
<p>The key thing to keep in mind is that as developers, we need to use the technically accurate terms when speaking with each other (even if MSDN doesn&#8217;t), and reserve the marketing/UI terms when speaking with people who would never see the object model. (Note: there are examples of these kinds of terminology differences all over the place in SharePoint 2007.)</p>
<p>I hope this clears things up a bit&#8230;if you find something that is not correct/accurate, please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2007/08/spsite-vs-spweb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSDN Link: SharePoint Best Practices &#8211; Disposing WSS Objects</title>
		<link>http://spsherm.uptempoconsulting.com/2007/08/msdn-link-sharepoint-best-practices-disposing-wss-objects/</link>
		<comments>http://spsherm.uptempoconsulting.com/2007/08/msdn-link-sharepoint-best-practices-disposing-wss-objects/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 23:28:52 +0000</pubDate>
		<dc:creator>Sherman</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[SP2007]]></category>

		<guid isPermaLink="false">http://spsherm.uptempoconsulting.com/?p=40</guid>
		<description><![CDATA[ Might as well dive right in and make the inaugural posting useful&#8230;  Anyone who&#8217;s done some development work with SharePoint probably already knows about this article, but I wanted to place it here for reference: Best Practices: Using Disposable Windows SharePoint Services Objects Review the article very carefully&#8230; there are things we do often such [...]]]></description>
			<content:encoded><![CDATA[<p> <em>Might as well dive right in and make the inaugural posting useful&#8230;</em> </p>
<p>Anyone who&#8217;s done some development work with SharePoint probably already knows about this article, but I wanted to place it here for reference:</p>
<p><a href="http://msdn2.microsoft.com/en-us/library/aa973248.aspx" target="_blank">Best Practices: Using Disposable Windows SharePoint Services Objects</a></p>
<p>Review the article very carefully&#8230; there are things we do often such as getting to an SPSite&#8217;s RootWeb, like this:</p>
<pre class="brush: csharp; light: true; title: ; notranslate">SPSite site = SPControl.GetContextSite(HttpContext.Current);
SPWeb rootWeb = site.RootWeb;</pre>
<p>In this case, it&#8217;s pretty obvious (based on the article) that we need to call:</p>
<pre class="brush: csharp; light: true; title: ; notranslate">rootWeb.Dispose();</pre>
<p>However, if you were to access a property like this:</p>
<pre class="brush: csharp; light: true; title: ; notranslate">string rootWebTitle = site.RootWeb.Title;</pre>
<p>the article states that you should call</p>
<pre class="brush: csharp; light: true; title: ; notranslate">site.RootWeb.Dispose();</pre>
<p>which is not obvious, in my opinion. So to keep/ensure your SharePoint site/application runs as smoothly as possible, clean up after yourself! </p>
<p>EDIT (September 2008):</p>
<p>This is kind of old news by now, but here is another article from Andrew Woodward (which references 3 articles other than MSDN). Worthy to note that we need to properly Close() all PublishingWeb objects as well.<br />
<a href="http://www.21apps.com/2008/02/sharepoint-ate-all-my-memory-dealing.html">http://www.21apps.com/2008/02/sharepoint-ate-all-my-memory-dealing.html</a></p>
<p>Roger Lamb&#8217;s blog has some really good examples. Also make sure to read the comments.<br />
<a href="http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx">http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx</a></p>
<p>Stefan Gossner gives a pretty good in-depth look at how memory is consumed.<br />
<a href="http://blogs.technet.com/stefan_gossner/archive/2007/11/26/dealing-with-memory-pressure-problems-in-moss-wss.aspx">http://blogs.technet.com/stefan_gossner/archive/2007/11/26/dealing-with-memory-pressure-problems-in-moss-wss.aspx</a></p>
<p>Finally, a post about application pool/worker process recycling and SharePoint.<br />
<a href="http://blogs.msdn.com/steveshe/archive/2007/12/17/overlapped-recycling-and-sharepoint-why-sharepoint-requires-it.aspx">http://blogs.msdn.com/steveshe/archive/2007/12/17/overlapped-recycling-and-sharepoint-why-sharepoint-requires-it.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://spsherm.uptempoconsulting.com/2007/08/msdn-link-sharepoint-best-practices-disposing-wss-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

