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

<channel>
	<title>entwicklungsgedanken &#187; EventReceiver</title>
	<atom:link href="http://www.entwicklungsgedanken.de/tag/eventreceiver/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entwicklungsgedanken.de</link>
	<description>Verschiedene Gedanken rund um die Softwareentwicklung</description>
	<lastBuildDate>Thu, 29 Jul 2010 11:09:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Redirecting from NewForm.aspx to DispForm.aspx after creating a new item</title>
		<link>http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 22:45:24 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[DispForm.aspx]]></category>
		<category><![CDATA[EventReceiver]]></category>
		<category><![CDATA[HttpContext]]></category>
		<category><![CDATA[NewForm.aspx]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/</guid>
		<description><![CDATA[The requirement Recently a simple requirement came up: &#8220;Redirect the user to the view-form of an item after he creates a new item&#8221;. Sounds simple, right? &#8230; The default behavior of SharePoint is to redirect the user to the url defined by the Source-parameter. If this parameter is not given the default view (mostly AllItems.aspx) [...]]]></description>
			<content:encoded><![CDATA[<div class="lang-en"></div>
<h3>The requirement</h3>
<p>Recently a simple requirement came up: &#8220;Redirect the user to the view-form of an item after he creates a new item&#8221;. Sounds simple, right? &#8230;</p>
<p>The default behavior of SharePoint is to redirect the user to the url defined by the <code>Source</code>-parameter. If this parameter is not given the default view (mostly <code>AllItems.aspx</code>) will be used.</p>
<h3>The result</h3>
<p>The implementation of the requirement can be seen in this short screencast. After the user creates a new item he will be redirected to review the item-properties.</p>
<div id="media">
            <object id="csSWF" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="400" codebase="http://active.macromedia.com/flash7/cabs/ swflash.cab#version=9,0,28,0"><param name="src" value="http://www.entwicklungsgedanken.de/wp-content/uploads/2008/03/RedirectDemo.swf"/><param name="bgcolor" value="#1a1a1a"/><param name="quality" value="best"/><param name="allowScriptAccess" value="always"/><param name="allowFullScreen" value="true"/><param name="scale" value="showall"/><param name="flashVars" value="autostart=false"/><embed name="csSWF" src="http://www.entwicklungsgedanken.de/wp-content/uploads/2008/03/RedirectDemo.swf" width="600" height="400" bgcolor="#1a1a1a" quality="best" allowScriptAccess="always" allowFullScreen="true" scale="showall" flashVars="autostart=false" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>
        </div>
<h3>The way it should be</h3>
<p>Not amazed by the pictures you just saw? One would think its easy to achieve this behavior. Simply add an EventReceiver to the desired list and listen to the <code>ItemAdded</code>-event and redirect the user&#8230;<br />
<strong>In theory</strong> this is should work. The problem is that there is no <code>HttpContext.Current</code> available inside the <code>ItemAdded</code>-method.</p>
<h3>The HttpContext</h3>
<p>The only way to get the current <code>HttpContext</code> is within the constructor of your custom <code>EventReceiver</code> during a <del datetime="2008-05-08T19:29:52+00:00"><strong>asynchronous event</strong></del> <strong>synchronous event</strong> (<code>ItemAdding, ItemUpdating</code>) as shown in the following pseudo code.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomEventReceiver <span style="color: #008000;">:</span> SPItemEventReceiver
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">private</span> HttpContext _currentContext <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> CustomEventReceiver <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">base</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> <span style="color: #008000;">!=</span> HttpContext.<span style="color: #0000FF;">Current</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _currentContext <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ItemAdding <span style="color: #000000;">&#40;</span>SPItemEventProperties properties<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
       <span style="color: #008080; font-style: italic;">// Here one can use _currentContext and redirect ...</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>But now another problem arises. If you redirect the current thread is aborted and the item is never added to the list/library</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Will abort the thread</span>
_currentContext.<span style="color: #0000FF;">Redirect</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://somewhere/to/go&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Will NOT abort the thread but the redirection is ignored</span>
_currentContext.<span style="color: #0000FF;">Redirect</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;http://somewhere/to/go&quot;</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// What a mess!</span></pre></div></div>

<h3>The magic</h3>
<p>The only possible solution is to &#8220;manually&#8221; add the item so the redirection works as shown in the next code-block. The manual addition of the new item is necessary because the <code>properties.ListItemId</code> within <code>ItemAdding</code> is 0. But we need this ID to build the destination url in the form e.g. <code>http://hostname/web/listname/DispForm.aspx?ID=22</code></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomEventReceiver <span style="color: #008000;">:</span> SPItemEventReceiver
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Code omitted ... see above</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ItemAdding <span style="color: #000000;">&#40;</span>SPItemEventProperties properties<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Get a &quot;reference&quot; to the list</span>
        SPSite siteColl <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite <span style="color: #000000;">&#40;</span>properties.<span style="color: #0000FF;">SiteId</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        SPWeb site <span style="color: #008000;">=</span> siteColl.<span style="color: #0000FF;">OpenWeb</span> <span style="color: #000000;">&#40;</span>properties.<span style="color: #0000FF;">RelativeWebUrl</span><span style="color: #000000;">&#41;</span>
        SPList list <span style="color: #008000;">=</span> site.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span>properties.<span style="color: #0000FF;">ListId</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Add the item and fill it with the values from properties</span>
        DisableEventFiring <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        SPListItem itemToAdd <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// ... </span>
        EnableEventFiring <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Cleanup</span>
        site.<span style="color: #0000FF;">Dispose</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        siteColl.<span style="color: #0000FF;">Dispose</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Redirect</span>
        SPUtility.<span style="color: #0000FF;">Redirect</span> <span style="color: #000000;">&#40;</span>targetUrlOfNewItem,
            SPRedirectFlags.<span style="color: #0600FF;">Default</span>, _currentContext<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Hint:</strong> Because the form used to display an item can change you should retrieve it via the <code>SPList.Forms[PAGETYPE.PAGE_DISPLAYFORM]</code>-property.</p>
<h3>Conclusion</h3>
<p>The <code>HttpContext.Current</code> is only available within the constructor of your event receiver when handling synchronous events like <code>ItemAdding, ItemUpdating</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/03/27/redirecting-from-newformaspx-to-dispformaspx-after-creating-a-new-item/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>[Tool] EventReceiver-Installer for SharePoint</title>
		<link>http://www.entwicklungsgedanken.de/2008/02/29/tool-eventreceiver-installer-for-sharepoint/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/02/29/tool-eventreceiver-installer-for-sharepoint/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 12:04:43 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[definition]]></category>
		<category><![CDATA[EventReceiver]]></category>
		<category><![CDATA[install]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/2008/02/29/tool-eventreceiver-installer-for-sharepoint/</guid>
		<description><![CDATA[I just created a simple tool that allows the easy installation (and deletion) of EventReceiver-Definitions with SharePoint. It&#8217;s a stand-alone tool written in C# and it must be executed on the Server that runs SharePoint. The tool is named &#8220;EventReceiver-Installer&#8221; and is now in Version 1.0 1.1. Features Browse web-applications Categorized view of EventReceivers Deletion [...]]]></description>
			<content:encoded><![CDATA[<div class="lang-en"></div>
<p>I just created a simple tool that allows the easy installation (and deletion) of EventReceiver-Definitions with SharePoint. It&#8217;s a stand-alone tool written in C# and it must be executed on the Server that runs SharePoint.</p>
<p>The tool is named &#8220;EventReceiver-Installer&#8221; and is now in Version <strike>1.0</strike> 1.1.
</p>
<h4>Features</h4>
<ul>
<li>Browse web-applications</li>
<li>Categorized view of EventReceivers</li>
<li>Deletion of EventReceiver-Definitions</li>
<li>Adding of multiple EventReceiver-Definitions with one click</li>
<li>Retrieves the assemblies full-name (no more Reflector required)</li>
</ul>
<h4>Screenshots</h4>
<div class="image-descriptor">
<a href='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-main.png' title='EventInstaller-Main' rel="lightbox"><img src='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-main.thumbnail.png' alt='EventInstaller-Main' /></a><br />
<span>Main view</span>
</div>
<div class="image-descriptor">
<a href='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-info.png' title='EventInstaller-Info' rel="lightbox"><img src='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-info.thumbnail.png' alt='EventInstaller-Info' /></a><br />
<span>Info view</span>
</div>
<div class="image-descriptor">
<a href='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-add.png' title='EventInstaller-Add' rel="lightbox"><img src='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-add.thumbnail.png' alt='EventInstaller-Add' /></a><br />
<span>Add new EventReceier</span>
</div>
<div class="image-descriptor">
<a href='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-add-2.png' title='EventInstaller-Add2' rel="lightbox"><img src='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-add-2.thumbnail.png' alt='EventInstaller-Add2' /></a><br />
<span>Add new EventReceiver 2</span>
</div>
<div class="image-descriptor">
<a href='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-delete-step1.png' title='EventInstaller-Delete1' rel="lightbox"><img src='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-delete-step1.thumbnail.png' alt='EventInstaller-Delete1' /></a><br />
<span>Delete EventReceiver-Definition</span>
</div>
<div class="image-descriptor">
<a href='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-delete-step2.png' title='EventInstaller-Delete2' rel="lightbox"><img src='http://www.entwicklungsgedanken.de/wp-content/uploads/2008/02/eventinstaller-delete-step2.thumbnail.png' alt='EventInstaller-Delete2' /></a><br />
<span>Delete EventReceiver-Definition 2</span>
</div>
<div class="image-descriptor-after"></div>
<h4>Download</h4>
<p>Your can download it <a title="Download EventReceiver-Installer-v1.1.zip" href="/download/EventReceiver-Installer-v1.1.zip">here</a> (443KB) for free. The license is included in the archive.</p>
<h4>Future</h4>
<p>This is Version 1.1 and there will be additional improvements.</p>
<ul>
<li><strike>Support of Document-Libraries and Websites</strike></li>
<li>Support for different credentials (not the current user)</li>
<li>Multi-Deletion of EventReceiver-Definitions</li>
<li><strike>Definition types grouped be target (list, document library, website)</strike></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/02/29/tool-eventreceiver-installer-for-sharepoint/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
