<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Stephen Vick&#039;s Blog</title>
	<atom:link href="http://stephenvick.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://stephenvick.wordpress.com</link>
	<description>Just another SharePoint blog</description>
	<lastBuildDate>Tue, 10 May 2011 18:58:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='stephenvick.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/c69f0c8aa266f2ae14dec95ab2b12046?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Stephen Vick&#039;s Blog</title>
		<link>http://stephenvick.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://stephenvick.wordpress.com/osd.xml" title="Stephen Vick&#039;s Blog" />
	<atom:link rel='hub' href='http://stephenvick.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Pokemon Exception Handling</title>
		<link>http://stephenvick.wordpress.com/2010/08/02/pokemon-exception-handling/</link>
		<comments>http://stephenvick.wordpress.com/2010/08/02/pokemon-exception-handling/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 01:37:45 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[Parody]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/?p=121</guid>
		<description><![CDATA[Repeated exposure to sub-optimal code and a 7 year old son obsessed with Pokemon and here&#8217;s what you get: (If you don&#8217;t have a 7 year old boy and aren&#8217;t familiar with the song you can read and listen to YouTube&#8217;s offering in all it&#8217;s delicious cheesiness.)   Exception! (Gotta Catch em all)  (Pokemon theme [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=121&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Repeated exposure to sub-optimal code and a 7 year old son obsessed with Pokemon and here&#8217;s what you get:</p>
<p>(If you don&#8217;t have a 7 year old boy and aren&#8217;t familiar with the song you can read and listen to YouTube&#8217;s offering in all it&#8217;s delicious cheesiness.)</p>
<p><span style="text-align:center; display: block;"><a href="http://stephenvick.wordpress.com/2010/08/02/pokemon-exception-handling/"><img src="http://img.youtube.com/vi/JuYeHPFR3f0/2.jpg" alt="" /></a></span> </p>
<p><a href="http://www.youtube.com/watch?v=JuYeHPFR3f0"></a></p>
<h1>Exception! (Gotta Catch em all)</h1>
<p><em> (Pokemon theme song)</em></p>
<p>I wanna code the very best</p>
<p>Like no bug ever was</p>
<p>To catch them is my real test</p>
<p>To suppress them is my cause</p>
<p>I will travel across the land</p>
<p>Searching far and wide</p>
<p>Each exception to just ignore</p>
<p>The message that&#8217;s inside</p>
<p>Exception! (gotta catch em all) it’s you and me</p>
<p>I know it’s my destiny,</p>
<p>Exception! Oh you&#8217;re my best friend</p>
<p>But our code we must defend</p>
<p>Exception! (gotta catch em all) it&#8217;s sad but true</p>
<p>Our catch block will pull us through,</p>
<p>You breach me and I&#8217;ll teach you,</p>
<p>Exception! gotta catch&#8217;em all</p>
<p>Gotta catch em all</p>
<p>Yeah&#8230;</p>
<p>Every challenge along the way</p>
<p>With courage I will face.</p>
<p>I will battle every day</p>
<p>To claim my bug-free space.</p>
<p>&#8220;Finally&#8221;,</p>
<p>Don’t feel neglected</p>
<p>There&#8217;s no better theme.</p>
<p>We can expect the unexpected</p>
<p>A project manager’s dream!</p>
<p>Exception! (gotta catch em all) it’s you and me</p>
<p>I know it’s my destiny,</p>
<p>Exception!  Oh you&#8217;re my best friend</p>
<p>But our code we must defend</p>
<p>Exception! (gotta catch em all) it&#8217;s sad but true</p>
<p>Our catch block will pull us through,</p>
<p>You breach me and I&#8217;ll teach you,</p>
<p>Exception! gotta catch&#8217;em all</p>
<p>Gotta catch em all</p>
<p>Gotta catch em all</p>
<p>Gotta catch em all</p>
<p>Gotta catch em all</p>
<p>Yeah&#8230;</p>
<p>(Guitar Solo)</p>
<p>Exception! (gotta catch em all) it’s you and me</p>
<p>I know it’s my destiny,</p>
<p>Exception!  Oh you&#8217;re my best friend</p>
<p>But our code we must defend</p>
<p>Exception! (gotta catch em all) it&#8217;s sad but true</p>
<p>Our catch block will pull us through,</p>
<p>You breach me and I&#8217;ll teach you,</p>
<p>Exception! gotta catch&#8217;em all</p>
<p>Gotta catch em all</p>
<p>Exception!</p>
<p><img class="alignnone" title="Pokemon" src="http://www.daimi.au.dk/~andos/images/catchemall.jpg" alt="" width="470" height="501" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=121&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2010/08/02/pokemon-exception-handling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>

		<media:content url="http://www.daimi.au.dk/~andos/images/catchemall.jpg" medium="image">
			<media:title type="html">Pokemon</media:title>
		</media:content>
	</item>
		<item>
		<title>Proxy Layer</title>
		<link>http://stephenvick.wordpress.com/2010/08/02/proxy-layer/</link>
		<comments>http://stephenvick.wordpress.com/2010/08/02/proxy-layer/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 01:26:31 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[Parody]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/?p=117</guid>
		<description><![CDATA[Proxy Layer (To the tune Foxy Lady by Jimi Hendrix) Proxy Proxy You know you&#8217;re a cute little mediator Proxy You know you&#8217;re a sweet little interfacer Proxy I want a good response From your sweet service farm, oh You&#8217;ve got to be so light, so light Ooh, proxy layer I see you, heh, gettin&#8217; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=117&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Proxy Layer</h1>
<p><em>(To the tune Foxy Lady by Jimi Hendrix)</em></p>
<p>Proxy</p>
<p>Proxy</p>
<p>You know you&#8217;re a cute little mediator</p>
<p>Proxy</p>
<p>You know you&#8217;re a sweet little interfacer</p>
<p>Proxy</p>
<p>I want a good response</p>
<p>From your sweet service farm, oh</p>
<p>You&#8217;ve got to be so light, so light</p>
<p>Ooh, proxy layer</p>
<p>I see you, heh, gettin&#8217; in between</p>
<p>Proxy</p>
<p>You make me wanna do it asynchronously</p>
<p>Proxy</p>
<p>Ah, baby listen now</p>
<p>I&#8217;ve made up my mind yeah</p>
<p>I&#8217;m tired of wasting all my precious RAM</p>
<p>You&#8217;ve got to be so light, so light</p>
<p>Proxy layer</p>
<p>Here I come</p>
<p>I want a good response</p>
<p>From your sweet service farm, oh</p>
<p>You&#8217;ve got to be so light, so light</p>
<p>Ooh, proxy layer</p>
<p>Here I come baby</p>
<p>I&#8217;ll dependency inject ya</p>
<p>Ow proxy layer</p>
<p>You broker so good</p>
<p>Yeah, proxy</p>
<p>Yeah, give us some</p>
<p>Proxy</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=117&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2010/08/02/proxy-layer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>
	</item>
		<item>
		<title>SPDisposeCheck using Static Analysis</title>
		<link>http://stephenvick.wordpress.com/2010/01/08/spdisposecheck-using-static-analysis/</link>
		<comments>http://stephenvick.wordpress.com/2010/01/08/spdisposecheck-using-static-analysis/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 19:18:19 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SPDisposeCheck]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/?p=106</guid>
		<description><![CDATA[I&#8217;ve created a static analysis ruleset for SPDisposeCheck! SPDisposeCheck is a valuable tool developed by a small team within Microsoft Premier Support led by Roger Lamb that inspects an assembly to ensure that SharePoint API objects are properly disposed. Failure to properly dispose SharePoint API objects can cause memory leaks. The SPDisposeCheck tool can be downloaded [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=106&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a static analysis ruleset for SPDisposeCheck!</p>
<p>SPDisposeCheck is a valuable tool developed by a small team within Microsoft Premier Support led by Roger Lamb that inspects an assembly to ensure that SharePoint API objects are properly disposed. Failure to properly dispose SharePoint API objects can cause memory leaks. The SPDisposeCheck tool can be downloaded here:</p>
<p><a href="http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi">http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi</a></p>
<p>The source and compiled versions are available on CodePlex:</p>
<p><a href="http://spdisposecheckstatic.codeplex.com/">http://spdisposecheckstatic.codeplex.com/</a></p>
<p>Here are the steps to get this up and running on your SharePoint projects:</p>
<p>Copy the SPDisposeCheck SPDisposeCheckRules.dll and the SPDisposeCheck.exe to your local static analysis rules folder.</p>
<p>Example: <em>C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules</em></p>
<p>Open a SharePoint project and select <em>Project Properties</em>. Select the <em>Code Analysis</em> tab. You should see a new ruleset available called <em>SPDisposeCheck Rules</em>.</p>
<p>If you select <em>Enable Code Analysis on Builds</em> and <em>Treat Warnings as Error</em> for the SPDisposeCheck ruleset, developers should see any SPDispose errors on build for any code added to the solution.  </p>
<p><img src="http://stephenvick.files.wordpress.com/2010/01/010810_1918_spdisposech1.png?w=780" alt="" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=106&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2010/01/08/spdisposecheck-using-static-analysis/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>

		<media:content url="http://stephenvick.files.wordpress.com/2010/01/010810_1918_spdisposech1.png" medium="image" />
	</item>
		<item>
		<title>Run SPDisposeCheck as Build Task and Automated Unit Test</title>
		<link>http://stephenvick.wordpress.com/2010/01/06/run-spdisposecheck-as-build-task-and-automated-unit-test/</link>
		<comments>http://stephenvick.wordpress.com/2010/01/06/run-spdisposecheck-as-build-task-and-automated-unit-test/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 15:49:30 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SPDisposeCheck]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2010/01/06/run-spdisposecheck-as-build-task-and-automated-unit-test/</guid>
		<description><![CDATA[SPDisposeCheck is a valuable tool devloped by a small team within Microsoft Premier Support led by Roger Lamb that inspects an assembly to ensure that SharePoint API objects are properly disposed. Failure to properly dispose SharePoint API objects can cause memory leaks. The SPDisposeCheck tool can be downloaded here:  http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi  Running SPDisposeCheck has always been a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=96&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SPDisposeCheck is a valuable tool devloped by a small team within Microsoft Premier Support led by Roger Lamb that inspects an assembly to ensure that SharePoint API objects are properly disposed. Failure to properly dispose SharePoint API objects can cause memory leaks. The SPDisposeCheck tool can be downloaded here:</p>
<p> <a href="http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi">http://download.microsoft.com/download/B/4/D/B4D279A0-E159-40BF-A5E8-F49ABDBE95C7/SPDisposeCheck.msi</a></p>
<p> Running SPDisposeCheck has always been a manual procedure that a SharePoint architect or team lead has to make sure is run against all new code before a release; or worse run afterward in order to find a leak that is already in production. A preferable approach would be to add this to a unit test that can be part of a restrictive check-in policy in TFS to ensure no code, in which SharePoint API objects are not properly disposed, can be checked in. Here is how that can be accomplished:</p>
<p> Copy the SharePoint Dispose Check folder as a sub folder of the solution folder as demonstrated below:</p>
<p> <img src="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos1.png?w=780" alt="" /></p>
<p> <br />
 Find all projects under the solution that reference the Microsoft.SharePoint namespace and select properties on the project file. Select the Build Events tab and enter the commands below into the Post-build events text box for On Successful Build:</p>
<p> cd $(ProjectDir)</p>
<p>&#8220;..\SharePoint Dispose Check\SPDisposeCheck&#8221; &#8220;$(TargetPath)&#8221; &gt; &#8220;$(ProjectName)&#8221;.SPDisposeCheck.log</p>
<p>findstr /C:&#8221;Total Found:&#8221; &#8220;$(ProjectName)&#8221;.SPDisposeCheck.log</p>
<p> The Post-build events above will run the SPDisposeCheck tool against the compiled assembly outputting to a file that consists of the assembly name appended with .SPDisposeCheck.log. When the project is compiled the developer will see in the output window &#8220;Total Found: X&#8221; where X is the count of SPDisposeCheck errors in the assembly. See below:</p>
<p> <img src="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos2.png?w=780" alt="" /></p>
<p> Any value other than &#8220;Total Found: 0&#8243; means that a SPDisposeCheck error has been spotted. This is a good start, as developers can be instructed to look for this value but not good enough because it&#8217;s too easy to ignore. The next step would be to add this to a unit test which can be tied to a TFS restricted check in policy which cannot be ignored. To do this open the class file right click the class and select &#8220;Create Unit Tests&#8221;</p>
<p> <img src="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos3.png?w=780" alt="" /></p>
<p> Add a new unit test to the automatically generated unit tests as seen below: The text specified in the File.OpenText section should be replaced with the name of the assembly in question.</p>
<p><code><br />
///<br />
///A test to ensure SharePoint objects are properly disposed<br />
///<br />
[TestMethod()]<br />
public void SPDisposeCheckTest()<br />
{<br />
     StreamReader streamReader = File.OpenText(@"..\..\..\Intellinet.SharePoint.Utility\Intellinet.SharePoint.Utility.SPDisposeCheck.log");<br />
     String logFile = streamReader.ReadToEnd();<br />
     Assert.IsTrue(logFile.Contains("Total Found: 0"), logFile);<br />
}<br />
</code></p>
<p>This unit test will fail if the file generated by SPDisposeCheck has any value other than &#8220;Total Found: 0&#8243; and the contents of the file including the links to Roger&#8217;s examples of correcting the particular type of dispose defect can be viewed by the developer by clicking the failed unit test.</p>
<p><img src="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos4.png?w=780" alt="" /></p>
<p><img src="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos5.png?w=780" alt="" /><span style="font-family:Times New Roman;font-size:12pt;"><br />
</span></p>
<p>Since SPDisposeCheck is performing static analysis on the IL a better approach would be to reverse the SPDisposeCheck code and create a Static Analysis rule that would be available as one of the Static Analysis rulesets in TFS. Until that day this can be a very useful approach for SharePoint architects to control code quality and prevent SharePoint API dispose memory leaks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/96/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/96/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/96/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=96&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2010/01/06/run-spdisposecheck-as-build-task-and-automated-unit-test/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>

		<media:content url="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos1.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos2.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos3.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos4.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2010/01/010610_1549_runspdispos5.png" medium="image" />
	</item>
		<item>
		<title>Mystery Solved! (SPDisposeCheck Missing Memory Leaks?)</title>
		<link>http://stephenvick.wordpress.com/2009/03/20/mystery-solved-spdisposecheck-missing-memory-leaks/</link>
		<comments>http://stephenvick.wordpress.com/2009/03/20/mystery-solved-spdisposecheck-missing-memory-leaks/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 19:21:36 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2009/03/20/mystery-solved-spdisposecheck-missing-memory-leaks/</guid>
		<description><![CDATA[Evidently the reason some memory leaks from Roger Lamb&#8217;s blog didn&#8217;t appear in my SPDisposeCheck test have to do with some offending sample code being optimized out when compiled to release mode. When compiling to debug all the offending samples are identified by SPDisposeCheck. Note the differences identified in Reflector.     Release Version:   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=85&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Evidently the reason some memory leaks from Roger Lamb&#8217;s blog didn&#8217;t appear in my SPDisposeCheck test have to do with some offending sample code being optimized out when compiled to release mode. When compiling to debug all the offending samples are identified by SPDisposeCheck. Note the differences identified in Reflector.</p>
<p> <br />
 </p>
<p>Release Version:</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/03/032009-1917-mysterysolv1.png?w=780" alt="" /></p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 3/20/2009, 2:32 PM<br />
</span></p>
<p> <br />
 </p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>Debug Version:</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/03/032009-1917-mysterysolv2.png?w=780" alt="" /></p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 3/20/2009, 2:33 PM<br />
</span></p>
<p> <br />
 </p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>Thanks Matt Ranlett and Paul Andrew for solving the mystery.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=85&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2009/03/20/mystery-solved-spdisposecheck-missing-memory-leaks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>

		<media:content url="http://stephenvick.files.wordpress.com/2009/03/032009-1917-mysterysolv1.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2009/03/032009-1917-mysterysolv2.png" medium="image" />
	</item>
		<item>
		<title>SPDisposeCheck Missing Memory Leaks?</title>
		<link>http://stephenvick.wordpress.com/2009/03/19/spdisposecheck-missing-memory-leaks/</link>
		<comments>http://stephenvick.wordpress.com/2009/03/19/spdisposecheck-missing-memory-leaks/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 20:44:02 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2009/03/19/spdisposecheck-missing-memory-leaks/</guid>
		<description><![CDATA[Checking SharePoint memory leaks I came across this blog entry http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_300 describing different types of coding no-nos that can cause memory leaks. As an exercise I created an assembly with all these samples and ran SPDisposeCheck against the assembly and discovered several of the examples were NOT identified by SPDisposeCheck. I wonder If I could [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=82&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Checking SharePoint memory leaks I came across this blog entry <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#SPDisposeCheckID_300</a> describing different types of coding no-nos that can cause memory leaks. As an exercise I created an assembly with all these samples and ran SPDisposeCheck against the assembly and discovered several of the examples were NOT identified by SPDisposeCheck. I wonder If I could be missing something?<br />
 </p>
<p>The following examples were not identified:</p>
<p> <br />
 </p>
<p>CreatingSPSiteLeak</p>
<p>AllWebsForEachLeak</p>
<p>AllWebsIndexerLeak</p>
<p>SPLimitedWebPartManagerLeak</p>
<p>WebsLeak</p>
<p>PublishingWebCollectionLeak</p>
<p>GetVariationLeak</p>
<p>PersonalSiteLeak</p>
<p>SPSiteCollectionIndexerLeak</p>
<p>SPSiteCollectionForEachLeak</p>
<p>CrossMethodLeak.MethodB</p>
<p>CrossMethodLeak.MethodC</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>SPDispose output text file:</p>
<p> <br />
 </p>
<p>Note: This tool may report errors which are not actually memory leaks, otherwise known as false positives.</p>
<p>Further investigation should be done to identify and correct real errors.</p>
<p>It is designed to assist developers in making sure their code adheres to best practices for memory allocation when using SharePoint APIs.</p>
<p>Please see the following for more information:</p>
<p><a href="http://blogs.msdn.com/rogerla/">http://blogs.msdn.com/rogerla/</a></p>
<p><a href="http://msdn2.microsoft.com/en-us/library/aa973248.aspx">http://msdn2.microsoft.com/en-us/library/aa973248.aspx</a></p>
<p><a href="http://msdn2.microsoft.com/en-us/library/bb687949.aspx">http://msdn2.microsoft.com/en-us/library/bb687949.aspx</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_110</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.OpenWebLeak</p>
<p>Statement: local0 := new Microsoft.SharePoint.SPSite(Microsoft.SharePoint.SPContext.get_Current().{Microsoft.SharePoint.SPContext}get_Web().{Microsoft.SharePoint.SPWeb}get_Url()).{Microsoft.SharePoint.SPSite}OpenWeb()</p>
<p>Notes: Constructor called for Microsoft.SharePoint.SPSite but not assigned. This type should be assigned and subsequently disposed</p>
<p>More Information: <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#SPDisposeCheckID_110</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_150</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.AllWebsAddLeak</p>
<p>Statement: OP_POP local0.{Microsoft.SharePoint.SPSite}get_AllWebs().{Microsoft.SharePoint.SPWebCollection}Add(&#8220;site-relative URL&#8221;)</p>
<p>Notes: Call to SPWebCollection.Add without capturing return value which should be disposed or closed</p>
<p>More Information: <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#SPDisposeCheckID_150</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_150</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.WebsAddLeak(System.String)</p>
<p>Statement: OP_POP local1.{Microsoft.SharePoint.SPWeb}get_Webs().{Microsoft.SharePoint.SPWebCollection}Add(strWebUrl)</p>
<p>Notes: Call to SPWebCollection.Add without capturing return value which should be disposed or closed</p>
<p>More Information: <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#SPDisposeCheckID_150</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_150</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.SPWebCollectionAddLeak(System.String)</p>
<p>Statement: OP_POP local2.{Microsoft.SharePoint.SPWebCollection}Add(strWebUrl)</p>
<p>Notes: Call to SPWebCollection.Add without capturing return value which should be disposed or closed</p>
<p>More Information: <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#SPDisposeCheckID_150</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_110</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.SPSiteCollectionAddLeak</p>
<p>Statement: local0 := new Microsoft.SharePoint.SPSite(&#8220;http://moss&#8221;).{Microsoft.SharePoint.SPSite}get_WebApplication()</p>
<p>Notes: Constructor called for Microsoft.SharePoint.SPSite but not assigned. This type should be assigned and subsequently disposed</p>
<p>More Information: <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#SPDisposeCheckID_110</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_240</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.SPSiteCollectionAddLeak</p>
<p>Statement: OP_POP local1.{Microsoft.SharePoint.Administration.SPSiteCollection}Add(&#8220;sites/myNewSiteCollection&#8221;, &#8220;DOMAIN\\User&#8221;, &#8220;roger.lamb@litwareinc.com&#8221;)</p>
<p>Notes: Call to SPSiteCollection.Add without capturing return value which should be disposed or closed</p>
<p>More Information: <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#SPDisposeCheckID_240</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_110</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1.SPSiteCollectionAddNoLeak</p>
<p>Statement: local0 := new Microsoft.SharePoint.SPSite(&#8220;http://moss&#8221;).{Microsoft.SharePoint.SPSite}get_WebApplication()</p>
<p>Notes: Constructor called for Microsoft.SharePoint.SPSite but not assigned. This type should be assigned and subsequently disposed</p>
<p>More Information: <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#SPDisposeCheckID_110</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_110</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1+CrossMethodLeak.MethodA</p>
<p>Statement: this._siteCollection := new Microsoft.SharePoint.SPSite(&#8220;http://moss&#8221;)</p>
<p>Notes:          Disposable type not disposed: Microsoft.SharePoint.SPSite</p>
<p style="margin-left:27pt;">***This may be a false positive depending on how the type was created or if it is disposed outside the current scope</p>
<p>More Information: <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#SPDisposeCheckID_110</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>ID: SPDisposeCheckID_120</p>
<p>Module: SPDisposeTest.dll</p>
<p>Method: SPDisposeTest.Class1+CrossMethodLeak.MethodA</p>
<p>Statement: this._web := this._siteCollection.{Microsoft.SharePoint.SPSite}OpenWeb()</p>
<p>Notes:          Disposable type not disposed: Microsoft.SharePoint.SPWeb</p>
<p style="margin-left:27pt;">***This may be a false positive depending on how the type was created or if it is disposed outside the current scope</p>
<p>More Information: <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#SPDisposeCheckID_120</a></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p>Total Found: 9</p>
<p> <br />
 </p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p>Modules Checked: 1</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>spdisposetest.dll</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p>Modules Ignored: 0</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p>Methods Ignored: 0</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p> <br />
 </p>
<p>The source code for my test assembly:</p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Collections.Generic;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Text;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.Office.Server;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.Office.Server.UserProfiles;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint.Utilities;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint.Publishing;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint.Portal.WebControls;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint.WebControls;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint.WebPartPages;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> Microsoft.SharePoint.Administration;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Web.UI;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Web.UI.WebControls;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Web.UI.WebControls.WebParts;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Web;<br />
</span></p>
<p> <br />
 </p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">namespace</span> SPDisposeTest<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">public</span><br />
<span style="color:blue;">class</span><br />
<span style="color:#2b91af;">Class1</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> CreatingSPSiteLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>);<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// siteCollection leaked<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> CreatingSPSiteExplicitDisposeNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = <span style="color:blue;">null</span>;<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (siteCollection != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollection.Dispose();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> CreatingSPSiteWithAutomaticDisposeNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> OpenWebLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = <span style="color:blue;">new</span> SPSite(SPContext.Current.Web.Url).OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPSite leaked !<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> OpenWebNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> AllWebsForEachLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb outerWeb = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (SPWeb innerWeb <span style="color:blue;">in</span> siteCollection.AllWebs)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// explicit dispose here to avoid OOM&#8217;s with large # of webs<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> AllWebsForEachNoLeakOrMemoryOOM()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb outerWeb = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (SPWeb innerWeb <span style="color:blue;">in</span> siteCollection.AllWebs)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (innerWeb != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">innerWeb.Dispose();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> AllWebsIndexerLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb web = siteCollection.AllWebs[0];<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPWeb web leaked<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> AllWebsIndexerNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.AllWebs[0])<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> AllWebsAddLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb web = siteCollection.AllWebs.Add(<span style="color:#a31515;">&#8220;site-relative URL&#8221;</span>);<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPWeb web Leaked<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> AllWebsAddNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.AllWebs.Add(<span style="color:#a31515;">&#8220;site-relative URL&#8221;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPLimitedWebPartManagerLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPFile page = web.GetFile(<span style="color:#a31515;">&#8220;Source_Folder_Name/Source_Page&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPLimitedWebPartManager webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPWeb object webPartManager.Web leaked<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPLimitedWebPartManagerNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPFile page = web.GetFile(<span style="color:#a31515;">&#8220;Source_Folder_Name/Source_Page&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPLimitedWebPartManager webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">webPartManager.Web.Dispose();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> WebsLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb outerWeb = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (SPWeb innerWeb <span style="color:blue;">in</span> outerWeb.Webs)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPWeb innerWeb leak<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> WebsNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb outerWeb = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (SPWeb innerWeb <span style="color:blue;">in</span> outerWeb.Webs)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">try</span><br />
<span style="color:green;">//should be 1st statement after foreach</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (innerWeb != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">innerWeb.Dispose();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> WebsAddLeak(<span style="color:blue;">string</span> strWebUrl)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb addedWeb = web.Webs.Add(strWebUrl); <span style="color:green;">// will leak</span><br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> WebsAddNoLeak(<span style="color:blue;">string</span> strWebUrl)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb addedWeb = web.Webs.Add(strWebUrl))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">//..<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPWebCollectionAddLeak(<span style="color:blue;">string</span> strWebUrl)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb outerWeb = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebCollection webCollection = siteCollection.AllWebs; <span style="color:green;">// no AllWebs leak just getting reference</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb innerWeb = webCollection.Add(strWebUrl); <span style="color:green;">// must dispose of innerWeb</span><br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// innerWeb Leak<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPWebCollectionAddNoLeak(<span style="color:blue;">string</span> strWebUrl)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb outerWeb = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebCollection webCollection = siteCollection.AllWebs; <span style="color:green;">// no AllWebs leak just getting reference</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb innerWeb = webCollection.Add(strWebUrl))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">//&#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPControlBADPractice()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">HttpContext Context = <span style="color:blue;">null</span>;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = SPControl.GetContextSite(Context);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollection.Dispose(); <span style="color:green;">// DO NOT DO THIS</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb web = SPControl.GetContextWeb(Context);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">web.Dispose(); <span style="color:green;">// DO NOT DO THIS</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPControlBestPractice()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">HttpContext Context = <span style="color:blue;">null</span>;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = SPControl.GetContextSite(Context);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb web = SPControl.GetContextWeb(Context);<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// Do NOT call Dispose()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPContextBADPractice()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = SPContext.Current.Site;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollection.Dispose(); <span style="color:green;">// DO NOT DO THIS</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb web = SPContext.Current.Web;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">web.Dispose(); <span style="color:green;">// DO NOT DO THIS</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPContextBestPractice()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = SPContext.Current.Site;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWeb web = SPContext.Current.Web;<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// Do NOT call Dispose()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> PublishingWebCollectionLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// passing in web you own, no dispose needed on outerPubWeb<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb outerPubWeb = PublishingWeb.GetPublishingWeb(web);<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWebCollection pubWebCollection = outerPubWeb.GetPublishingWebs();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (PublishingWeb innerPubWeb <span style="color:blue;">in</span> pubWebCollection)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// innerPubWeb leak<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// PublishingWeb will leak for each innerPubWeb referenced<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> PublishingWebCollectionNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// passing in web you own, no dispose needed on outerPubWeb<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb outerPubWeb = PublishingWeb.GetPublishingWeb(web);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWebCollection pubWebCollection = outerPubWeb.GetPublishingWebs();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (PublishingWeb innerPubWeb <span style="color:blue;">in</span> pubWebCollection)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (innerPubWeb != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">innerPubWeb.Close();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// outerPubWeb.Close(); not needed and if called will log warning in ULS log<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> GetPublishingWebNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// passing in web you own, no dispose needed on singlePubWeb<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb singlePubWeb = PublishingWeb.GetPublishingWeb(web);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> GetVariationLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); <span style="color:green;">// Passing in web so no Close() needed</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">VariationLabel variationLabel = Variations.Current.UserAccessibleLabels[0];<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb variationPublishingWeb = publishingWeb.GetVariation(variationLabel); <span style="color:green;">// must be Closed()</span><br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object web.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> GetVariationNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPWeb web = siteCollection.OpenWeb())<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb variationPublishingWeb = <span style="color:blue;">null</span>;<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web); <span style="color:green;">// Passing in web so no Close() needed</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">VariationLabel variationLabel = Variations.Current.UserAccessibleLabels[0];<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">variationPublishingWeb = publishingWeb.GetVariation(variationLabel); <span style="color:green;">// must be Closed()</span><br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (variationPublishingWeb != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">variationPublishingWeb.Close();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPWeb object outerWeb.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called </span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> PersonalSiteLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// open a site collection<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">UserProfileManager profileManager = <span style="color:blue;">new</span> UserProfileManager(ServerContext.GetContext(siteCollection));<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">UserProfile profile = profileManager.GetUserProfile(<span style="color:#a31515;">&#8220;domain\\username&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite personalSite = profile.PersonalSite; <span style="color:green;">// will leak</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> PersonalSiteNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// open a site collection<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">UserProfileManager profileManager = <span style="color:blue;">new</span> UserProfileManager(ServerContext.GetContext(siteCollection));<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">UserProfile profile = profileManager.GetUserProfile(<span style="color:#a31515;">&#8220;domain\\username&#8221;</span>);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite personalSite = profile.PersonalSite)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPSiteCollectionIndexerLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollectionOuter = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebApplication webApp = siteCollectionOuter.WebApplication;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSiteCollection siteCollections = webApp.Sites;<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollectionInner = siteCollections[0];<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPSite siteCollectionInner leak<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollectionOuter.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPSiteCollectionIndexerNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollectionOuter = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollectionInner = <span style="color:blue;">null</span>;<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebApplication webApp = siteCollectionOuter.WebApplication;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSiteCollection siteCollections = webApp.Sites;<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollectionInner = siteCollections[0];<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (siteCollectionInner != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollectionInner.Dispose();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollectionOuter.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPSiteCollectionForEachLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollectionOuter = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebApplication webApp = siteCollectionOuter.WebApplication;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSiteCollection siteCollections = webApp.Sites;<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (SPSite siteCollectionInner <span style="color:blue;">in</span> siteCollections)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPSite siteCollectionInner leak<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollectionOuter.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPSiteCollectionForEachNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollectionOuter = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebApplication webApp = siteCollectionOuter.WebApplication;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSiteCollection siteCollections = webApp.Sites;<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">foreach</span> (SPSite siteCollectionInner <span style="color:blue;">in</span> siteCollections)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">try<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// &#8230;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="color:blue;font-family:Courier New;font-size:10pt;">finally<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (siteCollectionInner != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">siteCollectionInner.Dispose();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollectionOuter.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPSiteCollectionAddLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebApplication webApp = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss%22).WebApplication">http://moss&#8221;</a></span>).WebApplication;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSiteCollection siteCollections = webApp.Sites;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSite siteCollection = siteCollections.Add(<span style="color:#a31515;">&#8220;sites/myNewSiteCollection&#8221;</span>, <span style="color:#a31515;">&#8220;DOMAIN\\User&#8221;</span>, <span style="color:#a31515;">&#8220;roger.lamb@litwareinc.com&#8221;</span>);<br />
</span></p>
<p><span style="color:green;font-family:Courier New;font-size:10pt;">// SPSite siteCollection leak<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">void</span> SPSiteCollectionAddNoLeak()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPWebApplication webApp = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss%22).WebApplication">http://moss&#8221;</a></span>).WebApplication;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">SPSiteCollection siteCollections = webApp.Sites;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> (SPSite siteCollection = siteCollections.Add(<span style="color:#a31515;">&#8220;sites/myNewSiteCollection&#8221;</span>, <span style="color:#a31515;">&#8220;DOMAIN\\User&#8221;</span>, <span style="color:#a31515;">&#8220;roger.lamb@litwareinc.com&#8221;</span>))<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">} <span style="color:green;">// SPSite object siteCollection.Dispose() automatically called</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">public</span><br />
<span style="color:blue;">class</span><br />
<span style="color:#2b91af;">CrossMethodLeak</span><br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">private</span> SPSite _siteCollection = <span style="color:blue;">null</span>;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">private</span> SPWeb _web = <span style="color:blue;">null</span>;<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">public</span><br />
<span style="color:blue;">void</span> MethodA()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">_siteCollection = <span style="color:blue;">new</span> SPSite(<span style="color:#a31515;">&#8220;<a href="http://moss">http://moss</a>&#8220;</span>);<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">_web = _siteCollection.OpenWeb();<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">public</span><br />
<span style="color:blue;">void</span> MethodB()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (_web != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">string</span> title = _web.Title;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">public</span><br />
<span style="color:blue;">void</span> MethodC()<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">if</span> (_web != <span style="color:blue;">null</span>)<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">string</span> name = _web.Name;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p> <br />
 </p>
<p> UPDATE:  Mystery Solved! &#8211; <a href="http://stephenvick.wordpress.com/2009/03/20/mystery-solved-spdisposecheck-missing-memory-leaks/">http://stephenvick.wordpress.com/2009/03/20/mystery-solved-spdisposecheck-missing-memory-leaks/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/82/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/82/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/82/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=82&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2009/03/19/spdisposecheck-missing-memory-leaks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>
	</item>
		<item>
		<title>Error &#8220;Value does not fall within the expected range&#8221; when calling GetCustomListTemplates method when creating a custom list from a ListTemplate.</title>
		<link>http://stephenvick.wordpress.com/2009/02/18/error-value-does-not-fall-within-the-expected-range-when-calling-getcustomlisttemplates-method-when-creating-a-custom-list-from-a-listtemplate/</link>
		<comments>http://stephenvick.wordpress.com/2009/02/18/error-value-does-not-fall-within-the-expected-range-when-calling-getcustomlisttemplates-method-when-creating-a-custom-list-from-a-listtemplate/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 17:23:39 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2009/02/18/error-value-does-not-fall-within-the-expected-range-when-calling-getcustomlisttemplates-method-when-creating-a-custom-list-from-a-listtemplate/</guid>
		<description><![CDATA[When deploying an .stp file within a feature and trying to use this file within a feature receiver FeatureActivated method the list template will not return in the GetCustomListTemplates method unless two properties are specified for the .stp within the elements.xml. These properties are LanguageDisplay and Version. Shown below.       Screen clipping taken: 2/18/2009, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=80&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When deploying an .stp file within a feature and trying to use this file within a feature receiver FeatureActivated method the list template will not return in the GetCustomListTemplates method unless two properties are specified for the .stp within the elements.xml. These properties are <strong>LanguageDisplay</strong> and <strong>Version</strong>. Shown below.  </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/02/021809-1721-errorvalued1.png?w=780" alt="" /></p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 2/18/2009, 12:14 PM</span></p>
<p>What magical property these properties hold that allow the list template to be seen in the GetCustomListTemplate method I do know. But once I deleted the old .stp file from the gallery, re-deployed and activated the feature all was well.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=80&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2009/02/18/error-value-does-not-fall-within-the-expected-range-when-calling-getcustomlisttemplates-method-when-creating-a-custom-list-from-a-listtemplate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>

		<media:content url="http://stephenvick.files.wordpress.com/2009/02/021809-1721-errorvalued1.png" medium="image" />
	</item>
		<item>
		<title>CreateDate for List Items in Manage Site Content and Structure</title>
		<link>http://stephenvick.wordpress.com/2009/01/29/createdate-for-list-items-in-manage-site-content-and-structure/</link>
		<comments>http://stephenvick.wordpress.com/2009/01/29/createdate-for-list-items-in-manage-site-content-and-structure/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 18:11:26 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2009/01/29/createdate-for-list-items-in-manage-site-content-and-structure/</guid>
		<description><![CDATA[Just discovered that when you Copy or Move content using Manage Site Content and Structure the target content has the EXACT same CreateDate +1 second. Not sure why this is but since the GUIDs are not preserved for either move or copy this could end up being very useful if you have data in SQL [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=78&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just discovered that when you Copy or Move content using Manage Site Content and Structure the target content has the EXACT same CreateDate +1 second.  Not sure why this is but since the GUIDs are not preserved for either move or copy this could end up being very useful if you have data in SQL outside of SharePoint that references the ObjectID.
</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef1.png?w=780">
	</p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 1/29/2009, 1:01 PM<br />
</span></p>
<p> <br />
 </p>
<p>Move or Copy
</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef2.png?w=780">
	</p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 1/29/2009, 1:02 PM<br />
</span></p>
<p> <br />
 </p>
<p>Select destination
</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef3.png?w=780">
	</p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 1/29/2009, 1:02 PM<br />
</span></p>
<p> <br />
 </p>
<p>Copy in progress
</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef4.png?w=780">
	</p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 1/29/2009, 1:04 PM<br />
</span></p>
<p> <br />
 </p>
<p>CreateDate before Copy/Move
</p>
<p>&amp;
</p>
<p> <br />
 </p>
<p><img src="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef5.png?w=780">
	</p>
<p> <br />
 </p>
<p><span style="color:#666666;font-family:Tahoma;font-size:8pt;">Screen clipping taken: 1/29/2009, 1:05 PM<br />
</span></p>
<p> <br />
 </p>
<p>Target is CreateDate is exactly the same +1 second.
</p>
<p>o</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=78&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2009/01/29/createdate-for-list-items-in-manage-site-content-and-structure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>

		<media:content url="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef1.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef2.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef3.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef4.png" medium="image" />

		<media:content url="http://stephenvick.files.wordpress.com/2009/01/012909-1812-createdatef5.png" medium="image" />
	</item>
		<item>
		<title>Art Vandelay &#8211; Import/Export SharePoint Content in C#</title>
		<link>http://stephenvick.wordpress.com/2009/01/28/art-vandelay-importexport-sharepoint-content-in-c/</link>
		<comments>http://stephenvick.wordpress.com/2009/01/28/art-vandelay-importexport-sharepoint-content-in-c/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 13:42:33 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[Import]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2009/01/28/art-vandelay-importexport-sharepoint-content-in-c/</guid>
		<description><![CDATA[Here is some handy dandy code for Exporting content from a SharePoint site and importing into another.         using System; using System.Collections.Generic; using System.Text;     namespace ContentMoveTest { class Program { static void Main(string[] args) { ExportImport(&#8220;http://www.source.com&#8220;, &#8220;http://www.target.com&#8220;); }         static void ExportImport(string sourceUrl, string destinationUrl) { string [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=69&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is some handy dandy code for Exporting content from a SharePoint site and importing into another.</p>
<p> <br />
 </p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Collections.Generic;<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">using</span> System.Text;<br />
</span></p>
<p> <br />
 </p>
<p><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">namespace</span> ContentMoveTest<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p style="margin-left:27pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">class</span><br />
<span style="color:#2b91af;">Program</span><br />
</span></p>
<p style="margin-left:27pt;"><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">static</span><br />
<span style="color:blue;">void</span> Main(<span style="color:blue;">string</span>[] args)<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">ExportImport(<span style="color:#a31515;">&#8220;<a href="http://www.source.com">http://www.source.com</a>&#8220;</span>, <span style="color:#a31515;">&#8220;<a href="http://www.target.com">http://www.target.com</a>&#8220;</span>);<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p style="margin-left:54pt;"> <br />
 </p>
<p style="margin-left:54pt;"> <br />
 </p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">static</span><br />
<span style="color:blue;">void</span> ExportImport(<span style="color:blue;">string</span> sourceUrl, <span style="color:blue;">string</span> destinationUrl)<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">string</span> fileName = Export(sourceUrl);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&#8220;Local filename for this export/import is {0}&#8221;</span>, fileName);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">Import(destinationUrl, fileName);<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p style="margin-left:54pt;"> <br />
 </p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">static</span><br />
<span style="color:blue;">string</span> Export(<span style="color:blue;">string</span> siteURL)<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPExportSettings</span> exportSettings = <span style="color:blue;">new</span> Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPExportSettings</span>();<br />
</span></p>
<p style="margin-left:81pt;"> <br />
 </p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">exportSettings.AutoGenerateDataFileName = <span style="color:blue;">true</span>;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">exportSettings.ExportMethod = Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPExportMethodType</span>.ExportAll;<br />
</span></p>
<p style="margin-left:81pt;"><span style="color:green;font-family:Courier New;font-size:10pt;">//exportSettings.ExportMethod = Microsoft.SharePoint.Deployment.SPExportMethodType.ExportChanges;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">exportSettings.CommandLineVerbose = <span style="color:blue;">true</span>;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">exportSettings.SiteUrl = siteURL;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">exportSettings.IncludeSecurity = Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPIncludeSecurity</span>.All;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">exportSettings.IncludeVersions = Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPIncludeVersions</span>.All;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPExport</span> export = <span style="color:blue;">new</span> Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPExport</span>(exportSettings);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&#8220;Starting export of URL {0}&#8221;</span>, siteURL);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">export.Run();<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">return</span> exportSettings.FileLocation + <span style="color:#a31515;">&#8220;\\&#8221;</span> + exportSettings.BaseFileName;<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p style="margin-left:54pt;"> <br />
 </p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:blue;">static</span><br />
<span style="color:blue;">void</span> Import(<span style="color:blue;">string</span> siteURL, <span style="color:blue;">string</span> fileToImport)<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">{<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPImportSettings</span> importSettings = <span style="color:blue;">new</span> Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPImportSettings</span>();<br />
</span></p>
<p style="margin-left:81pt;"> <br />
 </p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.BaseFileName = System.IO.<span style="color:#2b91af;">Path</span>.GetFileName(fileToImport);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.FileLocation = System.IO.<span style="color:#2b91af;">Path</span>.GetDirectoryName(fileToImport);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.CommandLineVerbose = <span style="color:blue;">true</span>;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.SiteUrl = siteURL;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.RetainObjectIdentity = <span style="color:blue;">true</span>;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.IncludeSecurity = Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPIncludeSecurity</span>.All;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.UpdateVersions = Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPUpdateVersions</span>.Append;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">importSettings.UserInfoDateTime = Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPImportUserInfoDateTimeOption</span>.ImportAll;<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPImport</span> import = <span style="color:blue;">new</span> Microsoft.SharePoint.Deployment.<span style="color:#2b91af;">SPImport</span>(importSettings);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;"><span style="color:#2b91af;">Console</span>.WriteLine(<span style="color:#a31515;">&#8220;Starting import to URL {0}&#8221;</span>, siteURL);<br />
</span></p>
<p style="margin-left:81pt;"><span style="font-family:Courier New;font-size:10pt;">import.Run();<br />
</span></p>
<p style="margin-left:54pt;"><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p style="margin-left:27pt;"> <br />
 </p>
<p style="margin-left:27pt;"><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<p><span style="font-family:Courier New;font-size:10pt;">}<br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=69&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2009/01/28/art-vandelay-importexport-sharepoint-content-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>
	</item>
		<item>
		<title>Extending VariationRoot.aspx Redirection in SharePoint</title>
		<link>http://stephenvick.wordpress.com/2009/01/27/extending-variationrootaspx-redirection-in-sharepoint/</link>
		<comments>http://stephenvick.wordpress.com/2009/01/27/extending-variationrootaspx-redirection-in-sharepoint/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 14:28:30 +0000</pubDate>
		<dc:creator>stephenvick</dc:creator>
				<category><![CDATA[.NET Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Variations]]></category>

		<guid isPermaLink="false">http://stephenvick.wordpress.com/2009/01/27/extending-variationrootaspx-redirection-in-sharepoint/</guid>
		<description><![CDATA[Some code used to extend variation redirection logic based on a preferred locale setting in the users profile. If the property is not present or blank it falls back to default variations logic. A locale picker to set this value will be posted soon.     using System; using Microsoft.SharePoint; using CCE.SharePoint.UserControls; using CCE.SharePoint.Utility; using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=66&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Some code used to extend variation redirection logic based on a preferred locale setting in the users profile. If the property is not present or blank it falls back to default variations logic. A locale picker to set this value will be posted soon.</p>
<p> <br />
 </p>
<p>using System;</p>
<p>using Microsoft.SharePoint;</p>
<p>using CCE.SharePoint.UserControls;</p>
<p>using CCE.SharePoint.Utility;</p>
<p>using Microsoft.Office.Server.UserProfiles;</p>
<p>using Microsoft.SharePoint.Utilities;</p>
<p> <br />
 </p>
<p>namespace CCE.SharePoint.UserControls</p>
<p>{</p>
<p>public class VariationsRootLanding : CCEBaseUserControl</p>
<p>{</p>
<p> <br />
 </p>
<p>protected override void OnLoad(EventArgs e)</p>
<p>{</p>
<p>string targetUrl = this.GetRedirectTargetUrl();</p>
<p> </p>
<p>if (!string.IsNullOrEmpty(targetUrl))</p>
<p>{</p>
<p>SPUtility.Redirect(targetUrl, SPRedirectFlags.Default, Context);</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>SPUtility.Redirect(&#8220;VariationRoot.aspx&#8221;, SPRedirectFlags.Default, Context);</p>
<p>}</p>
<p>}</p>
<p> <br />
 </p>
<p>private string GetRedirectTargetUrl()</p>
<p>{</p>
<p>String url = &#8220;&#8221;;</p>
<p> <br />
 </p>
<p>try</p>
<p>{</p>
<p>String loginName = SPContext.Current.Web.CurrentUser.LoginName;</p>
<p> <br />
 </p>
<p>UserProfile currentUserProfile = Utility.UserProfiles.GetUserProfile(loginName);</p>
<p>String preferredLocale = Utility.UserProfiles.GetSinglePropertyValue(currentUserProfile, &#8220;preferredLocale&#8221;);</p>
<p> <br />
 </p>
<p>using (SPSite _SPSite = new SPSite(SPContext.Current.Site.ID))</p>
<p>{</p>
<p>using (SPWeb rootWeb = _SPSite.RootWeb)</p>
<p>{</p>
<p>foreach (SPWeb subWeb in rootWeb.Webs)</p>
<p>{</p>
<p>if (subWeb.Locale.ToString() == preferredLocale)</p>
<p>{</p>
<p>url = &#8220;/&#8221; + subWeb.Name;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>catch (Exception)</p>
<p>{</p>
<p>//Log error</p>
<p>}</p>
<p> <br />
 </p>
<p>return url;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/stephenvick.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/stephenvick.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/stephenvick.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/stephenvick.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/stephenvick.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/stephenvick.wordpress.com/66/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/stephenvick.wordpress.com/66/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/stephenvick.wordpress.com/66/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=stephenvick.wordpress.com&amp;blog=5931829&amp;post=66&amp;subd=stephenvick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://stephenvick.wordpress.com/2009/01/27/extending-variationrootaspx-redirection-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/be3ed628165e189943ec94b8e1e84e0b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">stephenvick</media:title>
		</media:content>
	</item>
	</channel>
</rss>
