<?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>CMS Source - sitecore CMS specialists</title>
	<atom:link href="http://www.cmssource.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://www.cmssource.co.uk</link>
	<description>Specialists in providing Sitecore solutions.</description>
	<lastBuildDate>Fri, 04 May 2012 12:11:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to implement a proper 404 page in sitecore (that returns a 404 response header)</title>
		<link>http://www.cmssource.co.uk/blog/sitecore-404-header</link>
		<comments>http://www.cmssource.co.uk/blog/sitecore-404-header#comments</comments>
		<pubDate>Fri, 04 May 2012 12:11:03 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[404 Page]]></category>
		<category><![CDATA[404 response header]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=146</guid>
		<description><![CDATA[In order to get sitecore to return a 404 response header along with the 404 page, you need to create a custom pipeline entry. This blog article will show you how.]]></description>
			<content:encoded><![CDATA[<p>For SEO purposes, we want to make sure that our 404 pages always return a 404 response header like the image below. Otherwise search engines will not recognise the 404 page as a &#8216;not found&#8217;.</p>
<p>Unfortunately, Sitecore&#8217;s 404 pages returns a 200 Response header, which corresponds to &#8216;found&#8217;.</p>
<p>The only way to implement a proper 404 in Sitecore is to add a custom pipeline which will return a 404 response header and  then output the content of your custom 404 page. If you want more details on this you can read this <a title="301 and 404 handler" href="http://techcolin.net/2011/10/ultimate-301-404-handler-for-sitecore-part-1/">blog post</a>, the code below will provide a similar solution.<a href="http://www.cmssource.co.uk/wp-content/uploads/2012/05/Not-found.png"><br />
</a></p>
<div id="attachment_148" class="wp-caption alignnone" style="width: 660px"><a href="http://www.cmssource.co.uk/wp-content/uploads/2012/05/Not-found1.png"><img class=" wp-image-148 " title="Correct 404 not found response" src="http://www.cmssource.co.uk/wp-content/uploads/2012/05/Not-found1.png" alt="Correct 404 not found response" width="650" height="361" /></a><p class="wp-caption-text">The above image shows the response header we want to see when we hit a 404 page.</p></div>
<p>1. We need to add our out pipeline intercept to appear before the &#8216;ExecuteRequest&#8217; Sitecore pipeline:</p>
<pre style="font-family: Consolas; font-size: 10; color: black; background: white;"><span style="color: blue;">&lt;?</span><span style="color: #a31515;">xml</span><span style="color: blue;"> </span><span style="color: red;">version</span><span style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span style="color: blue;">?&gt;</span>
<span style="color: blue;">    &lt;</span><span style="color: #a31515;">configuration</span><span style="color: blue;"> </span><span style="color: red;">xmlns:x</span><span style="color: blue;">=</span>"<span style="color: blue;">http://www.sitecore.net/xmlconfig/</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;</span><span style="color: #a31515;">pipelines</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;</span><span style="color: #a31515;">httpRequestBegin</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">processor</span><span style="color: blue;"> </span><span style="color: red;">x:before</span><span style="color: blue;">=</span>"<span style="color: blue;">processor[@type='Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel']</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">CmsSource.Utils.Pipelines.Custom404Reolver, CmsSource.Utils</span>"<span style="color: blue;">/&gt;</span>
<span style="color: blue;">      &lt;/</span><span style="color: #a31515;">httpRequestBegin</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">pipelines</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: blue;">&gt;</span></pre>
<p>&nbsp;</p>
<p>2. The key section of code for the pipeline:</p>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white;"><span style="color: #2b91af;">HttpContext</span> context = <span style="color: #2b91af;">HttpContext</span>.Current;
<span style="color: green;">// Send headers</span>
context.Response.TrySkipIisCustomErrors = <span style="color: blue;">true</span>;
context.Response.StatusCode = 404;
context.Response.StatusDescription = <span style="color: #a31515;">"Page not found"</span>;

<span style="color: green;">// Get content of 404 page and send to the client</span>
<span style="color: blue;">try</span>
{
    <span style="color: #2b91af;">String</span> str404Url = <span style="color: #a31515;">"http://"</span> + context.Request.ServerVariables[<span style="color: #a31515;">"SERVER_NAME"</span>] + <span style="color: #2b91af;">Settings</span>.ItemNotFoundUrl;
    <span style="color: #2b91af;">WebClient</span> client = <span style="color: blue;">new</span> <span style="color: #2b91af;">WebClient</span>();
    client.Headers.Add(<span style="color: #2b91af;">HttpRequestHeader</span>.UserAgent, <span style="color: #a31515;">"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0)"</span>);
    <span style="color: #2b91af;">String</span> str404Content = client.DownloadString(str404Url);

    context.Response.Write(str404Content);
    context.Response.End();

}
<span style="color: blue;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)
{
    <span style="color: #2b91af;">Log</span>.Error(<span style="color: #a31515;">"Problem loading 404 page content"</span>, ex, <span style="color: blue;">this</span>);
}</pre>
<p>&nbsp;</p>
<p>The full .cs file can be downloaded below. There was some redirect code that needed to be added to make sure that Sitecore&#8217;s default functionality was still working (e.g. redirects to login page when trying to request secure pages).</p>
<p><a title="Code" href="http://www.cmssource.co.uk/wp-content/uploads/2012/05/Custom404Resolver.zip">Download Code Here</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/sitecore-404-header/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful include file config patch snippets for sitecore</title>
		<link>http://www.cmssource.co.uk/blog/usefull-include-file-config-patch-snippets-for-sitecore</link>
		<comments>http://www.cmssource.co.uk/blog/usefull-include-file-config-patch-snippets-for-sitecore#comments</comments>
		<pubDate>Mon, 06 Feb 2012 15:40:13 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[config patch]]></category>
		<category><![CDATA[patrch]]></category>
		<category><![CDATA[sitecore include file]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=139</guid>
		<description><![CDATA[A list of handy patch file snippets for sitecore 6.3 onwards.]]></description>
			<content:encoded><![CDATA[<p>I thought I will keep a list of handy patch file snippets in this post that I seem to need to keep re-using. Please feel free to comment and help me increase the collection.</p>
<h4>Add multiple sites to the publish:end cache clearing config entry:</h4>
<pre style="font-family: Consolas; font-size: 10; color: black; background: white;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">events</span><span style="color: blue;"> </span><span style="color: red;">timingLevel</span><span style="color: blue;">=</span>"<span style="color: blue;">custom</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;</span><span style="color: #a31515;">event</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">publish:end</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">handler</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel</span>"<span style="color: blue;"> </span><span style="color: red;">method</span><span style="color: blue;">=</span>"<span style="color: blue;">ClearCache</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">          &lt;</span><span style="color: #a31515;">sites</span><span style="color: blue;"> </span><span style="color: red;">hint</span><span style="color: blue;">=</span>"<span style="color: blue;">list</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">            &lt;</span><span style="color: #a31515;">patch:delete</span><span style="color: blue;"> /&gt;</span>
<span style="color: blue;">          &lt;/</span><span style="color: #a31515;">sites</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">          &lt;</span><span style="color: #a31515;">sites</span><span style="color: blue;"> </span><span style="color: red;">hint</span><span style="color: blue;">=</span>"<span style="color: blue;">list</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">            &lt;</span><span style="color: #a31515;">site</span><span style="color: blue;">&gt;</span>website<span style="color: blue;">&lt;/</span><span style="color: #a31515;">site</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">            &lt;</span><span style="color: #a31515;">site</span><span style="color: blue;">&gt;</span>site1<span style="color: blue;">&lt;/</span><span style="color: #a31515;">site</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">            &lt;</span><span style="color: #a31515;">site</span><span style="color: blue;">&gt;</span>site2<span style="color: blue;">&lt;/</span><span style="color: #a31515;">site</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">          &lt;/</span><span style="color: #a31515;">sites</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;/</span><span style="color: #a31515;">handler</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;/</span><span style="color: #a31515;">event</span><span style="color: blue;">&gt;</span></pre>
<pre style="font-family: Consolas; font-size: 10; color: black; background: white;"><span style="color: blue;">  &lt;/</span><span style="color: #a31515;">events</span><span style="color: blue;">&gt;</span></pre>
<p>&nbsp;</p>
<h4>Modify the keep-alive location:</h4>
<pre style="font-family: Consolas; font-size: 10; color: black; background: white;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">scheduling</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;</span><span style="color: #a31515;">agent</span><span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">Sitecore.Tasks.UrlAgent</span>"<span style="color: blue;"> </span><span style="color: red;">method</span><span style="color: blue;">=</span>"<span style="color: blue;">Run</span>"<span style="color: blue;"> </span><span style="color: red;">interval</span><span style="color: blue;">=</span>"<span style="color: blue;">00:30:00</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">        &lt;</span><span style="color: #a31515;">param</span><span style="color: blue;"> </span><span style="color: red;">desc</span><span style="color: blue;">=</span>"<span style="color: blue;">url</span>"<span style="color: blue;">&gt;</span>http://mysite/sitecore/service/keepalive.aspx<span style="color: blue;">&lt;/</span><span style="color: #a31515;">param</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;/</span><span style="color: #a31515;">agent</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">scheduling</span><span style="color: blue;">&gt;</span></pre>
<pre style="font-family: Consolas; font-size: 10; color: black; background: white;"></pre>
<p>&nbsp;</p>
<h4>Remove .ashx extension from media items and keep original media extension (e.g. .pdf, .jpg)</h4>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white;"><span style="color: blue;">      &lt;</span><span style="color: #a31515;">settings</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">          &lt;</span><span style="color: #a31515;">setting</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">Media.RequestExtension</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">              &lt;</span><span style="color: #a31515;">patch:attribute</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">value</span>"<span style="color: blue;">&gt;&lt;/</span><span style="color: #a31515;">patch:attribute</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">          &lt;/</span><span style="color: #a31515;">setting</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;/</span><span style="color: #a31515;">settings</span><span style="color: blue;">&gt;</span></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white;"></pre>
<p>&nbsp;</p>
<h4>Patch entry to set the DATA folder location</h4>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white;"><span style="color: blue;">    &lt;</span><span style="color: #a31515;">sc.variable</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">dataFolder</span>"<span style="color: blue;">&gt;</span>
<span style="color: blue;">      &lt;</span><span style="color: #a31515;">patch:attribute</span><span style="color: blue;"> </span><span style="color: red;">name</span><span style="color: blue;">=</span>"<span style="color: blue;">value</span>"<span style="color: blue;">&gt;</span>H:\Development\CmsS\TestProj\trunk\Data<span style="color: blue;">&lt;/</span><span style="color: #a31515;">patch:attribute</span><span style="color: blue;">&gt;</span>
<span style="color: blue;">    &lt;/</span><span style="color: #a31515;">sc.variable</span><span style="color: blue;">&gt;</span></pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/usefull-include-file-config-patch-snippets-for-sitecore/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add custom tokens into your sitecore fields and replace them on render via pipeline</title>
		<link>http://www.cmssource.co.uk/blog/add-custom-tokens-into-your-sitecore-fields-and-replace-them-on-render-via-pipeline</link>
		<comments>http://www.cmssource.co.uk/blog/add-custom-tokens-into-your-sitecore-fields-and-replace-them-on-render-via-pipeline#comments</comments>
		<pubDate>Wed, 25 Jan 2012 14:01:10 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[content token replacement]]></category>
		<category><![CDATA[renderField extension]]></category>
		<category><![CDATA[sitecore 6.5]]></category>
		<category><![CDATA[sitecore pipeline patch]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=136</guid>
		<description><![CDATA[Tutorial on how to add a renderField pipeline extension to allow us to insert custom tokens into sitecore content fields and replace them on render.]]></description>
			<content:encoded><![CDATA[<p>I wanted my authors to be able to place tokens anywhere in body of text fields so that the logged in users first name and last name could be inserted into the content dynamically. This was quite straight forward and you can create your own tokens for whatever you wish, the example below works with {FIRSTNAME} and {LASTNAME} tokens.</p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2012/01/main-token-replace.png"><img class="aligncenter size-full wp-image-137" title="main token replace" src="http://www.cmssource.co.uk/wp-content/uploads/2012/01/main-token-replace.png" alt="" width="562" height="146" /></a></p>
<p>Create a class to fit into the &lt;renderField&gt; pipeline, this will be patched in just after the GetFieldValue operation.</p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">using</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> System.Linq;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">using</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> System.Collections.Generic;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">using</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> Sitecore.Diagnostics;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">using</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> Sitecore.Pipelines.RenderField;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">namespace</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> CmsS.Common.Pipelines</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">{</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">    </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">public</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">class</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">TokenReplacer</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">    {</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">        </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">public</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">void</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> Process(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">RenderFieldArgs</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> args)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">        {</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">Assert</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">.ArgumentNotNull(args, </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">&#8220;args&#8221;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: green;">//I store my tokens in a comma delemetered list somewhere, you might want to do the same, its hardcoded </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: green;">//here for example only</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">List</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">&lt;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">string</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">&gt; tokens = </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">&#8220;{FIRSTNAME},{LASTNAME}&#8221;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">.Split(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">&#8216;,&#8217;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">).ToList();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">string</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> originalValue = args.Result.FirstPart;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">var</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> usedTokens = tokens.Where(X =&gt; originalValue.Contains(X));</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">           </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">if</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> (usedTokens.Count() &gt; 0)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            {</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                Sitecore.Security.</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">UserProfile</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> profile = Sitecore.</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">Context</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">.User.Profile </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">as</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> Sitecore.Security.</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">UserProfile</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">if</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> (profile != </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">null</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                {</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                    </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">string</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">[] name = profile.FullName.Split(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">&#8216; &#8217;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                    </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">foreach</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> (</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">string</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> token </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">in</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> usedTokens)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                    {</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                        </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">switch</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> (token)</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                        {</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">case</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">&#8220;{FIRSTNAME}&#8221;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">:</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                                originalValue = originalValue.Replace(token, name.First());</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                                </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">break</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                            </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">case</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"> </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">&#8220;{LASTNAME}&#8221;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">:</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                                originalValue = originalValue.Replace(token, name.Last());</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                                </span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">break</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                        }</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                    }</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                    args.Result.FirstPart = originalValue;                    </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">                }</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            }</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">            </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">        }</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">    }</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">}</span></p>
<p>Add your patch file entry:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color: #0000ff;">&lt;?</span><span style="color: #a31515;">xml </span><span style="color: #ff0000;">version</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0</span>&#8220;<span style="color: #0000ff;">?&gt;</span></div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">configuration </span><span style="color: #ff0000;">xmlns:x</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">http://www.sitecore.net/xmlconfig/</span>&#8220;<span style="color: #0000ff;">&gt;</span></div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span><span style="color: #0000ff;">   </span></div>
<div style="background-color: #ffffff; max-height: 300px; overflow-x: auto; overflow-y: auto; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 35px;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">pipelines</span><span style="color: #0000ff;">&gt;</span></div>
<div style="background-color: #ffffff; max-height: 300px; overflow-x: auto; overflow-y: auto; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 65px;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">renderField</span><span style="color: #0000ff;">&gt;</span><span style="color: #0000ff;">        </span></div>
<div style="background-color: #ffffff; max-height: 300px; overflow-x: auto; overflow-y: auto; padding-top: 2px; padding-right: 5px; padding-bottom: 2px; padding-left: 95px;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">processor </span><span style="color: #ff0000;">x:after</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">*[@type='Sitecore.Pipelines.RenderField.GetFieldValue, Sitecore.Kernel']</span>&#8220; <span style="color: #ff0000;">type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">CmsS.Common.Pipelines.TokenReplacer, CmsS.Common</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></div>
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">
<p><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">renderField</span><span style="color: #0000ff;">&gt;</span></p>
<p><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">pipelines</span><span style="color: #0000ff;">&gt;</span></p>
<p><span style="color: #0000ff;">  &lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></p>
<p><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></p>
</div>
</div>
<p>You are good to go.</p>
<p>This will work with most versions of sitecore 6.5 and down.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/add-custom-tokens-into-your-sitecore-fields-and-replace-them-on-render-via-pipeline/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web.config changes to run sitecore under .net 4 framework without using MVC</title>
		<link>http://www.cmssource.co.uk/blog/web-config-changes-to-run-sitecore-under-net-4-framework-without-using-mvc</link>
		<comments>http://www.cmssource.co.uk/blog/web-config-changes-to-run-sitecore-under-net-4-framework-without-using-mvc#comments</comments>
		<pubDate>Sun, 15 Jan 2012 15:55:32 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[.NET 4]]></category>
		<category><![CDATA[.NET4 with Sitecore]]></category>
		<category><![CDATA[Sitecore configuration]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=132</guid>
		<description><![CDATA[Alterations needed for a Sitecore web.config to make sitecore run on .NET4 framework on integrated mode without MVC.]]></description>
			<content:encoded><![CDATA[<p>I seem to need to do this all the time and there is no sample web.config for running Sitecore under the .net4 framework without using MVC in integrated mode.</p>
<p>Here are the steps:</p>
<p><strong>1. Delete this whole section from existing web.config, the code snippet can be found right at the bottom:</strong></p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color: #0000ff;">  &lt;</span><span style="color: #a31515;">system.codedom</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">compilers</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">compiler</span><span style="color: #ff0000;"> language</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">c#;cs;csharp</span>&#8221; <span style="color: #ff0000;">extension</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">.cs</span>&#8220;<span style="color: #ff0000;"> type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</span>&#8220;<span style="color: #ff0000;"> warningLevel</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">4</span>&#8220;<span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">providerOption </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">CompilerVersion</span>&#8220;<span style="color: #ff0000;"> value</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">v3.5</span>&#8220;<span style="color: #0000ff;"> /&gt;</span><br />
<span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">providerOption </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">WarnAsError</span>&#8220;<span style="color: #ff0000;"> value</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">false</span>&#8220;<span style="color: #0000ff;"> /&gt;</span><br />
<span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">compiler</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">compilers</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">  &lt;/</span><span style="color: #a31515;">system.codedom</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">  &lt;</span><span style="color: #a31515;">runtime</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">assemblyBinding</span><span style="color: #ff0000;"> xmlns</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">urn:schemas-microsoft-com:asm.v1</span>&#8220;<span style="color: #ff0000;"> appliesTo</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">v2.0.50727</span>&#8220;<span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">dependentAssembly</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">assemblyIdentity</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Web.Extensions</span>&#8221; <span style="color: #ff0000;">publicKeyToken</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">31bf3856ad364e35</span>&#8220;<span style="color: #0000ff;"> /&gt;</span><br />
<span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">bindingRedirect</span><span style="color: #ff0000;"> oldVersion</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0.0.0-1.1.0.0</span>&#8220;<span style="color: #ff0000;"> newVersion</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">3.5.0.0</span>&#8220;<span style="color: #0000ff;"> /&gt;</span><br />
<span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">dependentAssembly</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">dependentAssembly</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">assemblyIdentity</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Web.Extensions.Design</span>&#8220;<span style="color: #ff0000;"> publicKeyToken</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">31bf3856ad364e35</span>&#8220;<span style="color: #0000ff;"> /&gt;</span><br />
<span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">bindingRedirect</span><span style="color: #ff0000;">oldVersion</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0.0.0-1.1.0.0</span>&#8220;<span style="color: #ff0000;">newVersion</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">3.5.0.0</span>&#8220;<span style="color: #0000ff;"> /&gt;</span><br />
<span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">dependentAssembly</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">assemblyBinding</span><span style="color: #0000ff;">&gt;</span><br />
<span style="color: #0000ff;">  &lt;/</span><span style="color: #a31515;">runtime</span><span style="color: #0000ff;">&gt;</span></div>
</div>
<p>&nbsp;</p>
<p><strong>2. Replace this part:</strong></p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;">
<p><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">compilation</span><span style="color: #ff0000;"> defaultLanguage</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">c#</span>&#8220;<span style="color: #ff0000;">debug</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">false</span>&#8220;<span style="color: #0000ff;">&gt;</span></p>
<p><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">assemblies</span><span style="color: #0000ff;">&gt;</span></p>
<p><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">add</span><span style="color: #ff0000;"> assembly</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></p>
<p><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">add </span><span style="color: #ff0000;">assembly</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></p>
<p><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">add </span><span style="color: #ff0000;">assembly</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></p>
<p><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">add </span><span style="color: #ff0000;">assembly</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></p>
<p><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">add</span><span style="color: #ff0000;"> assembly</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></p>
<p><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">assemblies</span><span style="color: #0000ff;">&gt;</span></p>
<p><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">compilation</span><span style="color: #0000ff;">&gt;</span></p>
</div>
</div>
<p>&nbsp;</p>
<p>With this:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">compilation</span><span style="color: #ff0000;"> defaultLanguage</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">c#</span>&#8220;<span style="color: #ff0000;"> debug</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">false</span>&#8221; <span style="color: #ff0000;">targetFramework</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">4.0</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></div>
</div>
<p>&nbsp;</p>
<p>Compile and you are now good to go!<br />
I have uploaded the .NET4 config (without MVC) for Sitecore 6.5.0 rev 110818 here if anyone wants it:<br />
<a title="Example .NET 4 web.config" href="http://www.cmssource.co.uk/wp-content/uploads/2011/10/Web.config.NET4">http://www.cmssource.co.uk/wp-content/uploads/2011/10/Web.config.NET4</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/web-config-changes-to-run-sitecore-under-net-4-framework-without-using-mvc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modifying sitecore alias to append custom query strings via 301 redirect</title>
		<link>http://www.cmssource.co.uk/blog/modifying-sitecore-alias-to-append-custom-query-strings-via-301-redirect</link>
		<comments>http://www.cmssource.co.uk/blog/modifying-sitecore-alias-to-append-custom-query-strings-via-301-redirect#comments</comments>
		<pubDate>Fri, 16 Dec 2011 12:38:19 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[.NET 2]]></category>
		<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[custom query string to alias]]></category>
		<category><![CDATA[sitecore 6.5]]></category>
		<category><![CDATA[sitecore alias patch]]></category>
		<category><![CDATA[sitecore pipeline patch]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=122</guid>
		<description><![CDATA[Extend sitecore alias to append custom querystring vars.]]></description>
			<content:encoded><![CDATA[<h4>The following solution extends sitecore alias to allow us to append any custom querystring vars to any alias via a 301 redirect. &#8211; Solution applied to sitecore version 6.5</h4>
<p>&nbsp;</p>
<p><strong>Scenario:</strong></p>
<p>We have a client that relies heavily on google analytics to track campaigns. Lets assume they have an online campaign, as well as an offline campaign with the Sun newspaper. Both mediums will link through to their own alias that point to http://www.site.com/2-for1:</p>
<ol>
<li>http://www.site.com/<strong>sun2-for1</strong></li>
<li>http://www.site.com/<strong>online-2-for1</strong></li>
</ol>
<p>In order to get google analytics to register the campaigns for the correct medium, we need to add some query string vars according to the definition here: <a href="http://support.google.com/googleanalytics/bin/answer.py?hl=en-GB&amp;answer=55578">http://support.google.com/googleanalytics/bin/answer.py?hl=en-GB&amp;answer=55578</a></p>
<p>We can achieve this by responding with a<strong> 301 redirect</strong> with the new URL&#8217;s when the user types in one of the aliased URL&#8217;s above. For example, if the user types the sun campaign URL #1 (http://www.site.com/sun2-for1) above, we want them to be redirected to: <strong>http://www.site.com/sun2-for1<span style="color: #008000;">?utm_source=sun%2Bnews&amp;utm_medium=offline&amp;utm_campaign=2-for-1</span></strong></p>
<p>&nbsp;</p>
<p><strong>Solution:</strong></p>
<p>Add a <em>single line text</em> field &#8216;<strong>Custom querystring</strong>&#8216; to the alias template located in the master DB: /sitecore/templates/System/Alias:</p>
<p style="text-align: center;"><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/12/alias-template.png"><img class="aligncenter size-full wp-image-129" title="alias-template" src="http://www.cmssource.co.uk/wp-content/uploads/2011/12/alias-template.png" alt="Alias template" width="700" height="295" /></a></p>
<p>We need to patch the pipelie before the Sitecore.Pipelines.HttpRequest.AliasResolver is called:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">CustomAliasPatch.config</div>
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;" start="1">
<li><span style="color: #0000ff;">&lt;?</span><span style="color: #a31515;">xml </span><span style="color: #ff0000;">version</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0</span>&#8220;<span style="color: #0000ff;">?&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: #ff0000;"> xmlns:x</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">http://www.sitecore.net/xmlconfig/</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">  &lt;</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">pipelines</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">httpRequestBegin</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">processor </span><span style="color: #ff0000;">x:before</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">processor[@type='Sitecore.Pipelines.HttpRequest.AliasResolver, Sitecore.Kernel']</span>&#8220;<span style="color: #ff0000;"> type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">CmsSource.Pipelines.CustomAliasResolver, CmsSource</span>&#8220;<span style="color: #0000ff;">/&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">httpRequestBegin</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">pipelines</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></li>
</ol>
</div>
</div>
<p>Now we create our pipeline CustomAliasResolver.cs which:</p>
<ol>
<li>Checks that we are dealing with an alias.</li>
<li>If yes to step one and the &#8216;Custom querystring&#8217; field contains a value, then</li>
<li>Generate the new URL from the current URL and append the custom querystring, add an extra query string flag: proc=1 (we check for this flag, so that we know that we have already processed the custom query string).</li>
<li>Perform a 301 redirect to the newly generated URL.</li>
</ol>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">CustomAliasResolver.cs</div>
<div style="background: #fff; max-height: 500px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;" start="1">
<li><span style="color: #0000ff;">using</span> System;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Collections.Generic;</li>
<li><span style="color: #0000ff;">using</span> System.Linq;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Text;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Diagnostics;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Configuration;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Data;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Pipelines.HttpRequest;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Data.Items;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Data.Managers;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.IO;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Globalization;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.SecurityModel;</li>
<li><span style="color: #0000ff;">using</span> System.Web;</li>
<li><span style="color: #0000ff;">namespace</span> CmsSource.Pipelines</li>
<li style="background: #f3f3f3;">{</li>
<li>    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">CustomAliasResolver</span> : <span style="color: #2b91af;">HttpRequestProcessor</span></li>
<li style="background: #f3f3f3;">    {</li>
<li>        <span style="color: #008000;">// Methods</span></li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> Process(<span style="color: #2b91af;">HttpRequestArgs</span> args)</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(args, <span style="color: #a31515;">&#8220;args&#8221;</span>);</li>
<li>            <span style="color: #0000ff;">if</span> (!<span style="color: #2b91af;">Settings</span>.AliasesActive)</li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #2b91af;">Tracer</span>.Warning(<span style="color: #a31515;">&#8220;Aliases are not active.&#8221;</span>);</li>
<li style="background: #f3f3f3;">            }</li>
<li>            <span style="color: #0000ff;">else</span></li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #2b91af;">Database</span> database = <span style="color: #2b91af;">Context</span>.Database;</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">if</span> (database == <span style="color: #0000ff;">null</span>)</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">Tracer</span>.Warning(<span style="color: #a31515;">&#8220;There is no context database in AliasResover.&#8221;</span>);</li>
<li>                }</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">else</span></li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #0000ff;">try</span></li>
<li>                    {</li>
<li style="background: #f3f3f3;">                        <span style="color: #2b91af;">Profiler</span>.StartOperation(<span style="color: #a31515;">&#8220;Resolve virgin alias pipeline.&#8221;</span>);</li>
<li>                        <span style="color: #2b91af;">Item</span> item = <span style="color: #2b91af;">ItemManager</span>.GetItem(<span style="color: #2b91af;">FileUtil</span>.MakePath(<span style="color: #a31515;">&#8220;/sitecore/system/aliases&#8221;</span>, args.LocalPath, <span style="color: #a31515;">&#8216;/&#8217;</span>), <span style="color: #2b91af;">Language</span>.Current, Sitecore.Data.<span style="color: #2b91af;">Version</span>.First, database, <span style="color: #2b91af;">SecurityCheck</span>.Disable);</li>
<li style="background: #f3f3f3;">                        <span style="color: #0000ff;">if</span> (item != <span style="color: #0000ff;">null</span>)</li>
<li>                        {</li>
<li style="background: #f3f3f3;">                            <span style="color: #008000;">//Alias existis (now we have the alias item)</span></li>
<li>                            <span style="color: #0000ff;">if</span> (item.Fields[<span style="color: #a31515;">"Custom querystring"</span>] != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">                            {</li>
<li>                                <span style="color: #0000ff;">if</span> (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(item.Fields[<span style="color: #a31515;">"Custom querystring"</span>].Value) &amp;&amp; !args.Url.QueryString.Contains(<span style="color: #a31515;">&#8220;aproc&#8221;</span>))</li>
<li style="background: #f3f3f3;">                                {</li>
<li>                                    <span style="color: #0000ff;">string</span> requestUrl = <span style="color: #2b91af;">HttpContext</span>.Current.Request.Url.ToString();</li>
<li style="background: #f3f3f3;">                                    <span style="color: #0000ff;">string</span> newUrl = <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;{0}{1}{2}&amp;aproc=1&#8243;</span>, requestUrl, requestUrl.Contains(<span style="color: #a31515;">&#8220;?&#8221;</span>) ? <span style="color: #a31515;">&#8220;&amp;&#8221;</span> : <span style="color: #a31515;">&#8220;?&#8221;</span>, item.Fields[<span style="color: #a31515;">"Custom querystring"</span>].Value);</li>
<li>                                    SendResponse(newUrl, args);</li>
<li style="background: #f3f3f3;">                                }</li>
<li>                            }</li>
<li style="background: #f3f3f3;">                        }</li>
<li style="background: #f3f3f3;">                        <span style="color: #2b91af;">Profiler</span>.EndOperation();</li>
<li>                    }</li>
<li style="background: #f3f3f3;">                    <span style="color: #0000ff;">catch</span> (<span style="color: #2b91af;">Exception</span> ex)</li>
<li>                    {</li>
<li style="background: #f3f3f3;">                        <span style="color: #2b91af;">Log</span>.Error(<span style="color: #a31515;">&#8220;Had a problem in the VirginAliasResolver. Error: &#8220;</span> + ex.Message, <span style="color: #0000ff;">this</span>);</li>
<li>                    }</li>
<li style="background: #f3f3f3;">                }</li>
<li>            }</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #808080;">///</span><span style="color: #808080;">&lt;summary&gt;</span></li>
<li>        <span style="color: #808080;">///</span><span style="color: #008000;">  Once a match is found and we have a Sitecore Item, we can send the 301 response.</span></li>
<li style="background: #f3f3f3;">        <span style="color: #808080;">///</span><span style="color: #808080;">&lt;/summary&gt;</span></li>
<li>        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> SendResponse(<span style="color: #0000ff;">string</span> redirectToUrl, <span style="color: #2b91af;">HttpRequestArgs</span> args)</li>
<li style="background: #f3f3f3;">        {</li>
<li>            args.Context.Response.Status = <span style="color: #a31515;">&#8220;301 Moved Permanently&#8221;</span>;</li>
<li style="background: #f3f3f3;">            args.Context.Response.StatusCode = 301;</li>
<li>            args.Context.Response.AddHeader(<span style="color: #a31515;">&#8220;Location&#8221;</span>, redirectToUrl);</li>
<li style="background: #f3f3f3;">            args.Context.Response.End();</li>
<li>        }</li>
<li style="background: #f3f3f3;">    }</li>
<li>}</li>
</ol>
</div>
</div>
<p>&nbsp;</p>
<p>To create the alias in the example above, we would simply add a new alias item &#8216;<em>sun2-for1</em>&#8216; which will point at &#8216;<em>home/2-for-1</em>&#8216; and add &#8216;utm_source=sun%2Bnews&amp;utm_medium=offline&amp;utm_campaign=2-for-1&#8242; to the Custom quesrystring field:</p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/12/custom-alias-example.png"><img class="aligncenter size-full wp-image-126" title="custom-alias-example" src="http://www.cmssource.co.uk/wp-content/uploads/2011/12/custom-alias-example.png" alt="Example of custom alias query string" width="753" height="591" /></a></p>
<p>This code has been tested with sitecore 6.5 (should work for all version of sitecore 5.3 upwards) and will work alongside existing aliases. If the field &#8216;Custom querystring&#8217; is left blank, the alias will be handled as a regular sitecore alias with no redirect.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/modifying-sitecore-alias-to-append-custom-query-strings-via-301-redirect/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting sitecore dictionary items to work on CD Servers against WEB database</title>
		<link>http://www.cmssource.co.uk/blog/getting-sitecore-dictionary-items-to-work-on-cd-servers-against-web-database</link>
		<comments>http://www.cmssource.co.uk/blog/getting-sitecore-dictionary-items-to-work-on-cd-servers-against-web-database#comments</comments>
		<pubDate>Tue, 15 Nov 2011 17:29:16 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=114</guid>
		<description><![CDATA[Work-around for sitecore Dictionary limitation which indexes only dictionary items on the Core DB.]]></description>
			<content:encoded><![CDATA[<p>The sitecore dictionary that can be accessed via the Sitecore.Globalization.Translate is a handy feature that can be used to help you create a fully multi-lingual website. Dictionary items are stored within &#8216;/sitecore/system/Dictionary&#8217; and hashed within a root/temp/dictionary.dat file for super fast access.</p>
<p>One BIG problem, even though you can store dictionary items on all databases, sitecore only indexes the items within the CORE database. This basically makes the Translate function useless for most high-end solutions that often have CD servers that do not communicate with the original core DB.</p>
<p>On the plus side, you can copy most of sitecore&#8217;s dictionary code and generate your own to match the content of the web DB. <em>NOTE: I will soon be testing this in a proper multi-server environment, at the moment this solution has only been tested in a development environment.</em></p>
<p><em>Download the code here:  <a title="Custom dictionary code" href="http://www.cmssource.co.uk/wp-content/uploads/2011/11/Translate.zip">Translate.zip</a></em></p>
<p>For this, you have to:</p>
<ol>
<li>Make your own Translate class that writes to a different .dat file and reads the WEB db.</li>
<li>Make your own ItemEventHandler that will rebuild your dictionary when the dictionary entry items are deleted or saved, this too is an almost straight copy of sitecore&#8217;s Sitecore.Globalization.ItemEventHandler class. You then use a patch file to sneak your events in after Sitecore&#8217;s own dictionary events.</li>
</ol>
<p>You end up having a fairly elegent solution to the problem, see the code below:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Translate.cs</div>
<div style="background: #fff; max-height: 400px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">using</span> System;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Collections.Generic;</li>
<li><span style="color: #0000ff;">using</span> System.Linq;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Text;</li>
<li><span style="color: #0000ff;">using</span> System.Collections;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Diagnostics;</li>
<li><span style="color: #0000ff;">using</span> System.Xml.Linq;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Reflection;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.IO;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.IO;</li>
<li><span style="color: #0000ff;">using</span> System.Threading;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Runtime.Serialization.Formatters.Binary;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Data;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Data.Items;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.SecurityModel;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Globalization;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Configuration;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Collections;</li>
<li><span style="color: #0000ff;">using</span> Sitecore;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.StringExtensions;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">namespace</span> mm.virginactive.common.Globalization</li>
<li>{</li>
<li style="background: #f3f3f3;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">Translate</span></li>
<li>    {</li>
<li style="background: #f3f3f3;">        <span style="color: #008000;">// Fields</span></li>
<li>        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #2b91af;">Hashtable</span> _languages;</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">readonly</span> <span style="color: #0000ff;">object</span> _lock = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>();</li>
<li style="background: #f3f3f3;">        <span style="color: #008000;">// Methods</span></li>
<li>        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #2b91af;">XDocument</span> CreateDictionary(<span style="color: #2b91af;">Type</span> type)</li>
<li style="background: #f3f3f3;">        {</li>
<li>            <span style="color: #2b91af;">Assert</span>.IsNotNull(type, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Type</span>));</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">XDocument</span> document = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">XDocument</span>(<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">XDeclaration</span>(<span style="color: #a31515;">&#8220;1.0&#8243;</span>, <span style="color: #a31515;">&#8220;utf-8&#8243;</span>, <span style="color: #0000ff;">null</span>), <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>[0]);</li>
<li>            <span style="color: #2b91af;">XElement</span> content = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">&#8220;sitecore&#8221;</span>);</li>
<li style="background: #f3f3f3;">            document.Add(content);</li>
<li>            <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">FieldInfo</span> info <span style="color: #0000ff;">in</span> type.GetFields())</li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #0000ff;">string</span> rawConstantValue = info.GetRawConstantValue() <span style="color: #0000ff;">as</span> <span style="color: #0000ff;">string</span>;</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(rawConstantValue))</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">XElement</span> element2 = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">&#8220;phrase&#8221;</span>)</li>
<li>                    {</li>
<li style="background: #f3f3f3;">                        Value = Text(rawConstantValue)</li>
<li>                    };</li>
<li style="background: #f3f3f3;">                    element2.Add(<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">XAttribute</span>(<span style="color: #a31515;">&#8220;key&#8221;</span>, rawConstantValue));</li>
<li>                    content.Add(element2);</li>
<li style="background: #f3f3f3;">                }</li>
<li>            }</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">return</span> document;</li>
<li>        }</li>
<li>        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> GetFilename()</li>
<li style="background: #f3f3f3;">        {</li>
<li>            <span style="color: #0000ff;">return</span> <span style="color: #2b91af;">FileUtil</span>.MapPath(<span style="color: #2b91af;">FileUtil</span>.MakePath(<span style="color: #2b91af;">TempFolder</span>.Folder, <span style="color: #a31515;">&#8220;dictionary_web.dat&#8221;</span>));</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #2b91af;">Hashtable</span> Load()</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">string</span> filename = GetFilename();</li>
<li>            <span style="color: #0000ff;">if</span> (<span style="color: #2b91af;">FileUtil</span>.Exists(filename))</li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #0000ff;">object</span> obj2;</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">try</span></li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #0000ff;">if</span> ((<span style="color: #2b91af;">File</span>.GetAttributes(filename) &amp; <span style="color: #2b91af;">FileAttributes</span>.ReadOnly) == <span style="color: #2b91af;">FileAttributes</span>.ReadOnly)</li>
<li>                    {</li>
<li style="background: #f3f3f3;">                        <span style="color: #2b91af;">Log</span>.Info(<span style="color: #0000ff;">string</span>.Format(<span style="color: #a31515;">&#8220;{0} is read-only. Rebuilding cache from database.&#8221;</span>, filename), <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li>                        <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</li>
<li style="background: #f3f3f3;">                    }</li>
<li>                }</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">catch</span> (<span style="color: #2b91af;">Exception</span> exception)</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">Log</span>.Error(<span style="color: #0000ff;">string</span>.Format(<span style="color: #a31515;">&#8220;Failed to get file attributes on {0}. Rebuilding cache from database.&#8221;</span>, filename), exception, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li>                    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #2b91af;">Monitor</span>.Enter(obj2 = <span style="color: #2b91af;">FileUtil</span>.GetFileLock(filename));</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">try</span></li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">Log</span>.Info(<span style="color: #a31515;">&#8220;Loading Dictionary from cache&#8221;</span>, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li>                    <span style="color: #2b91af;">BinaryFormatter</span> formatter = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">BinaryFormatter</span>();</li>
<li style="background: #f3f3f3;">                    <span style="color: #0000ff;">using</span> (<span style="color: #2b91af;">FileStream</span> stream = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">FileStream</span>(filename, <span style="color: #2b91af;">FileMode</span>.Open, <span style="color: #2b91af;">FileAccess</span>.Read, <span style="color: #2b91af;">FileShare</span>.Read, 0&#215;2000))</li>
<li>                    {</li>
<li style="background: #f3f3f3;">                        <span style="color: #0000ff;">return</span> (formatter.Deserialize(stream) <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">Hashtable</span>);</li>
<li>                    }</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #0000ff;">catch</span> (<span style="color: #2b91af;">Exception</span> exception2)</li>
<li style="background: #f3f3f3;">                {</li>
<li>                    <span style="color: #2b91af;">Log</span>.Error(<span style="color: #a31515;">&#8220;Error loading data.&#8221;</span>, exception2, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #0000ff;">finally</span></li>
<li style="background: #f3f3f3;">                {</li>
<li>                    <span style="color: #2b91af;">Monitor</span>.Exit(obj2);</li>
<li style="background: #f3f3f3;">                }</li>
<li>            }</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;</li>
<li>        }</li>
<li>        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #2b91af;">Hashtable</span> Load(<span style="color: #0000ff;">string</span> language)</li>
<li style="background: #f3f3f3;">        {</li>
<li>            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(language, <span style="color: #a31515;">&#8220;language&#8221;</span>);</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Log</span>.Info(<span style="color: #a31515;">&#8220;Loading Dictionary from database&#8221;</span>, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li>            <span style="color: #2b91af;">Hashtable</span> table = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Hashtable</span>();</li>
<li style="background: #f3f3f3;">            Languages[language] = table;</li>
<li>            <span style="color: #0000ff;">try</span></li>
<li style="background: #f3f3f3;">            {</li>
<li>                Sitecore.Data.<span style="color: #2b91af;">Database</span> database = <span style="color: #2b91af;">Factory</span>.GetDatabase(<span style="color: #a31515;">&#8220;web&#8221;</span>);</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">using</span> (<span style="color: #0000ff;">new</span> <span style="color: #2b91af;">SecurityDisabler</span>())</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">Item</span> item = database.GetItem(<span style="color: #a31515;">&#8220;/sitecore/system/dictionary&#8221;</span>, <span style="color: #2b91af;">Language</span>.Parse(language));</li>
<li>                    <span style="color: #0000ff;">if</span> (item != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">                    {</li>
<li>                        Load(table, item);</li>
<li style="background: #f3f3f3;">                    }</li>
<li>                }</li>
<li style="background: #f3f3f3;">                Save();</li>
<li>            }</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">catch</span> (<span style="color: #2b91af;">InvalidOperationException</span> exception)</li>
<li>            {</li>
<li style="background: #f3f3f3;">                <span style="color: #2b91af;">Log</span>.Warn(<span style="color: #a31515;">&#8220;Failed to load Dictionary (language: {0}). Error message: {1}&#8221;</span>.FormatWith(<span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>[] { language, exception.Message }), <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">object</span>());</li>
<li>            }</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">return</span> table;</li>
<li>        }</li>
<li>        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Load(<span style="color: #2b91af;">Hashtable</span> table, <span style="color: #2b91af;">Item</span> item)</li>
<li style="background: #f3f3f3;">        {</li>
<li>            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(table, <span style="color: #a31515;">&#8220;table&#8221;</span>);</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(item, <span style="color: #a31515;">&#8220;item&#8221;</span>);</li>
<li>            <span style="color: #2b91af;">TemplateItem</span> template = item.Template;</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">if</span> (template != <span style="color: #0000ff;">null</span>)</li>
<li>            {</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">if</span> (template.Key == <span style="color: #a31515;">&#8220;dictionary entry&#8221;</span>)</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #0000ff;">string</span> str = item[<span style="color: #a31515;">"Key"</span>].Replace(<span style="color: #a31515;">&#8220;\r\n&#8221;</span>, <span style="color: #a31515;">&#8220;\n&#8221;</span>).Replace(<span style="color: #a31515;">@&#8221;\n&#8221;</span>, <span style="color: #a31515;">&#8220;\n&#8221;</span>);</li>
<li>                    <span style="color: #0000ff;">string</span> str2 = item[<span style="color: #a31515;">"Phrase"</span>];</li>
<li style="background: #f3f3f3;">                    str2 = str2.Replace(<span style="color: #a31515;">&#8220;\r\n&#8221;</span>, <span style="color: #a31515;">&#8220;\n&#8221;</span>).Replace(<span style="color: #a31515;">@&#8221;\n&#8221;</span>, <span style="color: #a31515;">&#8220;\n&#8221;</span>).Replace(<span style="color: #a31515;">&#8220;&amp;lt;&#8221;</span>, <span style="color: #a31515;">&#8220;&lt;&#8221;</span>).Replace(<span style="color: #a31515;">&#8220;&amp;gt;&#8221;</span>, <span style="color: #a31515;">&#8220;&gt;&#8221;</span>);</li>
<li>                    table[str] = str2;</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">Item</span> item3 <span style="color: #0000ff;">in</span> item.GetChildren(<span style="color: #2b91af;">ChildListOptions</span>.None))</li>
<li style="background: #f3f3f3;">                {</li>
<li>                    Load(table, item3);</li>
<li style="background: #f3f3f3;">                }</li>
<li>            }</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">internal</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Save()</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">string</span> filename = GetFilename();</li>
<li>            <span style="color: #0000ff;">lock</span> (<span style="color: #2b91af;">FileUtil</span>.GetFileLock(filename))</li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #0000ff;">try</span></li>
<li style="background: #f3f3f3;">                {</li>
<li>                    <span style="color: #2b91af;">FileUtil</span>.Delete(filename);</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #0000ff;">catch</span> (<span style="color: #2b91af;">Exception</span> exception)</li>
<li style="background: #f3f3f3;">                {</li>
<li>                    <span style="color: #2b91af;">Log</span>.Error(<span style="color: #0000ff;">string</span>.Format(<span style="color: #a31515;">&#8220;Error delete {0}.&#8221;</span>, filename), exception, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #0000ff;">try</span></li>
<li style="background: #f3f3f3;">                {</li>
<li>                    <span style="color: #2b91af;">TempFolder</span>.EnsureFolder();</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">BinaryFormatter</span> formatter = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">BinaryFormatter</span>();</li>
<li>                    <span style="color: #0000ff;">using</span> (<span style="color: #2b91af;">FileStream</span> stream = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">FileStream</span>(filename, <span style="color: #2b91af;">FileMode</span>.CreateNew, <span style="color: #2b91af;">FileAccess</span>.Write, <span style="color: #2b91af;">FileShare</span>.Write, 0&#215;2000))</li>
<li style="background: #f3f3f3;">                    {</li>
<li>                        formatter.Serialize(stream, Languages);</li>
<li style="background: #f3f3f3;">                    }</li>
<li>                }</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">catch</span> (<span style="color: #2b91af;">Exception</span> exception2)</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #2b91af;">Log</span>.Error(<span style="color: #0000ff;">string</span>.Format(<span style="color: #a31515;">&#8220;Error saving {0}.&#8221;</span>, filename), exception2, <span style="color: #0000ff;">typeof</span>(<span style="color: #2b91af;">Translate</span>));</li>
<li>                    <span style="color: #2b91af;">FileUtil</span>.Delete(filename);</li>
<li style="background: #f3f3f3;">                }</li>
<li>            }</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> Text(<span style="color: #0000ff;">string</span> key)</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(key, <span style="color: #a31515;">&#8220;key&#8221;</span>);</li>
<li>            <span style="color: #0000ff;">return</span> TextByLanguage(key, <span style="color: #2b91af;">Context</span>.Language);</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> Text(<span style="color: #0000ff;">string</span> key, <span style="color: #0000ff;">params</span> <span style="color: #0000ff;">object</span>[] parameters)</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(key, <span style="color: #a31515;">&#8220;key&#8221;</span>);</li>
<li>            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(parameters, <span style="color: #a31515;">&#8220;parameters&#8221;</span>);</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">string</span> format = Text(key);</li>
<li>            <span style="color: #0000ff;">if</span> (parameters.Length &gt; 0)</li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">string</span>.Format(format, parameters);</li>
<li style="background: #f3f3f3;">            }</li>
<li>            <span style="color: #0000ff;">return</span> format;</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> TextByLanguage(<span style="color: #0000ff;">string</span> key, <span style="color: #2b91af;">Language</span> language)</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(key, <span style="color: #a31515;">&#8220;key&#8221;</span>);</li>
<li>            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(language, <span style="color: #a31515;">&#8220;language&#8221;</span>);</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">return</span> (TextByLanguage(key, language, key) ?? <span style="color: #0000ff;">string</span>.Empty);</li>
<li>        }</li>
<li>        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> TextByLanguage(<span style="color: #0000ff;">string</span> key, <span style="color: #2b91af;">Language</span> language, <span style="color: #0000ff;">string</span> defaultValue)</li>
<li style="background: #f3f3f3;">        {</li>
<li>            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(key, <span style="color: #a31515;">&#8220;key&#8221;</span>);</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Assert</span>.ArgumentNotNull(language, <span style="color: #a31515;">&#8220;language&#8221;</span>);</li>
<li>            <span style="color: #0000ff;">return</span> (TextByLanguage(key, language, defaultValue, <span style="color: #0000ff;">null</span>) ?? defaultValue);</li>
<li style="background: #f3f3f3;">        }</li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> TextByLanguage(<span style="color: #0000ff;">string</span> key, <span style="color: #2b91af;">Language</span> language, <span style="color: #0000ff;">string</span> defaultValue, <span style="color: #0000ff;">params</span> <span style="color: #0000ff;">object</span>[] parameters)</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">string</span>.IsNullOrEmpty(key))</li>
<li>            {</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">return</span> key;</li>
<li>            }</li>
<li style="background: #f3f3f3;">            <span style="color: #2b91af;">Hashtable</span> hashtable = Languages[language.ToString()] <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">Hashtable</span>;</li>
<li>            <span style="color: #0000ff;">if</span> (hashtable == <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">            {</li>
<li>                hashtable = Load(language.ToString());</li>
<li style="background: #f3f3f3;">            }</li>
<li>            <span style="color: #0000ff;">string</span> str = hashtable[key] <span style="color: #0000ff;">as</span> <span style="color: #0000ff;">string</span>;</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">string</span>.IsNullOrEmpty(str))</li>
<li>            {</li>
<li style="background: #f3f3f3;">                <span style="color: #008000;">//GlobalizationCounters.TextsTranslated.Increment();</span></li>
<li>                <span style="color: #0000ff;">if</span> (parameters != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">                {</li>
<li>                    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">string</span>.Format(str, parameters);</li>
<li style="background: #f3f3f3;">                }</li>
<li>                <span style="color: #0000ff;">return</span> str;</li>
<li style="background: #f3f3f3;">            }</li>
<li>            <span style="color: #008000;">//GlobalizationCounters.TranslateFailed.Increment();</span></li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">if</span> ((parameters != <span style="color: #0000ff;">null</span>) &amp;&amp; (defaultValue != <span style="color: #0000ff;">null</span>))</li>
<li>            {</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">string</span>.Format(defaultValue, parameters);</li>
<li>            }</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">return</span> defaultValue;</li>
<li>        }</li>
<li>        <span style="color: #008000;">// Properties</span></li>
<li style="background: #f3f3f3;">        <span style="color: #0000ff;">internal</span> <span style="color: #0000ff;">static</span> <span style="color: #2b91af;">Hashtable</span> Languages</li>
<li>        {</li>
<li style="background: #f3f3f3;">            <span style="color: #0000ff;">get</span></li>
<li>            {</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">if</span> (_languages == <span style="color: #0000ff;">null</span>)</li>
<li>                {</li>
<li style="background: #f3f3f3;">                    <span style="color: #0000ff;">lock</span> (_lock)</li>
<li>                    {</li>
<li style="background: #f3f3f3;">                        <span style="color: #0000ff;">if</span> (_languages == <span style="color: #0000ff;">null</span>)</li>
<li>                        {</li>
<li style="background: #f3f3f3;">                            _languages = Load();</li>
<li>                            <span style="color: #0000ff;">if</span> (_languages == <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">                            {</li>
<li>                                _languages = <span style="color: #0000ff;">new</span> <span style="color: #2b91af;">Hashtable</span>();</li>
<li style="background: #f3f3f3;">                            }</li>
<li>                        }</li>
<li style="background: #f3f3f3;">                    }</li>
<li>                }</li>
<li style="background: #f3f3f3;">                <span style="color: #0000ff;">return</span> _languages;</li>
<li>            }</li>
<li style="background: #f3f3f3;">        }</li>
<li>    }</li>
<li style="background: #f3f3f3;">}</li>
</ol>
</div>
</div>
<p>Here is the ItemEventHandler:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">ItemEventHandler.cs</div>
<div style="background: #fff; max-height: 400px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">using</span> System;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Collections.Generic;</li>
<li><span style="color: #0000ff;">using</span> System.Linq;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> System.Text;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Data.Items;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore;</li>
<li><span style="color: #0000ff;">using</span> System.Collections;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> Sitecore.Events;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Data.Events;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">using</span> mm.virginactive.common.Globalization;</li>
<li><span style="color: #0000ff;">using</span> Sitecore.Diagnostics;</li>
<li><span style="color: #0000ff;">namespace</span> mm.virginactive.common.Globalization</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">sealed</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">ItemEventHandler</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #008000;">// Methods</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnItemDeleted(<span style="color: #2b91af;">Item</span> item, <span style="color: #0000ff;">bool</span> saveToDisk)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (item.TemplateID == <span style="color: #2b91af;">TemplateIDs</span>.DictionaryEntry)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">string</span> key = item[<span style="color: #a31515;">"Key"</span>];</li>
<li><span style="color: #0000ff;">foreach</span> (<span style="color: #2b91af;">Hashtable</span> hashtable <span style="color: #0000ff;">in</span> <span style="color: #2b91af;">Translate</span>.Languages.Values)</li>
<li style="background: #f3f3f3;">{</li>
<li>hashtable.Remove(key);</li>
<li style="background: #f3f3f3;">}</li>
<li><span style="color: #0000ff;">if</span> (saveToDisk)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">Translate</span>.Save();</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">internal</span> <span style="color: #0000ff;">void</span> OnItemDeleted(<span style="color: #0000ff;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> args)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Item</span> item = <span style="color: #2b91af;">Event</span>.ExtractParameter(args, 0) <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">Item</span>;</li>
<li><span style="color: #0000ff;">if</span> (item != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">this</span>.OnItemDeleted(item, <span style="color: #0000ff;">true</span>);</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li><span style="color: #0000ff;">internal</span> <span style="color: #0000ff;">void</span> OnItemDeletedRemote(<span style="color: #0000ff;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> args)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">ItemDeletedRemoteEventArgs</span> args2 = args <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">ItemDeletedRemoteEventArgs</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (args2 != <span style="color: #0000ff;">null</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">this</span>.OnItemDeleted(args2.Item, <span style="color: #0000ff;">false</span>);</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> OnItemSaved(<span style="color: #2b91af;">Item</span> item, <span style="color: #0000ff;">bool</span> saveToDisk)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (item.TemplateID == <span style="color: #2b91af;">TemplateIDs</span>.DictionaryEntry)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Hashtable</span> languages = <span style="color: #2b91af;">Translate</span>.Languages;</li>
<li><span style="color: #0000ff;">string</span> str = item[<span style="color: #a31515;">"Key"</span>];</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">foreach</span> (Sitecore.Globalization.<span style="color: #2b91af;">Language</span> language <span style="color: #0000ff;">in</span> item.Languages)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Hashtable</span> hashtable2 = languages[language.ToString()] <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">Hashtable</span>;</li>
<li><span style="color: #0000ff;">if</span> (hashtable2 != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">Item</span> item2 = item.Database.Items[item.ID, language];</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (item2 != <span style="color: #0000ff;">null</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;">hashtable2[str] = item2[<span style="color: #a31515;">"Phrase"</span>];</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (saveToDisk)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Translate</span>.Save();</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li><span style="color: #0000ff;">internal</span> <span style="color: #0000ff;">void</span> OnItemSaved(<span style="color: #0000ff;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> args)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">Assert</span>.ArgumentNotNull(sender, <span style="color: #a31515;">&#8220;sender&#8221;</span>);</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Assert</span>.ArgumentNotNull(args, <span style="color: #a31515;">&#8220;args&#8221;</span>);</li>
<li><span style="color: #2b91af;">Item</span> item = <span style="color: #2b91af;">Event</span>.ExtractParameter(args, 0) <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">Item</span>;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (item != <span style="color: #0000ff;">null</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">this</span>.OnItemSaved(item, <span style="color: #0000ff;">true</span>);</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">internal</span> <span style="color: #0000ff;">void</span> OnItemSavedRemote(<span style="color: #0000ff;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> args)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Assert</span>.ArgumentNotNull(sender, <span style="color: #a31515;">&#8220;sender&#8221;</span>);</li>
<li><span style="color: #2b91af;">Assert</span>.ArgumentNotNull(args, <span style="color: #a31515;">&#8220;args&#8221;</span>);</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">ItemSavedRemoteEventArgs</span> args2 = args <span style="color: #0000ff;">as</span> <span style="color: #2b91af;">ItemSavedRemoteEventArgs</span>;</li>
<li><span style="color: #0000ff;">if</span> (args2 != <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">this</span>.OnItemSaved(args2.Item, <span style="color: #0000ff;">false</span>);</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol>
</div>
</div>
<p>Finally the patch file to make it all work:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">&lt;?</span><span style="color: #a31515;">xml</span><span style="color: #ff0000;">version</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0</span>&#8220;<span style="color: #0000ff;">?&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: #ff0000;">xmlns:x</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">http://www.sitecore.net/xmlconfig/</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">  &lt;</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">events</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">event</span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">item:deleted</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">handler</span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">mm.virginactive.common.Globalization.ItemEventHandler, mm.virginactive.common</span>&#8220;<span style="color: #ff0000;">method</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">OnItemDeleted</span>&#8220;<span style="color: #ff0000;">x:after</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">handler[@type='Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel']</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">event</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">event</span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">item:deleted:remote</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">handler</span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">mm.virginactive.common.Globalization.ItemEventHandler, mm.virginactive.common</span>&#8220;<span style="color: #ff0000;">method</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">OnItemDeletedRemote</span>&#8220;<span style="color: #ff0000;">x:after</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">handler[@type='Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel']</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">event</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">event</span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">item:saved</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">handler</span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">mm.virginactive.common.Globalization.ItemEventHandler, mm.virginactive.common</span>&#8220;<span style="color: #ff0000;">method</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">OnItemSaved</span>&#8220;<span style="color: #ff0000;">x:after</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">handler[@type='Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel']</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">event</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">event</span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">item:saved:remote</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">handler</span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">mm.virginactive.common.Globalization.ItemEventHandler, mm.virginactive.common</span>&#8220;<span style="color: #ff0000;">method</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">OnItemSavedRemote</span>&#8220;<span style="color: #ff0000;">x:after</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">handler[@type='Sitecore.Globalization.ItemEventHandler, Sitecore.Kernel']</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">event</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">events</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">  &lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></li>
</ol>
</div>
</div>
<p>This has been a result of the posts in the following discussion with <strong> Rickard Andersson</strong> within SDN:</p>
<p><a href="http://sdn.sitecore.net/forum//ShowPost.aspx?PostID=41386">http://sdn.sitecore.net/forum//ShowPost.aspx?PostID=41386</a></p>
<p>Please note, the namespace of my project is mm.virginactive.common, so in order to access a translated item I need to fetch:</p>
<p><span style="color: #0000ff;">mm.virginactive.common.Globalization.Translate.Text(&#8220;Dictionarykey&#8221;);</span></p>
<p>You should update the namespace to be relevant to your project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/getting-sitecore-dictionary-items-to-work-on-cd-servers-against-web-database/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fix for issue using SwitchMasterToWeb.config to remove all references to &#8216;master&#8217; database v6.5 when running DMS 2.0</title>
		<link>http://www.cmssource.co.uk/blog/error-using-switchmastertoweb-config-to-remove-all-references-to-master-database-v6-5-when-running-dms-2-0</link>
		<comments>http://www.cmssource.co.uk/blog/error-using-switchmastertoweb-config-to-remove-all-references-to-master-database-v6-5-when-running-dms-2-0#comments</comments>
		<pubDate>Thu, 15 Sep 2011 16:02:51 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=93</guid>
		<description><![CDATA[Error using SwitchMasterToWeb.config to remove all references to 'master' database v6.5 when running DMS 2.0 can be solved by adding  Analytics.DefaultDefinitionDatabase setting to the patch file. - by CMS Source]]></description>
			<content:encoded><![CDATA[<p>I have followed the scaling guide http://sdn.sitecore.net/upload/sitecore6/64/scaling_guide_sc63-64-a4.pdf section:</p>
<p>4.6 How to: Remove References to the Master Database.</p>
<p>You can download the SwitchMasterToWeb.config file <a href="http://sdn.sitecore.net/Reference/Sitecore%206/Scaling%20Guide.aspx">here</a> and place it the /App_Config/Includes folder.</p>
<p>If you have Analytics running, you may end up seeing this error (especially if you try to view the site from outside the server that is hosting):</p>
<pre>Exception: System.InvalidOperationException
Message: Could not find configuration node: databases/database[@id='master']
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.IsTrue(Boolean condition, String message)
   at Sitecore.Configuration.Factory.GetConfigNode(String xpath, Boolean assert)
   at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
   at Sitecore.Configuration.Factory.GetDatabase(String name, Boolean assert)
   at Sitecore.Configuration.Factory.GetDatabase(String name)
   at Sitecore.Analytics.Tracker.get_DefinitionDatabase()
   at Sitecore.Analytics.Pipelines.TrafficTypes.OrganicBranded.Process(TrafficTypeArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Analytics.Pipelines.CreateVisits.SetTrafficType.Process(CreateVisitArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Analytics.Pipelines.InitializeTracker.Initialize.CreateVisit(HttpContext httpContext, Visitor visitor)
   at Sitecore.Analytics.Pipelines.InitializeTracker.Initialize.Process(InitializeTrackerArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Analytics.Pipelines.StartTracking.InitializeTracker.Process(StartTrackingArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Analytics.Tracker.StartTracking()
   at Sitecore.Analytics.Pipelines.HttpRequest.StartAnalytics.Process(RenderLayoutArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Layouts.PageContext.BuildControlTree(Object sender, EventArgs e)
   at System.Web.UI.Page.OnPreInit(EventArgs e)
   at System.Web.UI.Page.PerformPreInit()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</pre>
<p>The one issue I had is, if you have analytics enabled, there is a bit of code in analytics that checks for a setting:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;" start="36">
<li>        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> DefaultDefinitionDatabase</li>
<li style="background: #f3f3f3;">        {</li>
<li>            <span style="color: #0000ff;">get</span></li>
<li style="background: #f3f3f3;">            {</li>
<li>                <span style="color: #0000ff;">return</span> <span style="color: #2b91af;">Settings</span>.GetSetting(<span style="color: #a31515;">&#8220;Analytics.DefaultDefinitionDatabase&#8221;</span>, <span style="color: #a31515;">&#8220;master&#8221;</span>);</li>
<li style="background: #f3f3f3;">            }</li>
<li>        }</li>
</ol>
</div>
</div>
<p>This setting does not exist in the Sitecore.Analytics.config file, and for that reason the code always defaulted to master DB and gave an error, for that reason I have added this config setting to the patch file to get everything working (you can just add it to the SwitchmasterToWeb.config):</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;" start="54">
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">  &lt;</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">settings</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;!&#8211;</span><span style="color: #008000;"> extra setting to bypass analytics error </span><span style="color: #0000ff;">&#8211;&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">setting </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">Analytics.DefaultDefinitionDatabase</span>&#8220; <span style="color: #ff0000;">value</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">web</span>&#8220;<span style="color: #0000ff;"> /&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">settings</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">  &lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></li>
</ol>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/error-using-switchmastertoweb-config-to-remove-all-references-to-master-database-v6-5-when-running-dms-2-0/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A starter patch file for new sitecore projects</title>
		<link>http://www.cmssource.co.uk/blog/a-starter-patch-file-for-new-sitecore-projects</link>
		<comments>http://www.cmssource.co.uk/blog/a-starter-patch-file-for-new-sitecore-projects#comments</comments>
		<pubDate>Tue, 30 Aug 2011 09:23:44 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[config patch]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[patch file]]></category>
		<category><![CDATA[sitecore]]></category>
		<category><![CDATA[sitecore 6.5]]></category>
		<category><![CDATA[sitecore include file]]></category>
		<category><![CDATA[web.config patch]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=63</guid>
		<description><![CDATA[There are very few reasons to pollute any of the web.config given that everything between the <sitecore></sitecore> tags can be modified via patch files. I have attempted to share a basic 'handy' patch file here which can be used with any new sitecore solution. - By CMS Source.]]></description>
			<content:encoded><![CDATA[<p>In general, since the introduction of patch file after sitecore 6.3, all sitecore projects should have their own basic patch file (these should be placed within the &#8216;sitecoreroot/App_Config/Include&#8217;  folder .</p>
<p>There are very few reasons to pollute any of the web.config given that everything between the &lt;sitecore&gt;&lt;/sitecore&gt; tags can be modified via patch files.</p>
<p>I have attempted to share a basic &#8216;handy&#8217; patch file here which can be used with any new sitecore solution, please let me know if I have missed anything obvious/important.  Most if not all the config entries that are patched here should eventually be patched for any sitecore implementation.  I will attempt to update this post with additional patch files that modify things like HTML caches and item threshold etc.</p>
<p><strong>Note</strong>: You will need to replace the values I have entered here with those relevant to your project.</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">ProjectName.config</div>
<div style="background: #fff; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0; padding: 0 0 0 5px;" start="1">
<li><span style="color: #0000ff;">&lt;?</span><span style="color: #a31515;">xml</span><span style="color: #ff0000;"> version</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0</span>&#8220;<span style="color: #0000ff;">?&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">configuration</span><span style="color: #ff0000;"> xmlns:x</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">http://www.sitecore.net/xmlconfig/</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">  &lt;</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">settings</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;"><br />
</span></li>
<li><span style="color: #0000ff;">      &lt;!&#8211;</span><span style="color: #008000;"> Custom 404 error page</span><span style="color: #0000ff;">&#8211;&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">setting</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">ItemNotFoundUrl</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">x:attribute </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">value</span>&#8220;<span style="color: #0000ff;">&gt;</span>/lost-404.aspx<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">x:attribute</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">setting</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">    </span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;!&#8211;</span><span style="color: #008000;">  ERROR HANDLER</span></li>
<li><span style="color: #008000;">            Url of page handling generic errors</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">      </span><span style="color: #0000ff;">&#8211;&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">setting </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">ErrorPage</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">x:attribute</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">value</span>&#8220;<span style="color: #0000ff;">&gt;</span>/general-error.aspx<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">x:attribute</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">setting</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;!&#8211;</span><span style="color: #008000;">  MAIL SERVER</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">            SMTP server used for sending mails by the Sitecore server</span></li>
<li><span style="color: #008000;">            Is used by MainUtil.SendMail()</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">            Default value: &#8220;&#8221;</span></li>
<li><span style="color: #008000;">      </span><span style="color: #0000ff;">&#8211;&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">setting </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">MailServer</span>&#8221; <span style="color: #ff0000;">value</span><span style="color: #0000ff;">=</span>&#8220;&#8221;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">x:attribute</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">value</span>&#8220;<span style="color: #0000ff;">&gt;</span>smtp.domain.com<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">x:attribute</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">setting</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;!&#8211;</span><span style="color: #008000;">  WEB SITE STYLESHEET</span></li>
<li><span style="color: #008000;">            CSS file for HTML content of Sitecore database.</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">            The file pointed to by WebStylesheet setting is automatically included in Html and Rich Text fields.</span></li>
<li><span style="color: #008000;">            By using it, you can make the content of HTML fields look the same as the actual Web Site</span></li>
<li style="background: #f3f3f3;"><span style="color: #008000;">      </span><span style="color: #0000ff;">&#8211;&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">setting</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">WebStylesheet</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">x:attribute </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">value</span>&#8220;<span style="color: #0000ff;">&gt;</span>/css/style.css<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">x:attribute</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">setting</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">settings</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">scheduling</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">agent</span><span style="color: #ff0000;"> type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">Sitecore.Tasks.UrlAgent</span>&#8221; <span style="color: #ff0000;">method</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">Run</span>&#8220;<span style="color: #ff0000;"> interval</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">01:00:00</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">        &lt;</span><span style="color: #a31515;">param </span><span style="color: #ff0000;">desc</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">url</span>&#8220;<span style="color: #0000ff;">&gt;</span>http://your.host/sitecore/service/keepalive.aspx<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">param</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">      &lt;/</span><span style="color: #a31515;">agent</span><span style="color: #0000ff;">&gt;      </span></li>
<li><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">scheduling</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    </span></li>
<li><span style="color: #0000ff;">    &lt;!&#8211;</span><span style="color: #008000;"> Your data folder should not be kept within your sitecore web root, you can explicitly define the location of your data folder here </span><span style="color: #0000ff;">&#8211;&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;</span><span style="color: #a31515;">sc.variable </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">dataFolder</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">      &lt;</span><span style="color: #a31515;">x:attribute </span><span style="color: #ff0000;">name</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">value</span>&#8220;<span style="color: #0000ff;">&gt;</span>C:\websites\yourproject\Data<span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">x:attribute</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">sc.variable</span><span>&gt;</span></li>
<li><span style="color: #0000ff;">    &lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></li>
</ol>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/a-starter-patch-file-for-new-sitecore-projects/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ignore sub-item structure and link directly to an article in sitecore</title>
		<link>http://www.cmssource.co.uk/blog/ignore-sub-item-structure-and-link-directly-to-an-article-in-sitecore</link>
		<comments>http://www.cmssource.co.uk/blog/ignore-sub-item-structure-and-link-directly-to-an-article-in-sitecore#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:53:15 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[HttpRequestProcessor]]></category>
		<category><![CDATA[sitecore 6.5]]></category>
		<category><![CDATA[URL resolve]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=59</guid>
		<description><![CDATA[In response to a forum post in SDN http://sdn.sitecore.net/SDN5/Forum/ShowPost.aspx?PostID=38809 , I thought I would blog about this because it is quite a common situation. (Tested on V 6.5)
Let's assume you have a huge collection of items that needs to be segregated into sub-folders because of sheer volume. You may still want to have the URL to the articles accessible via a more direct link (which ignores the sub-directory structure). This post highlights one method of achieving this in the Sitecore .NET CMS.]]></description>
			<content:encoded><![CDATA[<p>In response to a forum post in SDN <a title="SDN topic" href="http://sdn.sitecore.net/SDN5/Forum/ShowPost.aspx?PostID=38809" target="_blank">http://sdn.sitecore.net/SDN5/Forum/ShowPost.aspx?PostID=38809</a> , I thought I would blog about this because it is quite a common situation. (Tested on V 6.5)</p>
<p>Let&#8217;s assume you have a huge collection of items that needs to be segregated into sub-folders because of sheer volume. I will use a Press landing and press articles as an example.</p>
<p>So our content structure will be similar to what is shown in the image.<a href="http://www.cmssource.co.uk/wp-content/uploads/2011/08/news-section.png"><img class="alignleft size-full wp-image-60" title="news-section" src="http://www.cmssource.co.uk/wp-content/uploads/2011/08/news-section.png" alt="news section example" width="257" height="191" /></a></p>
<p>I have used only years to separate my articles, but depending on the number of articles your site is planning on having, you may want to have a folder structure like yyyy/MMM/dd/article.</p>
<p>Its often a requirement to not show the sub-folder structure in your URL, e.g. for the example below you would want: <a href="http://domain.com/press/article-one.aspx">http://domain.com/press/article-one.aspx</a></p>
<p>The actual location is  <a href="http://domain.com/press/2011/article-one.aspx">http://domain.com/press/2011/article-one.aspx</a></p>
<p>in order to achieve this, Add a custom pipeline after ItemResolver. Generate your URL&#8217;s so that the links look like the way you want it to look and you are good to go.</p>
<p>&nbsp;</p>
<p>Add an include file with the pipeline hack:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">&lt;?</span><span style="color: #a31515;">xml </span><span style="color: #ff0000;">version</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">1.0</span>&#8220;<span style="color: #0000ff;">?&gt;</span></li>
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">configuration </span><span style="color: #ff0000;">xmlns:x</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">http://www.sitecore.net/xmlconfig/</span>&#8220;<span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">pipelines</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">httpRequestBegin</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;</span><span style="color: #a31515;">processor </span><span style="color: #ff0000;">x:after</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">processor[@type='Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']</span>&#8221; <span style="color: #ff0000;">type</span><span style="color: #0000ff;">=</span>&#8220;<span style="color: #0000ff;">CmsS.example.controls.Pipelines.ExampleHttpResolver, CmsS.example.controls</span>&#8220;<span style="color: #0000ff;">/&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">httpRequestBegin</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">pipelines</span><span style="color: #0000ff;">&gt;</span></li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">sitecore</span><span style="color: #0000ff;">&gt;</span></li>
<li><span style="color: #0000ff;">&lt;/</span><span style="color: #a31515;">configuration</span><span style="color: #0000ff;">&gt;</span></li>
</ol>
</div>
</div>
<p>Create your ExampleHttpResolver.cs:</p>
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt;">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px;">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto;">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> <span style="color: #2b91af;">ExampleHttpResolver</span> : <span style="color: #2b91af;">HttpRequestProcessor</span></li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">private</span> <span style="color: #2b91af;">Item</span> context;</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> Process(<span style="color: #2b91af;">HttpRequestArgs</span> args)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Assert</span>.ArgumentNotNull(args, <span style="color: #a31515;">&#8220;args&#8221;</span>);</li>
<li style="background: #f3f3f3;">context = <span style="color: #2b91af;">Context</span>.Item;</li>
<li><span style="color: #0000ff;">if</span> (context == <span style="color: #0000ff;">null</span>)</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(args.LocalPath))</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #0000ff;">if</span> (args.LocalPath.Contains(<span style="color: #a31515;">&#8220;press&#8221;</span>))</li>
<li style="background: #f3f3f3;">{</li>
<li><span style="color: #2b91af;">Item</span> pressHome = <span style="color: #2b91af;">Context</span>.Database.GetItem(<span style="color: #a31515;">&#8220;/sitecore/content/Home/press&#8221;</span>);</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">string</span> articleName = args.LocalPath.Split(<span style="color: #a31515;">&#8216;/&#8217;</span>).Last();</li>
<li><span style="color: #2b91af;">Item</span> article = pressHome.Axes.SelectSingleItem(<span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;descendant::*[@@name='{0}']&#8220;</span>, articleName));</li>
<li style="background: #f3f3f3;"><span style="color: #0000ff;">if</span> (article != <span style="color: #0000ff;">null</span>)</li>
<li>{</li>
<li style="background: #f3f3f3;"><span style="color: #2b91af;">Context</span>.Item = article;</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
<li style="background: #f3f3f3;">}</li>
<li style="background: #f3f3f3;">}</li>
<li>}</li>
</ol>
</div>
</div>
<p>&nbsp;</p>
<p>Please take into account that this is a very basic example to give you an indication of how this can be done, you may also want to:</p>
<ol>
<li>Add error catching</li>
<li>Use a search index if you are dealing with &gt;1500 articles, use this to find the related article instead of an SC query</li>
</ol>
<p>All we are doing here is fooling sitecore to replace an article as a context item instead of throwing a 404, so your articles will need to have presentation assigned to it.</p>
<p>An alternative approach as mentioned by Karina Apostolides in the forum post is to create an Alias for every news article on item:created, you would also need to handle item:renamed to ensure that the alias is renamed when the item is renamed. The advantage of this method is that GetFriendlyUrl will handle the alias automatically.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/ignore-sub-item-structure-and-link-directly-to-an-article-in-sitecore/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customise EviBlog for sitecore</title>
		<link>http://www.cmssource.co.uk/blog/customise-eviblog-for-sitecore</link>
		<comments>http://www.cmssource.co.uk/blog/customise-eviblog-for-sitecore#comments</comments>
		<pubDate>Tue, 29 Mar 2011 13:16:24 +0000</pubDate>
		<dc:creator>Richard Dias</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[EviBlog]]></category>
		<category><![CDATA[Nested List]]></category>
		<category><![CDATA[sitecore]]></category>
		<category><![CDATA[TreeView]]></category>

		<guid isPermaLink="false">http://www.cmssource.co.uk/?p=39</guid>
		<description><![CDATA[There is a nifty new blogging module for sitecore called EviBlog (now known as WeBlog) for sitecore, it can be found in the shared source library. The content of this post is relevant for anyone that wants to customise EviBlog to suit their needs. Edit: the WeBlog source has changed since the release of this post but the concepts are still very much relevant to the current implementation.]]></description>
			<content:encoded><![CDATA[<p>There is a nifty new blogging module for sitecore called EviBlog for sitecore, it can be found in the shared source library.</p>
<p>There is a newer version of EviBlog since I wrote this post, however the content of this post is relevant for anyone that wants to customise EviBlog to suit their needs.</p>
<p>I have added a few examples here of how EviBlog’s functionality can be modified regardless of the version of sitecore and EviBlog that you are working with.</p>
<p>The hierarchical category functionality on this post can be used together with the <a title="Custom Tree List" href="http://www.cmssource.co.uk/blog/custom-tree-list">custom tree list sitecore field</a> I have posted to complete  the user experience.</p>
<p>Please note that I have not made allowance to cater for page editor compatibility for this example.</p>
<p><span style="color: #038119;">INSTALL THE BLOG MODULE</span></p>
<p>First step is to get an installation of EviBlog running on a sitecore environment, just download and install the Sitecore package from the EviBlog site:</p>
<p><a href="http://svn.sitecore.net/EviBlog/Trunk/EviBlog/Website/data/packages/Eviblog-1.5.zip">http://svn.sitecore.net/EviBlog/Trunk/EviBlog/Website/data/packages/Eviblog-1.5.zip</a></p>
<p>One you have successfully installed the module, create a Blog hierarchy wherever you want your blog to reside within your website using the /sitecore/templates/Modules/EviBlog/BlogHome template item.<a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture1.jpg"><img style="display: inline; margin: 5px 10px 0px 0px; border-width: 0px;" title="CropperCapture[1]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture1_thumb.jpg" alt="CropperCapture[1]" width="240" height="244" align="left" border="0" /></a></p>
<p>I wanted my blog to reside under <a href="http://www.host.com/blog">www.mydomain.com/blog</a> so I created a hierarchy within my home page item:</p>
<p>&nbsp;</p>
<p>Once you have created a bit of blog content you should be able to view the bare-bones blog. We are now ready to get the source and customise the blog module.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture2.jpg"><img style="display: inline; border-width: 0px;" title="CropperCapture[2]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture2_thumb.jpg" alt="CropperCapture[2]" width="644" height="242" border="0" /></a></p>
<p><span style="color: #038119;">DOWNLOAD THE SOURCE</span></p>
<p>Once you have the blog going, you can download the source code for the module from:</p>
<p><a href="http://svn.sitecore.net/EviBlog/Trunk/EviBlog">http://svn.sitecore.net/EviBlog/Trunk/EviBlog</a></p>
<p>I suggest that you download the code to an independent location, you do not need to worry about incorporating it with your Sitecore solution.</p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture3.jpg"><img class="alignleft" style="display: inline; margin: 0px 10px 0px 0px; border: 0pt none;" title="CropperCapture[3]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture3_thumb.jpg" alt="CropperCapture[3]" width="177" height="462" align="left" border="0" /></a></p>
<p>The solution file can be found within the ‘Website’ directory and I had no issued opening this with Visual Studio 2010.</p>
<p>The first thing we want to do is to get the project building, in order to do this we need to update the references within the projects to refer to dlls inside our own Sitecoreroot/bin directory. EviBlog is designed to be used with Sitecore version 6.2, if you are using a different version of Sitecore, the best way to get EviBlog running with your own version of Sitecore is the use the Sitecore.Kernel.dll from that version as a reference to the projects. You can set the copy local attribute to false under the properties of each of the dll’s you referenced</p>
<p>&nbsp;</p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/references.jpg"><img class="alignright" style="display: inline; margin-left: 0px; margin-right: 0px; border: 0pt none;" title="references" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/references_thumb.jpg" alt="references" width="387" height="187" align="right" border="0" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #038119;">RE-SKINNING</span></p>
<p>The structure of the Eviblog.Web project should look familiar, it matches the directory structure of your Sitecore root folder.</p>
<p>If you want to make life easier for yourself, you can create an xcopy postbuild event to copy specific folders from the EviBlog.Web project directly into your sitecore root folder. The alternative is to manually copy the changes you have made.</p>
<p>Assuming you are simply interested in re-skinning the EviBlog module to match your requirements, you should be able to get away with modifying some of the files within this project without doing a single build. If this is all you want to do, take a look at the following files:</p>
<p>\Website\sitecore modules\EviBlog\Themes\*.css</p>
<p>&nbsp;</p>
<p><span style="color: #038119;">MORE COMPLEX CHANGES</span></p>
<p>We will be making a series of changes and additions to improve the EviBlog module, the goal will be to provide enough examples to allow you to go ahead and make any additions you want to make with confidence.</p>
<p><span style="color: #038119;">ALLOW CATEGORY HIERACHY</span></p>
<p>We will need to perform the following tasks in order to add hierarchical category support:</p>
<ul>
<li>Add insert options to the category template to allow easy creation of sub-categories.</li>
<li>Change the categories renderer to display hierarchy.</li>
<li>Change the categories field type from a multilist to a tree (allow hierarchical category selection within posts).</li>
</ul>
<p><strong>Add Category insert option</strong></p>
<p>Simply add an insert item to itself via the Standard Values of the BlogCategory template:</p>
<p>/sitecore/templates/Modules/EviBlog/BlogCategory/__Standard Values</p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture4.jpg"><img style="display: inline; border: 0px;" title="CropperCapture[4]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture4_thumb.jpg" alt="CropperCapture[4]" width="644" height="373" border="0" /></a></p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture5.jpg"><img style="display: inline; margin: 0px 10px 0px 0px; border: 0px;" title="CropperCapture[5]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture5_thumb.jpg" alt="CropperCapture[5]" width="244" height="227" align="left" border="0" /></a></p>
<p>&nbsp;</p>
<p>Create a hierarchy of category items within your blog items so that we have something to test against.</p>
<p>This is the end of the easy part.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span id="more-39"></span></p>
<p>&nbsp;</p>
<p><strong>Change the categories renderer to display hierarchy</strong></p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/flatcategories.jpg"><img style="display: inline; margin: 0px 10px 0px 0px; border: 0px;" title="flatcategories" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/flatcategories_thumb.jpg" alt="flatcategories" width="186" height="244" align="left" border="0" /></a></p>
<p>&nbsp;</p>
<p>Fire-bugging the categories section reveals that a list is used as the HTML output, we want to make this into a nested list that represents our new category hierarchy.</p>
<p>We will need to create an XMLDocument to represent the categories. Look <a title="Get sitecore items as XML Hierarchy" href="http://www.cmssource.co.uk/blog/get-sitecore-items-as-xml-hierarchy">here</a> for a recursive method that will create this hierarchy for us.</p>
<p>Lets create a new helper class within the Sitecore.Modules.Eviblog.Utilities namespace. We can create the methods that generate an XMLDocument from an item hierarchy in there.</p>
<p>The control we are interested in is located within Eviblog.Web/Layouts/Blog/BlogCategories.ascx and the backend .cs can be found here: Sitecore.Modules.Eviblog.UserControls.BlogCategories.cs within the Sitecore.Modules.EviBlog project.</p>
<p>Add a method to Sitecore.Modules.Eviblog.Managers.CategoryManager.cs that will interface with our helper class to retrieve the XMLDocument from the Categories root:</p>
<pre class="code"><span style="color: gray;">/// &lt;summary&gt; /// </span><span style="color: green;">Get the categories for the context Blog and returns </span><span style="color: gray;">/// </span><span style="color: green;">an XmlDocument that represents the category hierarchy. </span><span style="color: gray;">/// &lt;/summary&gt; /// &lt;returns&gt;&lt;/returns&gt; </span><span style="color: blue;">public static </span>XmlDocument GetCategoriesAsXml()
{
    <span style="color: green;">//Get the current item </span>Item Blog = Context.Item;

    <span style="color: green;">//Check if current item equals blogroot </span><span style="color: blue;">if </span>(Blog.TemplateID.ToString() != Settings.Default.BlogTemplateID)
    {
        <span style="color: blue;">while </span>(Blog.TemplateID.ToString() != Settings.Default.BlogTemplateID)
        {
            Blog = Blog.Parent;
        }
    }
    Return Sitecore.Modules.Eviblog.Utilities.Helper.GetItemsAsXml(Blog.Axes.GetChild(<span style="color: #a31515;">"Categories"</span>).Paths.Path);
}</pre>
<p>&nbsp;</p>
<p><strong>Change the categories renderer to display hierarchy</strong></p>
<p>There are several ways in which we can now display the Category hierarchy in the front end. Some may prefer to use a plain nested &lt;ul&gt;, some people may choose to use a TreeView control.</p>
<p>For this solution we are going to stick with a nested list of hyperlinks, however I have created an example of both a nested list and a TreeView because it is relatively straight forward go with either one after you <a title="Get sitecore items as XML Hierarchy" href="http://www.cmssource.co.uk/blog/get-sitecore-items-as-xml-hierarchy">fetch the items in an XML hierarchy</a>.</p>
<p><em>Nested List Implementation Option:</em></p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture9.jpg"><img style="display: inline; margin: 0px 10px 0px 0px; border: 0px;" title="CropperCapture[9]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture9_thumb.jpg" alt="CropperCapture[9]" width="268" height="484" align="left" border="0" /></a></p>
<p>&nbsp;</p>
<p>Add a &lt;div&gt; with runat=”server” to the frontend sub-layout <span style="color: #0000ff;">EviBlog.Web.Layouts.Blog. BlogCategories.ascx</span> :</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Modify the backend class <span style="color: #0000ff;">Sitecore.Modules.Eviblog.UserControls .BlogCategories.cs</span> :</p>
<p>Declare the HTML Control:</p>
<p><span style="color: #0000ff;">protected </span>System.Web.UI.HtmlControls.<span style="color: #00ffff;">HtmlGenericControl</span> categoryMenu;</p>
<p>Populate the HTML Control in the <strong>Page_Load</strong> method with the XML hierarchy of the Category Items:</p>
<pre class="code"><span style="color: blue;">protected void </span>Page_Load(<span style="color: blue;">object </span>sender, EventArgs e)
        {
        ...
              ListViewCategories.DataSource = CategoryManager.GetCategories();
              ListViewCategories.ItemDataBound += ListViewCategories_ItemDataBound;
              ListViewCategories.DataBind();

docXML = CategoryManager.GetCategoriesAsXml();
XmlNode categoryNode = docXML.SelectSingleNode(<span style="color: #a31515;">"descendant::item"</span>);
categoryMenu.InnerHtml = String.Format(<span style="color: #a31515;">"&lt;h3&gt;{0}&lt;/h3&gt;&lt;ul id=\"blog-categories\" class=\"sidebar\"&gt;{1}&lt;/ul&gt;"</span>,
                     categoryNode.Attributes[<span style="color: #a31515;">"name"</span>].Value,
                     DisplayChildrenAsList(categoryNode));</pre>
<p>Create the recursive method to populate the nested list (note this list accepts any depth of items):</p>
<pre class="code"><span style="color: green;">// Add the children of this XML node // to this child nodes collection. </span><span style="color: blue;">private void </span>AddTreeViewChildNodes(TreeNodeCollection parent_nodes, XmlNode         xml_node)
{
    <span style="color: green;">// Make the new TreeView node. </span>TreeNode new_node = <span style="color: blue;">new </span>TreeNode(xml_node.Attributes[<span style="color: #a31515;">"name"</span>].Value);
    new_node.Value = xml_node.Attributes[<span style="color: #a31515;">"id"</span>].Value;
    new_node.NavigateUrl = xml_node.Attributes[<span style="color: #a31515;">"link"</span>].Value;
    parent_nodes.Add(new_node);

    <span style="color: blue;">foreach </span>(XmlNode child_node <span style="color: blue;">in </span>xml_node.ChildNodes)
    {
        <span style="color: green;">// Recursively make this node's descendants. </span>AddTreeViewChildNodes(new_node.ChildNodes, child_node);
    }
}</pre>
<p>&nbsp;</p>
<p><em>TreeView Control Implementation Option:</em></p>
<p><a href="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture8.jpg"><img style="display: inline; margin: 0px 10px 0px 0px; border: 0px;" title="CropperCapture[8]" src="http://www.cmssource.co.uk/wp-content/uploads/2011/03/CropperCapture8_thumb.jpg" alt="CropperCapture[8]" width="229" height="231" align="left" border="0" /></a></p>
<p>&nbsp;</p>
<p>Add a basic TreeView Control to the frontend sub-layout <span style="color: #0000ff;">EviBlog.Web.Layouts.Blog. BlogCategories.ascx</span> :</p>
<p><span style="color: #0000ff;">&lt;</span><span style="color: #400000;">asp:TreeView</span> <span style="color: #ff0000;">ID</span>=&#8221;<span style="color: #0000ff;">TreeViewCategories&#8221;</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">=&#8221;server&#8221; /&gt;</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Modify the backend class <span style="color: #0000ff;">Sitecore.Modules.Eviblog.UserControls .BlogCategories.cs</span> :</p>
<p>Declare the TreeView:</p>
<p><span style="color: #0000ff;">protected</span> TreeView TreeViewCategories;</p>
<p>Populate the TreeView in the <strong>Page_Load</strong> method with the XML hierarchy of the Category Items:</p>
<pre class="code"><span style="color: blue;">protected void </span>Page_Load(<span style="color: blue;">object </span>sender, EventArgs e)
        {
        ...
              ListViewCategories.DataSource = CategoryManager.GetCategories();
              ListViewCategories.ItemDataBound += ListViewCategories_ItemDataBound;
              ListViewCategories.DataBind();

        docXML = CategoryManager.GetCategoriesAsXml();
TreeViewCategories.Nodes.Clear() AddTreeViewChildNodes(TreeViewCategories.Nodes, docXML.SelectSingleNode(<span style="color: #a31515;">"descendant::item"</span>));</pre>
<p>Add the recursive method to populate the nodes:</p>
<pre class="code"><span style="color: green;">// Add the children of this XML node // to this child nodes collection. </span><span style="color: blue;">private void </span>AddTreeViewChildNodes(TreeNodeCollection parent_nodes, XmlNode xml_node)
{
    <span style="color: green;">// Make the new TreeView node. </span>TreeNode new_node = <span style="color: blue;">new </span>TreeNode(xml_node.Attributes[<span style="color: #a31515;">"name"</span>].Value);
    new_node.Value = xml_node.Attributes[<span style="color: #a31515;">"id"</span>].Value;
    new_node.NavigateUrl = xml_node.Attributes[<span style="color: #a31515;">"link"</span>].Value;
    parent_nodes.Add(new_node);

    <span style="color: blue;">foreach </span>(XmlNode child_node <span style="color: blue;">in </span>xml_node.ChildNodes)
    {
        <span style="color: green;">// Recursively make this node's descendants. </span>AddTreeViewChildNodes(new_node.ChildNodes, child_node);
    }
}</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmssource.co.uk/blog/customise-eviblog-for-sitecore/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

