<?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>SharePoint Internals - Hristo Pavlov's Blog</title>
	<atom:link href="http://hristopavlov.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hristopavlov.wordpress.com</link>
	<description>The "Why" and "How" of SharePoint Development</description>
	<lastBuildDate>Tue, 06 Dec 2011 19:59:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='hristopavlov.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>SharePoint Internals - Hristo Pavlov's Blog</title>
		<link>http://hristopavlov.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://hristopavlov.wordpress.com/osd.xml" title="SharePoint Internals - Hristo Pavlov&#039;s Blog" />
	<atom:link rel='hub' href='http://hristopavlov.wordpress.com/?pushpress=hub'/>
		<item>
		<title>My Last Post in &#8216;SharePoint Internals&#8217;</title>
		<link>http://hristopavlov.wordpress.com/2009/04/06/my-last-post-in-sharepoint-internals/</link>
		<comments>http://hristopavlov.wordpress.com/2009/04/06/my-last-post-in-sharepoint-internals/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 00:23:39 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=329</guid>
		<description><![CDATA[Hi all, I am moving away from SharePoint and consulting into serious custom software development and this is my last blog post here. I wish all the best to all of you that remain in the SharePoint world. The SPTraceView utility is now moved to CodePlex to address: http://sptraceview.codeplex.com/ If the project is not published yet, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=329&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>I am moving away from SharePoint and consulting into serious custom software development and this is my last blog post here. I wish all the best to all of you that remain in the SharePoint world.</p>
<p>The <strong>SPTraceView</strong> utility is now moved to CodePlex to address:</p>
<p><a href="http://sptraceview.codeplex.com/">http://sptraceview.codeplex.com/</a></p>
<p>If the project is not published yet, please check again later. It must be published before 6 May 2009.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/329/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/329/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/329/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=329&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/04/06/my-last-post-in-sharepoint-internals/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>
	</item>
		<item>
		<title>Running execadmsvcjobs through code</title>
		<link>http://hristopavlov.wordpress.com/2009/02/27/running-execadmsvcjobs-through-code/</link>
		<comments>http://hristopavlov.wordpress.com/2009/02/27/running-execadmsvcjobs-through-code/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 04:50:30 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[execadmsvcjobs]]></category>
		<category><![CDATA[execute]]></category>
		<category><![CDATA[Programmatically]]></category>
		<category><![CDATA[ProvisionGlobaly]]></category>
		<category><![CDATA[SPWebApplication]]></category>
		<category><![CDATA[stsadm]]></category>
		<category><![CDATA[timer jobs]]></category>
		<category><![CDATA[wait]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=321</guid>
		<description><![CDATA[Well there are many ways you could achieve this and this is just one of  them. It simply creates a new instance of the SPExecuteAdministrationServiceJobs class and calls its Run method. This will start and wait for all currently registered and/or running timer jobs to finish. The code is below: string stsadmPath = SPUtility.GetGenericSetupPath(&#8220;BIN&#8221;); Assembly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=321&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well there are many ways you could achieve this and this is just one of  them. It simply creates a new instance of the SPExecuteAdministrationServiceJobs class and calls its Run method. This will start and wait for all currently registered and/or running timer jobs to finish. The code is below:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">string </span><span style="font-size:10pt;font-family:&quot;">stsadmPath = <span style="color:teal;">SPUtility</span>.GetGenericSetupPath(<span style="color:maroon;">&#8220;BIN&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:teal;font-family:&quot;">Assembly </span><span style="font-size:10pt;font-family:&quot;">stsadmAsm = <span style="color:teal;">Assembly</span>.LoadFile(<span style="color:teal;">Path</span>.GetFullPath(stsadmPath + <span style="color:maroon;">&#8220;\\STSADM.EXE&#8221;</span>));</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:teal;font-family:&quot;">Type </span><span style="font-size:10pt;font-family:&quot;">admSvcJobType = stsadmAsm.GetType(<span style="color:maroon;">&#8220;Microsoft.SharePoint.StsAdmin.SPExecuteAdministrationServiceJobs&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:teal;font-family:&quot;">ConstructorInfo </span><span style="font-size:10pt;font-family:&quot;">ci = admSvcJobType.GetConstructor(<span style="color:blue;">new</span> <span style="color:teal;">Type</span>[] { <span style="color:blue;">typeof</span>(<span style="color:teal;">SPGlobalAdmin</span>) });</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">using</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:teal;">SPGlobalAdmin</span> admin = <span style="color:blue;">new</span> <span style="color:teal;">SPGlobalAdmin</span>())</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">object </span>svcjobs = ci.Invoke(<span style="color:blue;">new</span> <span style="color:blue;">object</span>[] { admin });</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:teal;">MethodInfo </span>runMi = admSvcJobType.GetMethod(<span style="color:maroon;">&#8220;Run&#8221;</span>, <span style="color:teal;">BindingFlags</span>.Instance | <span style="color:teal;">BindingFlags</span>.Public);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>runMi.Invoke(svcjobs, <span style="color:blue;">new</span> <span style="color:blue;">object</span>[] { <span style="color:blue;">new</span> <span style="color:teal;">StringDictionary</span>() });</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
</div>
<p>One place this could be handy is when you provision a web application on multiple front ends using SPWebApplication.ProvisionGlobaly(). This method creates a timer job and returns immediately. However if you need the web application to be created before you continue you need to wait for the timer job(s) to finish. One way to do this programmatically is using the code above.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/321/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/321/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/321/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=321&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/02/27/running-execadmsvcjobs-through-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding SharePoint: Event Receivers</title>
		<link>http://hristopavlov.wordpress.com/2009/02/24/understanding-sharepoint-event-receivers/</link>
		<comments>http://hristopavlov.wordpress.com/2009/02/24/understanding-sharepoint-event-receivers/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 10:22:02 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[EditForm.aspx]]></category>
		<category><![CDATA[Event Receivers]]></category>
		<category><![CDATA[SharePointInternals.SynchronousItemAdded]]></category>
		<category><![CDATA[SPEventManager]]></category>
		<category><![CDATA[SPItemEventProperties]]></category>
		<category><![CDATA[SPSynchronousReceiver]]></category>
		<category><![CDATA[Upload.aspx]]></category>
		<category><![CDATA[WaitForItemAdded]]></category>
		<category><![CDATA[WaitForItemAddedReceivers]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=253</guid>
		<description><![CDATA[This blog post shows some details about how the event receivers in SharePoint work and also provides a solution how to wait for an ItemAdded event receiver to complete before the EditForm.aspx page is displayed when uploading a document. The solution could be used to wait for any asynchronous event receiver when you are changing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=253&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog post shows some details about how the event receivers in SharePoint work and also provides a solution how to wait for an ItemAdded event receiver to complete before the EditForm.aspx page is displayed when uploading a document. The solution could be used to wait for any asynchronous event receiver when you are changing the list using code.</p>
<p>All list item, list and web event receivers in SharePoint with the exception of the <strong>ListItemFileConverted</strong> receiver are run from the <a href="http://hristopavlov.wordpress.com/2009/01/19/understanding-sharepoint-sprequest/" target="_blank">SPRequest</a> unmanaged class. There are two types of event receivers &#8211; synchronous (such as ItemAdding and ItemUpdating) and asynchronous (such as ItemAdded and ItemUpdated). Because the event receivers are implemented in managed code, the unmanaged SPRequest class needs a way to invoke them. This is done via the <strong>ISPEventManager</strong> COM interface which is implemented by the <strong>Microsoft.SharePoint.SPEventManager</strong> internal class.</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">[<span style="color:#2b91af;">ComImport</span>, <span style="color:#2b91af;">SuppressUnmanagedCodeSecurity</span>, <span style="color:#2b91af;">InterfaceType</span>((<span style="color:blue;">short</span>)1), <span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">"BDEADF0F-C265-11D0-BCED-00A0C90AB50F"</span>)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">interface</span> <span style="color:#2b91af;">ISPEventManager</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>[<span style="color:#2b91af;">MethodImpl</span>(<span style="color:#2b91af;">MethodImplOptions</span>.InternalCall, MethodCodeType = <span style="color:#2b91af;">MethodCodeType</span>.Runtime)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> ExecuteItemEventReceivers(</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">ref</span> <span style="color:blue;">byte</span>[] userToken, <span style="color:blue;">ref</span> <span style="color:blue;">object</span>eventReceivers, <span style="color:blue;">ref</span> ItemEventReceiverParams itemEventParams, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">out</span> <span style="color:blue;">object</span>changedFields, <span style="color:blue;">out</span>EventReceiverResult eventResult, <span style="color:blue;">out</span> <span style="color:blue;">string</span>errorMessage);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>[<span style="color:#2b91af;">MethodImpl</span>(<span style="color:#2b91af;">MethodImplOptions</span>.InternalCall, MethodCodeType = <span style="color:#2b91af;">MethodCodeType</span>.Runtime)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> EnqueueItemEventReceivers(<span style="color:blue;">ref</span> <span style="color:blue;">byte</span>[] userToken, <span style="color:blue;">ref</span> <span style="color:blue;">object</span>eventReceivers, <span style="color:blue;">ref</span> ItemEventReceiverParams itemEventParams);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>[<span style="color:#2b91af;">MethodImpl</span>(<span style="color:#2b91af;">MethodImplOptions</span>.InternalCall, MethodCodeType = <span style="color:#2b91af;">MethodCodeType</span>.Runtime)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> ExecuteListEventReceivers(</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">ref</span> <span style="color:blue;">byte</span>[] userToken, <span style="color:blue;">ref</span> <span style="color:blue;">object</span>eventReceivers, <span style="color:blue;">ref</span> ListEventReceiverParams ListEventParams, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">out</span>EventReceiverResult eventResult, <span style="color:blue;">out</span> <span style="color:blue;">string</span>errorMessage);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>[<span style="color:#2b91af;">MethodImpl</span>(<span style="color:#2b91af;">MethodImplOptions</span>.InternalCall, MethodCodeType = <span style="color:#2b91af;">MethodCodeType</span>.Runtime)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> EnqueueListEventReceivers(<span style="color:blue;">ref</span> <span style="color:blue;">byte</span>[] userToken, <span style="color:blue;">ref</span> <span style="color:blue;">object</span>eventReceivers, <span style="color:blue;">ref</span> ListEventReceiverParams ListEventParams);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>[<span style="color:#2b91af;">MethodImpl</span>(<span style="color:#2b91af;">MethodImplOptions</span>.InternalCall, MethodCodeType = <span style="color:#2b91af;">MethodCodeType</span>.Runtime)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> ExecuteWebEventReceivers(</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">ref</span> <span style="color:blue;">byte</span>[] userToken, <span style="color:blue;">ref</span> <span style="color:blue;">object</span>eventReceivers, <span style="color:blue;">ref</span> WebEventReceiverParams webEventParams, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">out</span>EventReceiverResult eventResult, <span style="color:blue;">out</span> <span style="color:blue;">string</span>errorMessage);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>[<span style="color:#2b91af;">MethodImpl</span>(<span style="color:#2b91af;">MethodImplOptions</span>.InternalCall, MethodCodeType = <span style="color:#2b91af;">MethodCodeType</span>.Runtime)]</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">void</span> EnqueueWebEventReceivers(<span style="color:blue;">ref</span> <span style="color:blue;">byte</span>[] userToken, <span style="color:blue;">ref</span> <span style="color:blue;">object</span>eventReceivers, <span style="color:blue;">ref</span> WebEventReceiverParams webEventParams);</span></p>
<p><span style="font-size:10pt;font-family:&quot;">}</span></div>
<p>As we can see from the interface all event receivers are passed to be executed in one call and there are two types of methods in the ISPEventManager class: EnqueueEventReceivers &#8211; used for the asynchronous ones and ExecuteEventReceivers &#8211; used for the synchronous.</p>
<p>So because the unmanaged code will make a call back to the managed SPEventManager class to run the event receivers, the first important question is which process will those event receivers run in. Well the answer is both synchronous and asynchronous event receivers will execute in the same process that has made the change that resulted in the event receivers being called. So for example if you are adding a new file into a document library from a web part, then the event receivers will execute in the w3wp.exe process of the application pool of the web application. If you are adding the file from a rich client (MyWinFormsApp.exe) then the event receivers, including the asynchronous ones will execute in the MyWinFormsApp.exe process.</p>
<p>The asynchronous event receivers may need some time to complete (could be a lot of time) and if you close your MyWinFormsApp.exe immediately after you have added the file, and while the event receivers are still running, what will happen is that <em><strong>they will be terminated and some of them may not run at all</strong></em>.</p>
<p>The situation with IIS is not very different unfortunately. If you do an <strong>iisreset </strong>without the /noforce switch then all currently running asynchronous event receivers will be terminated immediately. My tests showed that executing <strong>iisreset /noforce</strong> will indeed wait for an asynchronous event receiver to finish however if you are trying to save any changes to the item for example, those changes will not survive.</p>
<p>So this means that by doing <strong>iisreset</strong> you may be interrupting a running asynchronous (or synchronous) event receiver and corrupting your application integrity/state. When executing <strong>iisreset /noforce </strong>the event receivers will complete but they may not be able to update any of the SharePoint objects they could be trying to manipulate. This finding it actually very alarming! I wouldn&#8217;t recommend to anyone writing any event receiver that will take more than 1 second to complete as an iisreset may corrupt your application!</p>
<p>The asynchronous event receivers will be run in their own thread from the System.Threading.ThreadPool. And a new thread will be queued up with every call from the unmanaged SPRequest class. This means that if you add say 100 files to a document library this will result in 100 calls to EnqueueItemEventReceivers for each of the items. And this will create and en-queue 100 threads each of which will run one by one all asynchronous event receivers for the corresponding file. Now if some of those event receivers are taking some time to complete, which is a few times more than the time it takes you to add a file, what will happen is you will end up with enormous amount of running threads.</p>
<p>Switching between threads is a very resource intensive operation and if you have 100 threads running in your application or in IIS, this will pretty much slow down the process to a crawl. I&#8217;ve seen this happening with a custom built migration tool that moves documents from one document library to another. There were some heavy ItemAdded event receivers and after few hundreds files were moved for a minute or so, it took another 45 minutes for the event receivers to complete. The migration would have been faster if after adding each file the migration tool was waiting for the event receivers to complete because after adding all the files at once 90+% of the time the process was spending in switching between the few hundred threads and only up to 10% were the actual threads running the event receivers.</p>
<p>The next interesting question is what is the lifespan for the SPItemEventProperties that are passed to all item event receivers (synchronous and asynchronous). Well looking at the SPEventManager class code it turns out that the SPItemEventProperties are created once per batch of events receivers and are shared among all of them. So this means that all synchronous event receivers will share the same properties and all asynchronous event receivers will share different instance of the properties. However the unmanaged SPRequest class will keep the changes to the properties done by the synchronous event receivers and will pass them to the asynchronous event receivers.  This means that it is generally possible to store information in the SPEventProperties from some event receivers that could be passed to other event receivers executed later on.</p>
<p>This could only be done from an ItemAdding or ItemUpdating event receiver. You could add anything you want to the AfterProperties collection and the information you have added will be availabe as AfterProperties in the ItemAdded and ItemUpdated event receivers.</p>
<p>A question that have been bothering me for a while is should the web retrieved by SPItemEventProperties.OpenWeb() be disposed by the event receiver that have opened it. The answer as always lies in the implementation details of the class (in out case SPItemEventProperties) that can be retrieved using Reflector.</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">sealed</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">SPItemEventProperties</span> : <span style="color:#2b91af;">SPEventPropertiesBase</span>, <span style="color:#2b91af;">IDisposable</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#339966;font-family:&quot;" lang="EN-US"><span>    </span>&#8230;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">private</span> <span style="color:#2b91af;">SPSite </span>OpenSite()</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (((<span style="color:blue;">this</span>.m_site == <span style="color:blue;">null</span>) &amp;&amp; (<span style="color:blue;">this</span>.WebUrl != <span style="color:blue;">null</span>)) &amp;&amp; (<span style="color:blue;">this</span>.m_site == <span style="color:blue;">null</span>))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">if</span> (<span style="color:blue;">this</span>.m_userToken == <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">this</span>.m_site = <span style="color:blue;">new</span> <span style="color:#2b91af;">SPSite</span>(<span style="color:blue;">this</span>.WebUrl);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>               </span><span> </span><span style="color:blue;">this</span>.m_site = <span style="color:blue;">new</span> <span style="color:#2b91af;">SPSite</span>(<span style="color:blue;">this</span>.WebUrl, <span style="color:blue;">this</span>.m_userToken);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">this</span>.m_siteCreatedByThis = <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">return</span> <span style="color:blue;">this</span>.m_site;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#339966;font-family:&quot;" lang="EN-US"><span>    </span>&#8230;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:#2b91af;">SPWeb </span>OpenWeb()</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">this</span>.OpenSite();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (<span style="color:blue;">this</span>.m_site == <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span><span>     </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:blue;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">return</span> <span style="color:blue;">this</span>.m_site.OpenWeb(<span style="color:blue;">this</span>.RelativeWebUrl);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#339966;font-family:&quot;" lang="EN-US"><span>    </span>&#8230;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">public</span> <span style="color:blue;">void</span> Dispose()</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (<span style="color:blue;">this</span>.m_site != <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>     </span><span>       </span><span style="color:blue;">while</span> (<span style="color:blue;">this</span>.m_siteCreatedByThis)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">this</span>.m_site.Dispose();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">this</span>.m_site = <span style="color:blue;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">this</span>.m_siteCreatedByThis = <span style="color:blue;">false</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span><span style="color:blue;">break</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>} </span></p>
<p><span style="font-size:10pt;font-family:&quot;">}</span></div>
<p>So the SPItemEventProperties class actually implements IDisposable and disposes the allocated site or web. The SPEventManager class makes sure to call Dispose() after the batch of event receivers have executed.</p>
<h2>Waiting for ItemAdded to Complete Before Showing EditForm.aspx</h2>
<p>There is an <a href="http://hristopavlov.wordpress.com/2009/02/17/understanding-sharepoint-list-forms/" target="_blank">issue with document libraries and the Upload.aspx page</a> as descibed in my previous blog entry. The problem will be encountered if you have an ItemAdded event receiver attached to the document library that updates fields of the list item/document after it has been created. Because the ItemAdded event receiver runs asynchronously it may update the list item after the EditForm.aspx page has been displayed. This would result either in the EditForm.aspx form to not show the updated fields or in an exception to be generated when you click OK.</p>
<p>In order to solve the problem we need some code to wait for the event receiver to complete before loading the EditForm.aspx page. One way to do this is to customize the EditForm.aspx page either on a Content Type level or a List level or just using SharePoint designer and to insert a web control that will wait for the ItemAdded event receiver to complete. We also need a special ItemAdded event receiver which the web control will be able to communicate with.</p>
<p>And the good news for you is that I did the hard work or creating both the base class for the event receiver and the web control. They can be donwloaded here:</p>
<p><a href="http://www.hristopavlov.net/SPTraceView/SharePointInternals.SynchronousItemAdded.zip">SharePointInternals.SynchronousItemAdded.dll</a></p>
<p><a href="http://www.hristopavlov.net/SPTraceView/SharePointInternals.SynchronousItemAdded.src.zip">SharePointInternals.SynchronousItemAdded &#8211; Source Code</a></p>
<p>To use them you need to create your event receiver class to inherit from the SPSynchronousReceiver class and override the ItemAddedSynchronously method:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">class</span> <span style="color:teal;">SPTestReceiver</span> : <span style="color:teal;">SPSynchronousReceiver</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;font-family:&quot;" lang="EN-US"><span>  </span></span><span style="font-size:10pt;font-family:&quot;"><span>    </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> ItemAddedSynchronously(<span style="color:teal;">SPItemEventProperties</span> properties)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span>  </span></span><span style="font-size:10pt;color:#339966;font-family:&quot;" lang="EN-US">// Your code goes here</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span></span><span style="font-size:10pt;color:#339966;font-family:&quot;" lang="EN-US">// Your other item receiver overrides go here</span><span style="font-size:10pt;font-family:&quot;"><span>    </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
</div>
<p>Then you need to insert the WaitForItemAdded web control in the EditPage.aspx. The best place to do this is as a first control in the PlaceHolderMain.</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;background:yellow;font-family:&quot;">&lt;%</span><span style="font-size:10pt;color:blue;font-family:&quot;">@</span><span style="font-size:10pt;color:maroon;font-family:&quot;">Register</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:red;">TagPrefix</span><span style="color:blue;">=&#8221;SharePointInternals&#8221;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:red;">Assembly</span><span style="color:blue;">=&#8221;SharePointInternals.SynchronousItemAdded, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d7dbdc19a16aed51&#8243;</span> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:red;">namespace</span><span style="color:blue;">=&#8221;SharePointInternals.WebControls&#8221;</span><span style="background:yellow;">%&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"> </p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#339966;font-family:&quot;">&#8230;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:maroon;font-family:&quot;">asp</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:maroon;font-family:&quot;">Content</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:red;">ContentPlaceHolderId</span><span style="color:blue;">=&#8221;PlaceHolderMain&#8221;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePointInternals</span><span style="color:blue;">:</span><span style="color:maroon;">WaitForItemAdded</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;waitForItemAdded1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#339966;">&#8230; </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:maroon;font-family:&quot;">asp</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:maroon;font-family:&quot;">Content</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
</div>
<p>Unfortunately this is the only way to integrate the WaitForItemAdded control. If we add the web control to the ListFormTemplate used by the ListFormWebPart from EditForm.aspx, then it will wait for the event receivers to complete, but at this stage the ListItem would have been already loaded in the SPContext and the EditForm.aspx will show the field values of the list item before the ItemAdded event receivers have completed. If any of them have updated the list item then pressing OK on the EditForm.aspx will actually cause an exception:</p>
<p><em><strong>The file &#8230; has been modified by &#8230; on &#8230;</strong> </em></p>
<p>In order to get around the problem that the ListItem from the SPContext have been initialized we should put the WaitForItemAdded web control somewhere in the EditForm.aspx before the ListFormWebPart and before any other control that may be using SPContext.Current.ListItem. Accessing this property will load the list item which may happen before the asynchronous event receivers have completed.</p>
<p>You can also wait for the ItemAdded event receivers to complete when adding a file using code. This could be handy when doing migration of documents. In order to wait for the event receiver to complete just call SPSynchronousReceiver.WaitForItemAddedReceivers().</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">using</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:teal;">SPSite</span> site = <span style="color:blue;">new</span> <span style="color:teal;">SPSite</span>(<span style="color:maroon;">&#8220;http://server/sites/test&#8221;</span>))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">using</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:teal;">SPWeb </span>web = site.OpenWeb())</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:teal;">SPList</span> list = web.Lists[<span style="color:maroon;">"Shared Documents"</span>];</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:teal;">SPFile </span>file = list.RootFolder.Files.Add(fileName, fileBytes);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:teal;">SPSynchronousReceiver</span>.WaitForItemAddedReceivers(list, file.Item.ID);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
</div>
<p>Of course this will only wait for those event receivers that inherit from the <strong>SPSynchronousReceiver </strong>class. If you need to do the same for another asycnhronous event receiver, this could be easily done by changing the code of the base class.</p>
<p>And for completeness I also want to mention that the <strong>ListItemFileConverted</strong> event receivers execution is initiated from managed code when <strong>SPFile.Convert() </strong>is called. This is the only exception and the execution of all other event receivers is initialized from unmanaged code. The ListItemFileConverted event receivers run asynchronously.</p>
<p>Finally to recap our findings. The execution of all event receivers with the exception of the ListItemFileConverted will be initiated from unmanaged code. This happens when the SharePoint object model calls the corresponding method from the SPRequest unmanaged object to perform the operation that will trigger the event receivers. Then the unmanaged WSS world will use callbacks on the ISPEventManager COM interface implemented by the Microsoft.SharePoint.SPEventManager class to start the event receivers execution on batches of synchronous and asynchronous event receivers. You don&#8217;t have to dispose the SPWeb returned by properties.OpenWeb() in your event receiver code. Sometimes it may be a better idea to create a fresh SPSite and SPWeb instead of using properties.OpenWeb(). It is hard to say which one is good for you as it all depends on the parallel processes that may be running and the other event receivers being executed. All asynchronous event receivers for the given object (list item, list of web) will be executed in a separate thread created on the ThreadPool. SharePoint will queue a new thread for every object. This could potentially cause the server or the application to slow down dramatically as it struggles to switch between the different threads.  The asynchonous event receivers run in the same process in which the object was changed that lead to the event receivers being executed. If you stop the application or reset IIS all running event receivers will be terminated and all scheduled event receivers will not be executed at all. If you do iisreset /noforce this will wait for the event receivers to complete, but they may not be able to update the SharePoint objects they are working with. When you upload a file to a document library there is a nasty problem that you will be redirected to the EditForm.aspx page before the ItemAdded event receivers have completed. If you are doing any changes to the item in the event receivers these changes will not show up when EditForm.aspx page loads. Even more if you press OK in the EditForm.aspx page after the event receivers have modified the item you will get an exception. There is workaround if you use the SharePointInternals.SynchronousItemAdded.dll as described in this blogpost.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/253/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/253/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/253/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=253&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/02/24/understanding-sharepoint-event-receivers/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding SharePoint: List Forms</title>
		<link>http://hristopavlov.wordpress.com/2009/02/17/understanding-sharepoint-list-forms/</link>
		<comments>http://hristopavlov.wordpress.com/2009/02/17/understanding-sharepoint-list-forms/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 03:11:23 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[CONTROLTEMPLATES]]></category>
		<category><![CDATA[Custom]]></category>
		<category><![CDATA[DefaultTemplates.ascx]]></category>
		<category><![CDATA[DispForm]]></category>
		<category><![CDATA[EditForm]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[Form Template]]></category>
		<category><![CDATA[FormTemplates]]></category>
		<category><![CDATA[FormUrls]]></category>
		<category><![CDATA[List Form]]></category>
		<category><![CDATA[ListViewWebPart]]></category>
		<category><![CDATA[NewForm]]></category>
		<category><![CDATA[RenderingTemplate]]></category>
		<category><![CDATA[Uploads.aspx]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=259</guid>
		<description><![CDATA[For my Event Receiver&#8217;s post I had to do some more investigation on how the List Forms work and I thought it will be a good idea to put together my findings. As you know each list has 3 forms &#8211; one for creating a new item, one for editing an existing item and one for displaying an exiting item. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=259&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For my Event Receiver&#8217;s post I had to do some more investigation on how the List Forms work and I thought it will be a good idea to put together my findings. As you know each list has 3 forms &#8211; one for creating a new item, one for editing an existing item and one for displaying an exiting item.</p>
<p>The first place where those forms are defined is in the <a href="http://msdn.microsoft.com/en-us/library/aa543477.aspx" target="_blank">List schema xml</a>. In SharePoint 2003 (WSS 2.0) the forms used to be defined using a complex CAML but from SharePoint 2007 (WSS 3.0) they are implemented in ASPX pages using web controls. The <strong>Form </strong>element in the List schema xml is used to define the aspx page to be used for the given List Form and by default most lists use <strong>NewForm.aspx</strong>, <strong>EditForm.aspx</strong> and <strong>DistForm.aspx</strong> pages.</p>
<p>If necessary the aspx pages for the List forms can be redefined per item content type. This can be achieved by including a <a href="http://msdn.microsoft.com/en-us/library/ms473210.aspx" target="_blank">FormUrls</a> XmlDocument with your custom content type.</p>
<p>So sfter SharePoint has determined from the List schema xml and the ContentType FormUrls element which aspx page should be used it opens up that page. Each of those pages contain a <strong>ListFormWebPart </strong>which does all the job of rendering the list item. SharePoint 2007 still supports legacy forms and you can use the <strong>UseLegacyForm</strong> attribute of the <strong>Form </strong>element in the List schema xml to tell SharePoint you want to use the CALM forms. In such a case the rendering of the List Form will be done from the unmanaged SPRequest class, which will return the HTML to be rendered.</p>
<p>In most of the cases no legacy forms are used and then the ListFormWebPart needs to determine which Form Template has to be used with the List Form. The Form Templates provide a way to further customize the list forms without changing the aspx pages. This is what SharePoint does as it uses exactly the same <strong>NewForm.aspx</strong> page for all new forms but uses different Form Templates for a standard list and for a document library. The Form Templates also allow to customize the list forms for items in the same list but for different content types.</p>
<p>The <strong><a href="http://msdn.microsoft.com/en-us/library/ms468901.aspx" target="_blank">Form Templates</a> </strong>are defined as an XmlDocument per content type and all content types that inherit from the <strong>Item</strong> content type also inherit the Form Templates as defined in the <strong>Item</strong> Content Type. All forms use a Form Template called <strong>ListForm</strong>.</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="line-height:normal;margin:0;"> <span style="font-size:10pt;color:blue;font-family:'Courier New';">&lt;</span><span style="font-size:10pt;color:maroon;font-family:'Courier New';">FormTemplates</span><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:red;">xmlns</span><span style="color:blue;">=&#8221;http://schemas.microsoft.com/sharepoint/v3/contenttype/forms&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">Display</span><span style="color:blue;">&gt;</span>ListForm<span style="color:blue;">&lt;/</span><span style="color:maroon;">Display</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">Edit</span><span style="color:blue;">&gt;</span>ListForm<span style="color:blue;">&lt;/</span><span style="color:maroon;">Edit</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">New</span><span style="color:blue;">&gt;</span>ListForm<span style="color:blue;">&lt;/</span><span style="color:maroon;">New</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;color:blue;line-height:115%;font-family:'Courier New';">&lt;/</span><span style="font-size:10pt;color:maroon;line-height:115%;font-family:'Courier New';">FormTemplates</span><span style="font-size:10pt;color:blue;line-height:115%;font-family:'Courier New';">&gt;</span></p>
</div>
<p>However not all forms in SharePoint use these Form Templates. For example they are redefined by the <strong>Document</strong> content type (and all content types that inherit from <strong>Document</strong>) and they use a Form Template called <strong>DocumentLibraryForm</strong> instead of <strong>ListForm</strong>. </p>
<p><img class="alignnone size-full wp-image-262" title="listforms" src="http://hristopavlov.files.wordpress.com/2009/02/listforms.jpg" alt="listforms" width="617" height="461" /></p>
<p>The next question is where those Form Templates come from and the answer is they usually come from the <strong>12\TEMPLATE\CONTROLTEMPLATES\DefaultTemplates.ascx page</strong>. The form templates are simply <strong>RenderingTemplate </strong>web controls and define the sets of controls to be added to the List Form. The Form Templates are matched by their ID attribute and it is actually possible to overwrite an existing template or define your own Form Templates and deploy them in an ascx page in  <strong>12\TEMPLATE\CONTROLTEMPLATES. </strong></p>
<p>The code below shows the standard ListForm templates used by all generic lists:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:maroon;font-family:&quot;">SharePoint</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:maroon;font-family:&quot;">RenderingTemplate</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ListForm&#8221;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">&lt;</span><span style="color:maroon;">Template</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SPAN</span> <span style="color:red;">id</span><span style="color:blue;">=&#8217;part1&#8242;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">InformationBar</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;InformationBar1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">wssuc</span><span style="color:blue;">:</span><span style="color:maroon;">ToolBar</span> <span style="color:red;">CssClass</span><span style="color:blue;">=&#8221;ms-formtoolbar&#8221;</span> <span style="color:red;">id</span><span style="color:blue;">=&#8221;toolBarTbltop&#8221;</span> <span style="color:red;">RightButtonSeparator</span><span style="color:blue;">=&#8221;&amp;nbsp;&#8221;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span>                        </span><span style="color:blue;">&lt;</span><span style="color:maroon;">Template_RightButtons</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">NextPageButton</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;NextPageButton1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">SaveButton</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;SaveButton1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">GoBackButton</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;GoBackButton1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                              </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">Template_RightButtons</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">wssuc</span><span style="color:blue;">:</span><span style="color:maroon;">ToolBar</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">FormToolBar</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;FormToolBar1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">TABLE</span> <span style="color:red;">class</span><span style="color:blue;">=&#8221;ms-formtable&#8221;</span> <span style="color:red;">style</span><span style="color:blue;">=&#8221;margin-top: 8px;&#8221;</span> <span style="color:red;">border</span><span style="color:blue;">=0</span> <span style="color:red;">cellpadding</span><span style="color:blue;">=0</span> <span style="color:red;">cellspacing</span><span style="color:blue;">=0</span> <span style="color:red;">width</span><span style="color:blue;">=100%&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">ChangeContentType</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ChangeContentType1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">FolderFormFields</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;FolderFormFields1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">ListFieldIterator</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ListFieldIterator1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">ApprovalStatus</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ApprovalStatus1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">FormComponent</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;FormComponent1&#8243;</span> <span style="color:red;">TemplateName</span><span style="color:blue;">=&#8221;AttachmentRows&#8221;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">TABLE</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">table</span> <span style="color:red;">cellpadding</span><span style="color:blue;">=0</span> <span style="color:red;">cellspacing</span><span style="color:blue;">=0</span> <span style="color:red;">width</span><span style="color:blue;">=100%&gt;&lt;</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;&lt;</span><span style="color:maroon;">td</span> <span style="color:red;">class</span><span style="color:blue;">=&#8221;ms-formline&#8221;&gt;&lt;</span><span style="color:maroon;">IMG</span> <span style="color:red;">SRC</span><span style="color:blue;">=&#8221;/_layouts/images/blank.gif&#8221;</span> <span style="color:red;">width</span><span style="color:blue;">=1</span> <span style="color:red;">height</span><span style="color:blue;">=1</span> <span style="color:red;">alt</span><span style="color:blue;">=&#8221;"&gt;&lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">table</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">TABLE</span> <span style="color:red;">cellpadding</span><span style="color:blue;">=0</span> <span style="color:red;">cellspacing</span><span style="color:blue;">=0</span> <span style="color:red;">width</span><span style="color:blue;">=100%</span> <span style="color:red;">style</span><span style="color:blue;">=&#8221;padding-top: 7px&#8221;&gt;&lt;</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;&lt;</span><span style="color:maroon;">td</span> <span style="color:red;">width</span><span style="color:blue;">=100%&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">ItemHiddenVersion</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ItemHiddenVersion1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">ParentInformationField</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;ParentInformationField1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">InitContentType</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;InitContentType1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;</span><span style="color:maroon;">wssuc</span><span style="color:blue;">:</span><span style="color:maroon;">ToolBar</span> <span style="color:red;">CssClass</span><span style="color:blue;">=&#8221;ms-formtoolbar&#8221;</span> <span style="color:red;">id</span><span style="color:blue;">=&#8221;toolBarTbl&#8221;</span> <span style="color:red;">RightButtonSeparator</span><span style="color:blue;">=&#8221;&amp;nbsp;&#8221;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                              </span><span style="color:blue;">&lt;</span><span style="color:maroon;">Template_Buttons</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">CreatedModifiedInfo</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;CreatedModifiedInfo1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span>            </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">Template_Buttons</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                              </span><span style="color:blue;">&lt;</span><span style="color:maroon;">Template_RightButtons</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">SaveButton</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;SaveButton2&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                                    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">GoBackButton</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;GoBackButton2&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                              </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">Template_RightButtons</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">wssuc</span><span style="color:blue;">:</span><span style="color:maroon;">ToolBar</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                  </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;&lt;/</span><span style="color:maroon;">TABLE</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">SPAN</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">&lt;</span><span style="color:maroon;">SharePoint</span><span style="color:blue;">:</span><span style="color:maroon;">AttachmentUpload</span> <span style="color:red;">ID</span><span style="color:blue;">=&#8221;AttachmentUpload1&#8243;</span> <span style="color:red;">runat</span><span style="color:blue;">=&#8221;server&#8221;/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">Template</span><span style="color:blue;">&gt;</span></span></p>
<p><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:maroon;font-family:&quot;">SharePoint</span><span style="font-size:10pt;color:blue;font-family:&quot;">:</span><span style="font-size:10pt;color:maroon;font-family:&quot;">RenderingTemplate</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></div>
<p>You can probably recognize all the controls you have seen many times in those NewForm.aspx pages. There are many &#8220;interesting&#8221; controls in that form, such as the ListFieldIterator, InitContentType, SaveButton, AttachmentUpload. A detailed information on how to customize your ListForms, include custom fields and customize the Form Templates could be found in the following <a href="http://msdn.microsoft.com/en-us/library/aa543232.aspx" target="_blank">MSDN article</a>.</p>
<h3>Issues with Document Libraries and _layouts/Upload.aspx</h3>
<p>There is one specific issue when using a <strong>NewForm</strong> with a <strong>ListFormWebPart </strong>in a <strong>Document Library</strong>. You will be unconditionally redirected to the <strong>_layouts/Upload.aspx</strong> page so you can upload the file first. After the file is uploaded you will be redirected to the <strong>EditForm</strong>. So what does this mean:</p>
<p>- Well first of all the &#8220;List Form&#8221; and &#8220;Form Template&#8221; of  the <strong>NewForm </strong>are actually not used because you will be unconditionally redirected to the Upload.aspx page. Of course you have the alternative of creating a custom New Form that _<strong>does</strong> <strong>not_</strong> contain a <strong>ListFormWebPart</strong>. However all the SharePoint Field controls require to be inside a <strong>ListFormWebPart</strong> so you won&#8217;t be able to use those. You can actually use the SharePoint Field controls without a ListFormWebPart but you will need to create a new <strong>SPContext</strong> object in the Page.OnInit() event using reflection and set the ItemContext property of the SharePoint Field web control. No need to say that this will probably not be supported by Microsoft.</p>
<p>- Secondly the <strong>ItemAdded</strong> and <strong>ItemAdding</strong> event receivers will be initiated from the <strong>Upload.aspx </strong>page after the file is uploaded and a blank list item has been created. However this happens before you are redirected to the Edit Form and before the user has filled in the metadata of the document. Even worse the <strong>ItemAdded</strong> event receiver is executed asynchronously and there is no guarantee when it will be run. Depending on how loaded is the server and how quick the user clicks &#8220;Check In&#8221; on the Edit Form, the <strong>ItemAdded</strong> event receiver can be actually executed after the Edit Form has been submitted! Also if you rely the <strong>ItemAdded </strong>event receiver to set some default values for the item after it has been created, which values  you expect to be displayed in the Edit Form, it is quite possible that the <strong>ItemAdded</strong> will be executed after the Edit Form has rendered the old values of the item (before they have been changed by the event receiver).</p>
<p>- Lastly if you press &#8220;Cancel&#8221; on the Edit Form after the file has been already uploaded the file and the list item may remain in a strange state where it is only visible to the person who has uploaded the file and is even not visible to the system account. This happens when the document library is in a &#8220;Force Check Out&#8221; mode. See more in <a href="http://hristopavlov.wordpress.com/2008/06/24/content-type-is-still-in-use/" target="_self">this post</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/259/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/259/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/259/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=259&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/02/17/understanding-sharepoint-list-forms/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>

		<media:content url="http://hristopavlov.files.wordpress.com/2009/02/listforms.jpg" medium="image">
			<media:title type="html">listforms</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding SharePoint: SPRequest</title>
		<link>http://hristopavlov.wordpress.com/2009/01/19/understanding-sharepoint-sprequest/</link>
		<comments>http://hristopavlov.wordpress.com/2009/01/19/understanding-sharepoint-sprequest/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 04:07:04 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[different threads]]></category>
		<category><![CDATA[IDisposable]]></category>
		<category><![CDATA[OWSSVR]]></category>
		<category><![CDATA[RPC_E_ATTEMPTED_MULTITHREAD]]></category>
		<category><![CDATA[RunWithElevatedPrivilegies]]></category>
		<category><![CDATA[SP.SPRequest]]></category>
		<category><![CDATA[SPRequest]]></category>
		<category><![CDATA[SPSite]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=138</guid>
		<description><![CDATA[I am going to put together a series of &#8216;Understanding SharePoint&#8217; posts and cover various important parts of SharePoint which are not very well understood or for which there is little or no information on the net. The first post will be about possibly the most important class in SharePoint called SPRequest - an internal class from the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=138&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am going to put together a series of &#8216;Understanding SharePoint&#8217; posts and cover various important parts of SharePoint which are not very well understood or for which there is little or no information on the net. The first post will be about possibly the most important class in SharePoint called <strong>SPRequest </strong>- an internal class from the SharePoint object model.</p>
<p>It may come as a surprise to you (which only shows how little it has been written about this) but most of the &#8216;important&#8217; things in SharePoint are actually done through unmanaged code and the SharePoint .NET object model provided by the Microsoft.SharePoint.dll is a sort of a wrapper to this unmanaged world. Understanding how your code does what you want it to do can be very helpful when troubleshooting issues, fixing bugs, doing performance tuning and writing solid code in general so I believe that every SharePoint developer should know about <strong>SPRequest</strong>.</p>
<p>As you are aware the gateway to doing anything in SharePoint is the <strong>SPSite </strong>object. In order to get to any other objects that reside in a site collection such as <strong>SPWeb</strong>, <strong>SPList</strong>, <strong>SPListItem</strong>, <strong>SPFile</strong> and others we first need to obtain an <strong>SPSite </strong>and there is a very good reason for that. Every <strong>SPSite </strong>instance holds a reference to the unmanaged WSS world in the means of a field member of type <strong>SPRequest</strong> which is called m_Request. The internal <strong>SPRequest </strong>class has an unmanaged reference to a COM object called <em>SP.SPRequest</em> and having a ClassID of BDEADEE2-C265-11D0-BCED-00A0C90AB50F which is implemented in and exposed by the OWSSVR.DLL class library.</p>
<p>The <em>SP.SPRequest</em> COM object exposes almost 400 basic operations and almost everything you do with the Microsoft.NET managed SharePoint object model that reads from or writes to the ContentDatabase (including data, fields, content types, list schemas, etc) will actually go via this unmanaged COM object. Even more the OWSSVR.DLL is actually an ISAPI extension registered in IIS and its methods can be called directly via an HTTP request to /_vti_bin/owssvr.dll. Many of the Office applications (Word, Excel, InfoPath, SharePoint Designer etc) are using HTTP calls to OWSSRV directly in order to integrate with a remote SharePoint server. It won&#8217;t be too much of an exaggeration to say that OWSSRV.DLL is the soul and body of WSS 3.0. It comes historically from SharePoint ver 1.0 from the days before Microsoft.NET when web applications were developed using technologies like ISAPI and DCOM. For more information on OWSSRV and the WSS architecture have a look at the <a href="http://msdn.microsoft.com/en-us/library/ms947858.aspx" target="_blank">Overview of the SharePoint Team Services Architecture</a> in MSDN.</p>
<p>Let&#8217;s now have a look at the public <strong>ISPRequest</strong> interface which is implemented by the <em>SP.SPRequest</em> COM object and is available for .NET via the <strong>SPRequest </strong>class. The list below shows only a fraction of the ~400 actions exposed by this COM object and demonstrates what sort of operations are done through the <strong>SPRequest </strong>class. As you can see this is pretty much everything in WSS:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';">[</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">ComImport</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">"BDEADEBE-C265-11D0-BCED-00A0C90AB50F"</span>), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">ComConversionLoss</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">TypeLibType</span>((<span style="color:blue;">short</span>)0x100), </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">SuppressUnmanagedCodeSecurity</span>, </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">InterfaceType</span>((<span style="color:blue;">short</span>)1)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';">]</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:'Courier New';">public</span><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:blue;">interface</span> <span style="color:#2b91af;">ISPRequest</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> GetFieldsSchemaXml(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> GetViewsSchemaXml(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">string </span>CreateList(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>DeleteList(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> QueryUserInfo(<span style="color:#00b050;">&#8230;</span>);<span>        </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">string </span>AddField(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>RemoveField(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>UpdateField(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> GetMetadataForUrl(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>DeleteView(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>UpdateView(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>CreateView(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> AddOrUpdateItem(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>DeleteItem(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> GetAttachmentsInfo(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>CrossListQuery(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> RenderViewAsHtml(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>UpdateUser(<span style="color:#00b050;">&#8230;</span>);<span>        </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>BackupSite(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>CreateSite(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>DeleteSite(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>OpenSite(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>SetSiteProps(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> GetAllWebsOfSite(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> UpdateFileOrFolderProperties(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>PutFile(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>GetFile(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>CheckOutFile(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>CheckInFile(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>CreateWeb(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> SaveWebAsTemplate(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>OpenWeb(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">string </span>ApplyTheme(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">int </span>AddRoleDef(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>AddWebPart(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> CreateListViewPart(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>GetTimeZoneInfo(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>AddMeeting(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>GetSiteQuota(<span style="color:#00b050;">&#8230;</span>);<span>        </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>RegisterEventReceiver(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> InvokeTimerJob(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> GetListContentTypes(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void</span> AddWorkflowToListItem(<span style="color:#00b050;">&#8230;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">void </span>SetGhostedFile(<span style="color:#00b050;">&#8230;</span>);<span>        </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:blue;">int </span>AddNavigationNode(<span style="color:#00b050;">&#8230;</span>);<span>        </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#00b050;">&#8230;</span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:'Courier New';">}</span></p>
</div>
<p>To see the full list of methods exposed by <strong>SPRequest</strong> you can open up this class in Reflector. In order to do this you first need to get the <strong>Microsoft.SharePoint.Library </strong>assembly from the GAC. To get a physical copy of this file you can go Start -&gt; Run -&gt; type &#8216;C:\WINDOWS\ASSEMBLY\GAC_MSIL&#8217;  -&gt; press &#8216;Enter&#8217;. This is a little trick that will open up the physical store of the GAC assemblies. And remember you must do this from Start -&gt; Run &#8211; it will not work otherwise. So once you have it opened, navigate to Microsoft.SharePoint.Library\12.0.0.0__71e9bce111e9429c and copy the file to a place you can open it with Reflector.</p>
<p><strong>[Updated 23 Jan]</strong></p>
<p><strong>ISPRequest</strong> is actually a COM interface and the public <strong>SPRequestInternalClass </strong>from the Microsoft.SharePoint.Library.dll is a wrapper to it. The ISAPI extension  /_vti_bin/owssvr.dll can be used to do various things as documented in the <a href="http://msdn.microsoft.com/en-us/library/ms478653.aspx" target="_blank">Windows SharePoint Services URL Protocol</a>.</p>
<p>Even that the <strong>SPRequestInternalClass</strong> is public it is actually undocumented according to the Microsoft SharePoint Escalation Engineer Stefan Gossner. (See his comment below and the link to his blog <a href="http://blogs.technet.com/stefan_gossner/archive/2005/07/27/undocumented_API_Part1.aspx" target="_blank">Documented / Undocumented API &#8211; Why Should I care?</a>).  Stefan also points out that any SharePoint database which is modified using <span class="yshortcuts" style="background:none transparent scroll repeat 0 0;cursor:hand;border-bottom:medium none;">direct access</span> to this undocumented API will become an unsupported state as if you would have modified the database using direct <span class="yshortcuts" style="background:none transparent scroll repeat 0 0;cursor:hand;border-bottom:medium none;">SQL queries. So be warned! </span></p>
<p><strong>[/Updated 23 Jan]</strong></p>
<p>So now that we know that when we call the SharePoint .NET object model almost everything is done via unmanaged code the next question is what is the implication of this. Well firstly this means there are unmanaged objects being created all the time, and those objects cannot be cleaned up automatically by the .NET garbage collector. This is exactly why it is so important to call Dispose() or Close() on an <strong>SPSite</strong> when we have finished using it as we need to free those unmanaged resources. If we don&#8217;t do this they will cause unmanagedmemory leaks and will severely slow down the server. We need to call Close()/Dispose() with every object that implements the IDisposable interface and from the &#8216;common&#8217; SharePoint objects this are both the <strong>SPSite</strong> and <strong>SPWeb</strong> class instances.</p>
<p>If you try to allocate too many <strong>SPRequest</strong> objects (create too many <strong>SPSites</strong>) without releasing them you will start getting medium severity trace messages in the ULS Log similar to the one below:</p>
<p><span style="font-size:10pt;color:#800000;font-family:'Century Gothic';">&#8220;Potentially excessive number of SPRequest objects (10) currently unreleased on thread 23. Ensure that this object or its parent (such as an SPWeb or SPSite) is being properly disposed. This object will not be automatically disposed.&#8221;</span></p>
<p>There are two registry keys you can use to control the ULS trace log related to allocating and disposing <strong>SPRequest </strong>objects. Firstly the warning threshold can be controlled via the <strong>LocalSPRequestWarnCount</strong> value in the <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions</strong>. You should however always try to have a minimal number of <strong>SPSite </strong>objects created at the same time and should always dispose them as soon as you&#8217;ve finished working with them. Secondly to get the stack trace of the not correctly disposed <strong>SPRequests</strong> (which is not enabled by default) you can set a value of 1 for <strong>SPRequestStackTrace </strong> in the <strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings </strong>registry key.  You can monitor the ULS trace messages in real time using the very light-weight <a href="http://hristopavlov.wordpress.com/sptraceview/" target="_blank">SPTraceView</a> utility. For detailed information and best practices on disposing SharePoint objects see the following MSDN article: <a href="http://msdn.microsoft.com/en-us/library/aa973248.aspx" target="_blank">Best Practices: Using Disposable Windows SharePoint Services Objects</a></p>
<p>Because creating too many unmanaged objects is a serious concern for a server application, Microsoft have implemented a couple of ways for those <strong>SPRequest</strong> objects to be cached and reused internally whenever this is possible. However this caching might cause additional problems such as: Reusing a cached version when you don&#8217;t really want this or attempting to reuse a cached version of the <strong>SPRequest</strong> on a thread different from the thread it has been created on. Before looking into those potential issues lets see how the caching of <strong>SPRequests</strong> works.</p>
<p>For managing the <strong>SPRequests </strong>SharePoint gets the help of two internal classes &#8211; <strong>SPRequestManager</strong> and <strong>SPRequestContext</strong>.  All <strong>SPRequest </strong>objects created in the managed world of Microsoft.NET are tracked and cached per process using an <strong>SPRequestManager</strong> object which singleton instance is saved in the <strong>HttpContext</strong> for web applications or in the <strong>ThreadContext </strong>of the SPFarm for non web applications (such as OWS Timer jobs, command line application such as custom STSADM commands or rich clients). This also means that this caching is per thread. The code below shows how the <strong>SPRequestManager</strong> is created and associated with the running thread:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">private</span><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:#0000ff;">static</span> <span style="color:#2b91af;">SPRequestManager</span> Instance</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#0000ff;">get</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#2b91af;">SPRequestManager</span> manager = <span style="color:#0000ff;">null</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#0000ff;">if</span> (<span style="color:#2b91af;">HttpContext</span>.Current == <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span>manager = <span style="color:#2b91af;">SPFarm</span>.ThreadContext[<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">SPRequestManager</span>)] <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">SPRequestManager</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#0000ff;">else</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span>manager = <span style="color:#2b91af;">HttpContext</span>.Current.Items[<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">SPRequestManager</span>)] <span style="color:#0000ff;">as</span> <span style="color:#2b91af;">SPRequestManager</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#0000ff;">if</span> (manager == <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span>manager = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SPRequestManager</span> ();</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span><span style="color:#0000ff;">if</span> (<span style="color:#2b91af;">HttpContext</span>.Current == <span style="color:#0000ff;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>                </span><span style="color:#2b91af;">SPFarm</span>.ThreadContext[<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">SPRequestManager</span>)] = manager;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>                </span><span style="color:#0000ff;">return</span> manager;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>            </span><span style="color:#2b91af;">HttpContext</span>.Current.Items[<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">SPRequestManager</span>)] = manager;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#0000ff;">return</span> manager;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>}</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';">}</span></div>
<p> Additionally to this the SharePoint Object Model may be also caching the opened <strong>SPSites </strong>when running in a web context. This caching is done with the help of the <strong>SPRequestContext</strong> class which single instance is stored in the HttpContext per server thread that processes the request.</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">internal</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">static</span> <span style="color:#2b91af;">SPRequestContext </span>GetCurrent(<span style="color:#2b91af;">HttpContext</span> context)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">if</span> (context != <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">string </span>str = <span style="color:#a31515;">&#8220;HttpHandlerSPRequestContext&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:#2b91af;">SPRequestContext</span>reqContext = (<span style="color:#2b91af;">SPRequestContext</span>)context.Items[str];</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span>(reqContext== <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>reqContext= <span style="color:blue;">new</span> <span style="color:#2b91af;">SPRequestContext</span>(context);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>context.Items[str] = reqContext;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">return</span>reqContext;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">return</span> <span style="color:blue;">null</span>;</span></p>
<p><span style="font-size:10pt;font-family:&quot;">}</span></div>
<p>The site instances will be cached only if they <strong>have not </strong>been created with a farm admin account (when SPSite.m_bAdministratorOperationMode is false) . Please note that runing code using <strong>SPUtility.RunWithElevatedPrivilegies() </strong>method doesn&#8217;t mean your code will have farm administrator privileges. Whether a user is a farm administrator or not is determined by the <strong>SPFarm.CurrentUserIsAdministrator()</strong> method. An account will be a  farm admin if:</p>
<p>- It is the identity of the application pool used by the SharePoint Central Administration web application</p>
<p>- The account has been added to the SharePoint Administrators site group of the Central Administration web application</p>
<p>- The farm is being provisioned and the account is a local administrator or the Local System account</p>
<p>When you are using  <strong>SPUtility.RunWithElevatedPrivilegies() </strong>this will simply revert the current user identity to the identity of the current application pool, and if this identity is not a farm administrator then your <strong>SPSite</strong> _will_ be cached in the <strong>SPRequestContext</strong>. This is done when the <strong>SPSite</strong> object is created:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:#0000ff;font-family:'Courier New';">private</span><span style="font-size:10pt;font-family:'Courier New';"> <span style="color:#0000ff;">void</span> SPSiteConstructor(</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">SPFarm</span> farm, <span style="color:#2b91af;">Guid </span>applicationId, <span style="color:#2b91af;">Guid</span> contentDatabaseId, <span style="color:#2b91af;">Guid </span>siteId, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">SPUrlZone</span> zone, <span style="color:#2b91af;">Uri </span>requestUri, <span style="color:#0000ff;">string </span>serverRelativeUrl, <span style="color:#0000ff;">bool</span> hostHeaderIsSiteName, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#2b91af;">Uri </span>redirectUri, Pairing pairing, <span style="color:#2b91af;">SPUserToken </span>userToken)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>&#8230;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#0000ff;">if</span> (<span style="color:#2b91af;">SPSecurity</span>.ImpersonatingSelf &amp;&amp; (userToken == <span style="color:#0000ff;">null</span>))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#008000;">// We will enter here if the site is created inside SPUtility.RunWithElevatedPrivilegies()</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#0000ff;">this</span>.m_bAdministratorOperationMode = <span style="color:#2b91af;">SPSecurity</span>.ProcessIdIsGlobalAdmin;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#008000;"><span style="color:#000000;">&#8230;</span></span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span><span style="color:#0000ff;">if</span> (!<span style="color:#0000ff;">this</span>.m_bAdministratorOperationMode)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#008000;">// The site is cached here and may be reused when activating features</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>        </span><span style="color:#2b91af;">SPRequestContext</span>.RegisterSite(<span style="color:#0000ff;">this</span>);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:'Courier New';"><span>    </span>&#8230;</span></p>
<p><span style="font-size:10pt;font-family:'Courier New';">}</span></div>
<p>The following diagram shows at a high level the relationship between the various objects working with <strong>SPRequests</strong>:</p>
<p><img class="alignnone" src="http://hristopavlov.files.wordpress.com/2008/10/sprequest2.jpg?w=708&#038;h=279" alt="" width="708" height="279" /></p>
<p> </p>
<p>As you see one of  the classes I added on the above diagram is the <strong>SPFeatreManager </strong>class. This class can be actually called from the unmanaged world to activate features when you are provisioning a WSS site and this is when a cached <strong>SPSite </strong>may get reused. Here is what will happen every time you create a site or a web from a Web-based SharePoint application (web part, aspx page or SharePoint itself) if the WSS site definition you are using has some features to be activated:</p>
<p>- Before you can initiate a site creation first there must be an <strong>SPSite </strong>object created. This will be either done by the SharePoint UI code behind or by you directly creating the <strong>SPSite</strong>. If the user identity used to create the site is not a farm administrator then the <strong>SPSite </strong>will be cached by SiteId and by UserToken in the current <strong>SPRequestContext</strong>.</p>
<p>- You now initiate a new site creation for example by calling SPWebCollection.Add()</p>
<p>- The SharePoint Object Model calls the corresponding unmanaged function of the <em>SP.SPRequest</em> COM object to create the site. This is <em>ISRequest.CreateWeb()</em></p>
<p>- Based on the WSS site definition to be used for the site, there may be features to be activated. The <em>SP.SPRequest</em> COM object makes calls back to .NET using the <em>ISPFeatureManager</em> COM visible interface of the <strong>Microsoft.SharePoint.SPFeatureManager</strong> managed class in order to activate those features. It possibly calls EnsureTemplateAssociatedWebFeaturesActivated(). This results in any existing <strong>SPSites</strong>cached in the same HttpRequest for the same user to be reused. The SPFeatureManager.EnsureSite() method will reuse the cached <strong>SPSite</strong> or create a new one if there is no cached (when not running in HttpContext).</p>
<p>Now if you are using custom site definitions and depending on how complex are they i.e. how many features do you have and what they are doing, in some cases because the cached <strong>SPSite</strong> will be reused, you may get some very weird errors particularly when trying to provision two sites at the same time. Some of those errors which I have seen at least a couple of times each include:</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>System.InvalidOperationException : <strong><em>You cannot invalidate the SPRequest object while it&#8217;s in use.</em></strong><br />
Source: Microsoft.SharePoint; Help Link: <br />
Stack Trace:    at Microsoft.SharePoint.Library.SPRequest.ReleaseResources()<br />
    at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)<br />
    at Microsoft.SharePoint.SPWeb.Invalidate()<br />
    at Microsoft.SharePoint.SPWeb.Close()<br />
    at Microsoft.SharePoint.SPSite.Close()<br />
    at Microsoft.SharePoint.SPSite.Dispose()</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>System.Runtime.InteropServices.COMException : <strong><em>Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0&#215;80010102 (RPC_E_ATTEMPTED_MULTITHREAD))</em></strong><br />
Stack Trace:    at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, ISP2DSafeArrayWriter p2DWriter, Int32&amp; plRecycleBinCount)<br />
                       at Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32 dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32 dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean bGetSecurityData, ISP2DSafeArrayWriter p2DWriter, Int32&amp; plRecycleBinCount)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>ExeName: w3wp.exe, Machine: localhost, Severity: Unexpected, Product: &#8216;Windows SharePoint Services&#8217;, Category: &#8216;General&#8217;<br />
<strong><em>ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads</em></strong>. ThreadId = 24, Free call stack =    at Microsoft.SharePoint.SPRequestManager.Release(SPRequest request)<br />
    at Microsoft.SharePoint.SPWeb.Invalidate()<br />
    at Microsoft.SharePoint.SPWeb.Close()<br />
    at Microsoft.SharePoint.SPContentType.CloseWebAsNecessary()<br />
    at Microsoft.SharePoint.SPWeb.Close()<br />
    at Microsoft.SharePoint.SPSite.Close()<br />
    at Microsoft.SharePoint.SPSite.Dispose()</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>All of the 3 errors suggest that a cached <strong>SPSite</strong> may have been reused from a different thread, when it actually shouldn&#8217;t have been. It is very difficult to say why those errors do occur but I believe it has to do with the <strong>SPRequestContext</strong> caching some <strong>SPSites </strong>which are being reused when activating features. One of the facts that supports this theory is that you don&#8217;t get those errors when you are creating the sites from a non HttpContext application such as a custom STSADM command for example. In that case there is no HttpRequest and no <strong>SPRequestContext</strong> class i.e. no <strong>SPSites </strong>are being cached and reused. One of the times when I was getting those errors and was trying to resolve the problem I found a couple of post in Internet from people having the same problem but there were no resolutions. Almost everyone experiencing those errors was saying that they don&#8217;t get the errors when their code was called by a console application (custom STSADM command).  I wasn&#8217;t able to resolve the issue and it left as a known issue in the product. If you have experienced the same problem and have managed to nail it down I would love to hear about your findings/resolution. To mitigate the risk of getting those errors I would suggest that you should:</p>
<p>- Avoid using custom WSS site definitions if they include custom feature receivers that contain complex code</p>
<p>- Consider provisioning your sites from a non HttpContext application whenever possible. OWSTimer jobs count as non HttpContext way of provisioning sites</p>
<p>Also remember that you may be getting those errors for a different reason that is completely unrelated to the <strong>SPRequestContext</strong> cache. For example if you really are trying to reuse <strong>SPWeb</strong> or <strong>SPSite</strong> on a different thread or if you are not disposing properly the <strong>SPSite</strong>/<strong>SPWeb</strong>.</p>
<p>And finally lets recap the story about the <strong>SPRequest</strong>. Almost all read/write content/metadata operations that you do using the .NET SharePoint object model use unmanaged class to do the job. This unmanaged class is called <em>SP.SPRequest</em> and is used from .NET via the <strong>SPRequest</strong> internal class. The class is implemented and exposed by the OWSSRV.DLL library and has almost 400 methods. Because the <strong>SPSite</strong> and <strong>SPWeb</strong> objects have a reference to unmanaged objects you must keep the number of <strong>SPSite</strong>/<strong>SPWeb</strong> objects that are active at the same time to a minimum and should dispose them as soon as you have finished using them. You can monitor the creation and disposal of <strong>SPRequest</strong> objects via the ULS log. In order to minimize the number of <strong>SPRequests</strong> used in a HttpContext application, SharePoint uses internal cache. It is possible your <strong>SPSite</strong> objects to be reused when you are creating a site or a web from a web application which site/web is based on a custom WSS site definition that contains custom feature receivers. In rare cases you may be getting errors because of this so if you are using custom WSS site definitions then keep the complexity of your custom feature receivers to a minimum. Consider creating your sites from a non HttpContext application such as an STSADM command, Windows Forms application or a OWSTimer job.</p>
<p>I hope you&#8217;ve enjoyed this not very short reading. My next post in the &#8220;Understanding SharePoint&#8221; series, which will not necessarily be my next post, will be about how asynchronous Event Receivers work in SharePoint and what traps people can get into.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=138&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/01/19/understanding-sharepoint-sprequest/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>

		<media:content url="http://hristopavlov.files.wordpress.com/2008/10/sprequest2.jpg" medium="image" />
	</item>
		<item>
		<title>The column name that you entered is already in use or reserved. Choose another name.</title>
		<link>http://hristopavlov.wordpress.com/2009/01/15/the-column-name-that-you-entered-is-already-in-use-or-reserved-choose-another-name/</link>
		<comments>http://hristopavlov.wordpress.com/2009/01/15/the-column-name-that-you-entered-is-already-in-use-or-reserved-choose-another-name/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 03:34:54 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[concat]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[doesFieldNameConflict]]></category>
		<category><![CDATA[fldnew.aspx]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[pop]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[shift]]></category>
		<category><![CDATA[slice]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[splice]]></category>
		<category><![CDATA[unshift]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=224</guid>
		<description><![CDATA[This is an annoying one. SharePoint will not allow you to create a site column from the UI (using the _layouts/fldnew.aspx page) if the name of the column is one of: constructor, concat, join, pop, push, reverse, shift, slice, sort, splice or unshift even if these site columns do not exist in the SharePoint site. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=224&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is an annoying one. SharePoint will not allow you to create a site column from the UI (using the _layouts/fldnew.aspx page) if the name of the column is one of:</p>
<p><strong>constructor</strong>, <strong>concat</strong>, <strong>join</strong>, <strong>pop</strong>, <strong>push</strong>, <strong>reverse</strong>, <strong>shift</strong>, <strong>slice</strong>, <strong>sort</strong>, <strong>splice</strong> or <strong>unshift</strong></p>
<p>even if these site columns do not exist in the SharePoint site. If you try to create one of these fields you will get an error message saying that:</p>
<p><em>The column name that you entered is already in use or reserved. Choose another name.</em></p>
<p>Hmmm &#8230; Well after investigating this one it turned out to be a genuine bug caused by a JavaScript artifact. The way the fldnew.aspx page checks at the client side if a column already exists is by having all existing columns stored in a JavaScript Array called <em>g_FieldName</em> and then checking if the column that user tries to create is already in the array. This is done by the following code:</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">&#8230;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">g_FieldName[<span style="color:#a31515;">"E-Mail"</span>.toLowerCase()] = 1;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">g_FieldName[<span style="color:#a31515;">"Type"</span>.toLowerCase()] = 1;</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">&#8230;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">function </span><span style="font-size:10pt;font-family:&quot;">doesFieldNameConflict( strName )</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span>(g_FieldName[strName.toLowerCase()])</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
</div>
<p>The problem with this code is that for some unknown to me reason which is probably related to the way the JavaScript VM is implemented, if you create a new Array called <strong>arr</strong> and then try to read <strong>arr["shift"]</strong> for example, this will return the following string:</p>
<p> <img class="alignnone size-full wp-image-227" title="shift" src="http://hristopavlov.files.wordpress.com/2009/01/shift.jpg" alt="shift" width="194" height="139" /></p>
<p>And this happens on both Internet Explorer and Firefox. And this will happen for all strings that are names of methods of the JavaScript Array object and this is case sensitive. Because SharePoint does the check in lower case, then only the methods that are entirely in lower case will be a problem and the list of SharePoint site columns you won&#8217;t be able to create from the UI given at the top is the list of all methods of the Array object that are fully lower case.</p>
<p>So how to get around this. Well first of all this is a bug that should be resolved by Microsoft. They could either store everything in upper case (no JavaScript methods are fully upper case) or can change the function to</p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">function </span><span style="font-size:10pt;font-family:&quot;">doesFieldNameConflict( strName )</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">if</span>(g_FieldName[strName.toLowerCase()] == 1)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">return</span> <span style="color:blue;">true</span>;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
</div>
<p>The problem with the first function is that <strong>g_FieldName[strName.toLowerCase()] </strong>will be evaluated to true for anything which is not 0, false, null or unknown. In the case of arr["shift"] it will return the string shown on the screen-shot above, which will be evaluated to &#8220;true&#8221;. So explicitly testing for &#8220;1&#8243; will resolve the bug.</p>
<p>In the meantime if you need to create a site column with one of those names you could do it using code or features. And if you wonder how I discovered this issue &#8211; well I wanted to create a site column called &#8220;Shift&#8221; as in work shift which I consider as a totally legitimate use case.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/224/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/224/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/224/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=224&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/01/15/the-column-name-that-you-entered-is-already-in-use-or-reserved-choose-another-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>

		<media:content url="http://hristopavlov.files.wordpress.com/2009/01/shift.jpg" medium="image">
			<media:title type="html">shift</media:title>
		</media:content>
	</item>
		<item>
		<title>Custom &#8216;Presence&#8217; With SharePoint Person Fields</title>
		<link>http://hristopavlov.wordpress.com/2009/01/07/custom-presence-with-sharepoint-person-fields/</link>
		<comments>http://hristopavlov.wordpress.com/2009/01/07/custom-presence-with-sharepoint-person-fields/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 05:10:25 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[IMNControl]]></category>
		<category><![CDATA[IMNImageOnClick]]></category>
		<category><![CDATA[imnmark]]></category>
		<category><![CDATA[Name (with presence)]]></category>
		<category><![CDATA[Name.NameCtrl]]></category>
		<category><![CDATA[Presense]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=212</guid>
		<description><![CDATA[Not that you will want to do this often, but I discovered today that the &#8220;Presence&#8221; control displayed with every Person on a SharePoint site can be actually completely customized. Usually it looks something like this: According to the MSDN documentation for NameCtrl: A developer can create a custom control for displaying presence information if [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=212&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Not that you will want to do this often, but I discovered today that the &#8220;Presence&#8221; control displayed with every Person on a SharePoint site can be actually completely customized. Usually it looks something like this:</p>
<p><img class="alignnone size-full wp-image-213" title="presense" src="http://hristopavlov.files.wordpress.com/2009/01/presense.jpg" alt="presense" width="214" height="252" /></p>
<p>According to the MSDN documentation for <a href="http://msdn.microsoft.com/en-us/library/ms455335.aspx" target="_blank">NameCtrl</a>:</p>
<p><em>A developer can create a custom control for displaying presence information if it has the same ProgID (Name.NameCtrl.1), uses the same method or property names, and provides the same functionality that is described in this reference. Functions can be created that handle the event in which the online status of a specified person changes.</em></p>
<p>What this means is that if you don&#8217;t have Office 2007 installed (or another version of the name.dll) then you can implement your own ActiveX control (in .NET or VB6 or C++) and name the COM class &#8220;<strong>Name.NameCtrl</strong>&#8220;. Then automatically this control will be called by SharePoint and will display whatever you want.</p>
<p>This could be handy for example when your customers don&#8217;t use Outlook as an email client or Office Communicator as an instant office messenger.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/212/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=212&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2009/01/07/custom-presence-with-sharepoint-person-fields/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>

		<media:content url="http://hristopavlov.files.wordpress.com/2009/01/presense.jpg" medium="image">
			<media:title type="html">presense</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploying WebParts with a DelegateControl</title>
		<link>http://hristopavlov.wordpress.com/2008/12/10/deploying-webparts-with-a-delegatecontrol/</link>
		<comments>http://hristopavlov.wordpress.com/2008/12/10/deploying-webparts-with-a-delegatecontrol/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 01:07:42 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[ControlAssembly]]></category>
		<category><![CDATA[ControlClass]]></category>
		<category><![CDATA[ControlSrc]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[DelegateControl]]></category>
		<category><![CDATA[Deploy]]></category>
		<category><![CDATA[Feature]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[Sequence]]></category>
		<category><![CDATA[WebPart]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=187</guid>
		<description><![CDATA[Brian Farnhill talks about an interesting approach of deploying zoneless web parts by using a Delegate Control in your master page or page layout. See his blog post here:  http://pointstoshare.spaces.live.com/Blog/cns!AEC42F315B4528B0!3247.entry The idea is that you add a DelegateControl in your master page or page layout and configure it&#8217;s ControlId to a unique id that you are going to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=187&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Brian Farnhill talks about an interesting approach of deploying zoneless web parts by using a <a href="http://msdn.microsoft.com/en-us/library/bb861966.aspx" target="_blank">Delegate Control</a> in your master page or page layout. See his blog post here:  <a href="http://pointstoshare.spaces.live.com/Blog/cns!AEC42F315B4528B0!3247.entry" target="_blank">http://pointstoshare.spaces.live.com/Blog/cns!AEC42F315B4528B0!3247.entry</a></p>
<p>The idea is that you add a <strong>DelegateControl</strong> in your master page or page layout and configure it&#8217;s <strong>ControlId</strong> to a unique id that you are going to define in a separate feature by using a <a href="http://msdn.microsoft.com/en-us/library/ms469179.aspx" target="_blank">Control</a> element. This way you can replace the control/web part without the need of changing the master page but only by updating your feature. Even more you can activate different controls in different sites by activating different features in those sites, which define different controls with the same Id that matches the ControlId configured in the DelegateControl.</p>
<p>When SharePoint is searching for the control specified in the DelegateControl it can also search only features of a specific scope i.e. Web, Site, etc. This can be configured from the <strong>Scope</strong> attribute of the DelegateControl. Also you can configure only one control to be rendered or all controls with this id to be rendered with the <strong>AllowMultipleControls</strong> attribute. If no matching Control element could be found, then no control is rendered i.e. if you want to remove the web part, just deactivate the feature. Additionally the DelegateControl allows a <strong>PrefixHtml</strong> and <strong>SuffixHtml</strong> to be defined.</p>
<p>You will probably want to use this approach when you need for different sites to show different web parts on the same location of the page. You do this by using a single page layout (or master page) with a single DelegateControl and then activating different features on those sites which will activate the different web parts to be rendered. Very nice indeed!</p>
<p>Delegate controls are used for defining the search controls in SharePoint. The web controls that are going to be hosted must be registered as safe. You can also host ASCX web user controls the same way.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/187/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/187/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/187/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=187&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2008/12/10/deploying-webparts-with-a-delegatecontrol/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>
	</item>
		<item>
		<title>UrlAction Tokens of the CustomAction Feature</title>
		<link>http://hristopavlov.wordpress.com/2008/12/08/urlaction-tokens-of-the-customaction-feature/</link>
		<comments>http://hristopavlov.wordpress.com/2008/12/08/urlaction-tokens-of-the-customaction-feature/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 01:07:35 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[CustomAction]]></category>
		<category><![CDATA[Feature]]></category>
		<category><![CDATA[UrlToken]]></category>
		<category><![CDATA[{ItemId}]]></category>
		<category><![CDATA[{ItemUrl}]]></category>
		<category><![CDATA[{ListId}]]></category>
		<category><![CDATA[{RecurrenceId}]]></category>
		<category><![CDATA[{SiteUrl}]]></category>
		<category><![CDATA[~site]]></category>
		<category><![CDATA[~sitecollection]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=175</guid>
		<description><![CDATA[I was looking today for the complete list of tokens that can be used in the UrlAction element when building a CustomAction feature but I couldn&#8217;t find much. So I decided to put together this blog entry to help other people that may be looking for the same thing. As you know some tokens can be used [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=175&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was looking today for the complete list of tokens that can be used in the <a title="UrlAction" href="http://msdn.microsoft.com/en-us/library/ms478271.aspx" target="_blank">UrlAction</a> element when building a <a title="CustomAction" href="http://msdn.microsoft.com/en-us/library/ms460194.aspx" target="_blank">CustomAction</a> feature but I couldn&#8217;t find much. So I decided to put together this blog entry to help other people that may be looking for the same thing.</p>
<p>As you know some tokens can be used when specifying the Url of the custom action: </p>
<div style="overflow:auto;background-color:silver;">&lt;<span>UrlAction</span>Url=&#8221;~site/_layouts/ItemAudit.aspx?ID={ItemId}&amp;amp;List={ListId}&#8221;<span>/&gt;</span></div>
<p><span>Those token will be replaced by SharePoint at runtime with values derived from the current context. To get the complete list we just need to find the function that does the replacement. Luckily this function is in the .NET libraries of SharePoint and can be disassembled with Reflector. So here is the complete list of the tokens:</span></p>
<table border="0">
<tbody>
<tr>
<td width="150"><strong>Token</strong></td>
<td width="350"><strong>Replaced By</strong></td>
</tr>
<tr>
<td><strong>~site/</strong></td>
<td><span style="font-size:10pt;color:#2b91af;font-family:&quot;">SPContext</span><span style="font-size:10pt;font-family:&quot;">.Current.Web.ServerRelativeUrl</span></td>
</tr>
<tr>
<td><strong>~sitecollection/</strong></td>
<td><span style="font-size:10pt;color:#2b91af;font-family:&quot;">SPContext</span><span style="font-size:10pt;font-family:&quot;">.Current.Site.ServerRelativeUrl</span></td>
</tr>
<tr>
<td><strong>{ItemId}</strong></td>
<td><span style="font-size:10pt;font-family:&quot;">item.ID.ToString()</span></td>
</tr>
<tr>
<td><strong>{ItemUrl}</strong></td>
<td><span style="font-size:10pt;font-family:&quot;">item.Url</span></td>
</tr>
<tr>
<td><strong>{SiteUrl}</strong></td>
<td><span style="font-size:10pt;font-family:&quot;">web.Url</span></td>
</tr>
<tr>
<td><strong>{ListId}</strong></td>
<td><span style="font-size:10pt;font-family:&quot;">list.ID.ToString(<span style="color:#a31515;">&#8220;B&#8221;</span>)</span></td>
</tr>
<tr>
<td><strong>{RecurrenceId} </strong></td>
<td><span style="font-size:10pt;font-family:&quot;">item.RecurrenceID</span></td>
</tr>
</tbody>
</table>
<p><span>For the records the method that does the replacement is Microsoft.SharePoint.SPCustomActionElement.ReplaceUrlTokens() and looks like this:</span></p>
<div style="overflow:auto;background-color:silver;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">private</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">static</span> <span style="color:blue;">string</span> ReplaceUrlTokens(</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">string </span>urlAction, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">SPWeb</span> web, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">SPList</span> list, </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:#2b91af;">SPListItem</span> item)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">string </span>recurrenceID;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">if</span> (!<span style="color:blue;">string</span>.IsNullOrEmpty(urlAction))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">if</span> (item != <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">string </span>newValue = item.ID.ToString(CultureInfo.InvariantCulture);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>urlAction = urlAction.Replace(<span style="color:#a31515;">&#8220;{ItemId}&#8221;</span>, newValue);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>urlAction = urlAction.Replace(<span style="color:#a31515;">&#8220;{ItemUrl}&#8221;</span>, item.Url);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>recurrenceID = newValue;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span><span style="color:blue;">if</span> (!<span style="color:blue;">string</span>.IsNullOrEmpty(item.RecurrenceID))</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>                </span>recurrenceID = item.RecurrenceID;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>            </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">else</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span><span style="color:blue;">return </span>urlAction;</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>urlAction = urlAction.Replace(<span style="color:#a31515;">&#8220;{RecurrenceId}&#8221;</span>, recurrenceID);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">if</span> (web != <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>urlAction = urlAction.Replace(<span style="color:#a31515;">&#8220;{SiteUrl}&#8221;</span>, web.Url);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">if</span> (list != <span style="color:blue;">null</span>)</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>        </span>urlAction = urlAction.Replace(<span style="color:#a31515;">&#8220;{ListId}&#8221;</span>, list.ID.ToString(<span style="color:#a31515;">&#8220;B&#8221;</span>));</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:green;">// Replaces ~site/ and ~sitecollection/ with the site and site collection urls</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>urlAction = <span style="color:#2b91af;">SPUtility</span>.GetServerRelativeUrlFromPrefixedUrl(urlAction);</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">return </span>urlAction;</span></p>
<p><span style="font-size:10pt;font-family:&quot;">}</span></div>
<p>The web, list and item arguments are taken from the context before the user is redirected to the custom action page.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/175/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=175&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2008/12/08/urlaction-tokens-of-the-customaction-feature/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>
	</item>
		<item>
		<title>The file is currently checked out or locked for editing by another user</title>
		<link>http://hristopavlov.wordpress.com/2008/12/02/the-file-is-currently-checked-out-or-locked-for-editing-by-another-user/</link>
		<comments>http://hristopavlov.wordpress.com/2008/12/02/the-file-is-currently-checked-out-or-locked-for-editing-by-another-user/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 00:52:44 +0000</pubDate>
		<dc:creator>hristopavlov</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[0x81020036]]></category>
		<category><![CDATA[Checked out]]></category>
		<category><![CDATA[Folder]]></category>
		<category><![CDATA[Locked]]></category>
		<category><![CDATA[Rename]]></category>

		<guid isPermaLink="false">http://hristopavlov.wordpress.com/?p=168</guid>
		<description><![CDATA[This is a nasty one. If you try to rename a folder from the SharePoint UI sometimes you may get an error saying &#8220;The file is currently checked out or locked for editing by another user&#8221;. If you enable  the callstack in the Web.config the full stack trace will be something like this: [COMException (0x81020036): [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=168&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a nasty one. If you try to rename a folder from the SharePoint UI sometimes you may get an error saying &#8220;<em>The file is currently checked out or locked for editing by another user&#8221;</em>. If you enable  the callstack in the Web.config the full stack trace will be something like this:</p>
<div style="overflow:auto;background-color:#ffffcc;">
<pre>[COMException (0x81020036): The file is currently checked out or locked for editing by another user.]
   Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32&amp; plID, String&amp; pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object&amp; pvarAttachmentNames, Object&amp; pvarAttachmentContents, Object&amp; pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +0
   Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32&amp; plID, String&amp; pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object&amp; pvarAttachmentNames, Object&amp; pvarAttachmentContents, Object&amp; pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +411

[SPException: The file is currently checked out or locked for editing by another user.]
   Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32&amp; plID, String&amp; pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object&amp; pvarAttachmentNames, Object&amp; pvarAttachmentContents, Object&amp; pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish) +556
   Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32&amp; ulID, Object&amp; objAttachmentNames, Object&amp; objAttachmentContents, Boolean suppressAfterEvents) +3032
   Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +636
   Microsoft.SharePoint.SPListItem.Update() +194
   Microsoft.SharePoint.WebControls.SaveButton.SaveItem(SPContext itemContext, Boolean uploadMode, String checkInComment) +1806
   Microsoft.SharePoint.WebControls.SaveButton.SaveItem() +111
   Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +476
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +50
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3215</pre>
</div>
<p> It turns out that SharePoint will not allow you to rename a folder if there is a file under it which is currently checked out. The trouble is SharePoint doesn&#8217;t tell you which is the file.</p>
<p>To find out which is the file you can use SharePoint Designer to rename the same folder. Then the error message returned by SharePoint Designer will include the file name being checked out and the user it is checked out to.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hristopavlov.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hristopavlov.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/hristopavlov.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/hristopavlov.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hristopavlov.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hristopavlov.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hristopavlov.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hristopavlov.wordpress.com/168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hristopavlov.wordpress.com&amp;blog=3594398&amp;post=168&amp;subd=hristopavlov&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://hristopavlov.wordpress.com/2008/12/02/the-file-is-currently-checked-out-or-locked-for-editing-by-another-user/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/52d317cd30dd4f2f9ab0146be453cd6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Hristo Pavlov</media:title>
		</media:content>
	</item>
	</channel>
</rss>
