<?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>LegHumped.com &#187; ASP.NET &#187; Leghumped</title>
	<atom:link href="http://www.leghumped.com/blog/category/programming/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leghumped.com/blog</link>
	<description>Coding snippets, tutorials and procrastinations about C#, Java and Linux.</description>
	<lastBuildDate>Wed, 11 Jan 2012 20:15:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Internal Subnav with BlogEngine.NET</title>
		<link>http://www.leghumped.com/blog/2012/01/03/internal-subnav-with-blogengine-net/</link>
		<comments>http://www.leghumped.com/blog/2012/01/03/internal-subnav-with-blogengine-net/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 15:15:39 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[blogengine.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=479</guid>
		<description><![CDATA[One of the great ASP.NET web apps I&#8217;ve started using is BlogEngine.NET, a fairly simple yet powerful CMS. While it handles basic CMS type functionality without problems, there are something which it doesn&#8217;t make particularly easy, such as displaying navigation trees. This can be largely overcome by extending some of the controls which BlogEngine ships [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great ASP.NET web apps I&#8217;ve started using is <a href="http://blogengine.codeplex.com/">BlogEngine.NET</a>, a fairly simple yet powerful CMS. While it handles basic CMS type functionality without problems, there are something which it doesn&#8217;t make particularly easy, such as displaying navigation trees.</p>
<p>This can be largely overcome by extending some of the controls which BlogEngine ships with, such as the post list. I changed this to display a list of sub pages for the current page. Once you set a page&#8217;s parent page, the subnav is rendered on the masterpage.</p>
<p><span id="more-479"></span></p>
<p>We just need one control on <em>page.aspx</em> and some code to bind it in the code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;blog:PageList runat=&quot;server&quot; ID=&quot;pageList&quot; /&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> ServePage<span style="color: #008000;">&#40;</span>Guid id<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
 	<span style="color: #008000;">...</span>
  	<span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>pg<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> Guid<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// root page</span>
            pageList<span style="color: #008000;">.</span><span style="color: #0000FF;">RootPageID</span> <span style="color: #008000;">=</span> id<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// sub page of root level page</span>
            pageList<span style="color: #008000;">.</span><span style="color: #0000FF;">RootPageID</span> <span style="color: #008000;">=</span> pg<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Out of the box, the html for the tree is generated once which won&#8217;t work if it&#8217;s different for every page, so you&#8217;ll also need to modify <em>PageList.cs</em> in the <em>~/App_Code/Controls</em> folder. I kept the caching and replaced it with a dictionary for each page to map between page ID and HTML for the page list.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"> <span style="color: #0600FF; font-weight: bold;">static</span> PageList<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Saved</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>sender, args<span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> PageList<span style="color: #008000;">.</span><span style="color: #0000FF;">ClearCachedHtml</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            ClearCachedHtml<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> ClearCachedHtml<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PageList&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//We also need a few more properties:</span>
	<span style="color: #008080;">#region Properties</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> Dictionary<span style="color: #008000;">&lt;</span>Guid,<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> HtmlDictionary
        <span style="color: #008000;">&#123;</span>
            get
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">const</span> <span style="color: #6666cc; font-weight: bold;">string</span> cacheKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;pageListDict&quot;</span><span style="color: #008000;">;</span>
                var htmlDict <span style="color: #008000;">=</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">&#91;</span>cacheKey<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> Dictionary<span style="color: #008000;">&lt;</span>Guid, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>htmlDict <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    htmlDict <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span>Guid, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">&#91;</span>cacheKey<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> htmlDict<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> htmlDict<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetPageListForPage<span style="color: #008000;">&#40;</span>Guid pageId<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">string</span> html<span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>HtmlDictionary<span style="color: #008000;">.</span><span style="color: #0000FF;">TryGetValue</span><span style="color: #008000;">&#40;</span>pageId, <span style="color: #0600FF; font-weight: bold;">out</span> html<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                html <span style="color: #008000;">=</span> BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Utils</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RenderControl</span><span style="color: #008000;">&#40;</span>BindPages<span style="color: #008000;">&#40;</span>pageId<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                HtmlDictionary<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>pageId, html<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> html<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> Guid<span style="color: #008000;">?</span> RootPageID
        <span style="color: #008000;">&#123;</span>
            get
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RootPageID&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span>
                           <span style="color: #008000;">?</span> <span style="color: #008000;">&#40;</span>Guid<span style="color: #008000;">?</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">null</span>
                           <span style="color: #008000;">:</span> <span style="color: #008000;">new</span> Guid<span style="color: #008000;">&#40;</span>Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span>ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RootPageID&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> ViewState<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RootPageID&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
        <span style="color: #008080;">#endregion</span></pre></div></div>

<p>The root page ID specifies the parent pages whose children to render.</p>
<p>The final step is some changes to the private methods which render the lists:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> RenderControl<span style="color: #008000;">&#40;</span>HtmlTextWriter writer<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            writer<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>GetPageListForPage<span style="color: #008000;">&#40;</span>RootPageID<span style="color: #008000;">??</span>Guid<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
           <span style="color: #008080; font-style: italic;">// writer.Write(Environment.NewLine);</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> HtmlGenericControl BindPages<span style="color: #008000;">&#40;</span>Guid<span style="color: #008000;">?</span> pageId<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//HtmlGenericControl div = new HtmlGenericControl(&quot;div&quot;);</span>
            var div <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ul&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            div<span style="color: #008000;">.</span><span style="color: #0000FF;">Attributes</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>,<span style="color: #666666;">&quot;softwareList&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            div<span style="color: #008000;">.</span><span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;pagelist&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span> page <span style="color: #0600FF; font-weight: bold;">in</span> BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Pages</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>page<span style="color: #008000;">.</span><span style="color: #0000FF;">ShowInList</span> <span style="color: #008000;">&amp;&amp;</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">IsVisibleToPublic</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>pageId<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span> <span style="color: #008000;">&amp;&amp;</span> pageId<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span> <span style="color: #008000;">==</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>pageId<span style="color: #008000;">.</span><span style="color: #0000FF;">HasValue</span> <span style="color: #008000;">&amp;&amp;</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;00000000-0000-0000-0000-000000000000&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    div<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>BuildSubPages<span style="color: #008000;">&#40;</span>div, page<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> div<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> HtmlGenericControl BuildSubPages<span style="color: #008000;">&#40;</span>Control parentElement, BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span> page<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">&gt;</span> subPages <span style="color: #008000;">=</span> BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Pages</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> p<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToList</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            HtmlGenericControl li <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            HtmlAnchor anc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlAnchor<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            anc<span style="color: #008000;">.</span><span style="color: #0000FF;">HRef</span> <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">RelativeLink</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            anc<span style="color: #008000;">.</span><span style="color: #0000FF;">InnerHtml</span> <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span><span style="color: #008000;">;</span>
            anc<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span> <span style="color: #008000;">=</span> page<span style="color: #008000;">.</span><span style="color: #0000FF;">Description</span><span style="color: #008000;">;</span>
            li<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>anc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>subPages<span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                HtmlGenericControl ul <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ul&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                li<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>ul<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>BlogEngine<span style="color: #008000;">.</span><span style="color: #0000FF;">Core</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span> p <span style="color: #0600FF; font-weight: bold;">in</span> subPages<span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    HtmlGenericControl innerLi <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    ul<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>BuildSubPages<span style="color: #008000;">&#40;</span>innerLi, p<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            parentElement<span style="color: #008000;">.</span><span style="color: #0000FF;">Controls</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>li<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> li<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></div></div>

<p>Though this should work for unlimited navigation levels, I&#8217;ve only tested it with two. Ideally, <a href="http://www.umbraco.com/">Umbraco</a> is suited excellently to this due to it&#8217;s ability to use XSLT for jobs like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2012/01/03/internal-subnav-with-blogengine-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DevExpress Scheduler: ID of Repeating Appointment</title>
		<link>http://www.leghumped.com/blog/2011/10/01/devexpress-scheduler-id-of-repeating-appointment/</link>
		<comments>http://www.leghumped.com/blog/2011/10/01/devexpress-scheduler-id-of-repeating-appointment/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 17:31:21 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=454</guid>
		<description><![CDATA[Since I started using the DevExpress Scheduler a few weeks back I&#8217;ve found a few limitations in the 2011 version. The killer for me was the lack of appointment IDs for recurring appointments. After hunting around trying every suggested method from DevExpress, I found a support ticket from another developer having the same problem. Using [...]]]></description>
			<content:encoded><![CDATA[<p>Since I started using the DevExpress Scheduler a few weeks back I&#8217;ve found a few limitations in the 2011 version. The killer for me was the lack of appointment IDs for recurring appointments.<br />
<span id="more-454"></span><br />
After hunting around trying every suggested method from DevExpress, I found <a href="http://www.devexpress.com/Support/Center/p/Q261153.aspx">a support ticket from another developer</a> having the same problem.</p>
<p>Using the same kind of method I wrote the following core (pretty horrible) to do the job.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dx:ASPxScheduler</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span>...</span>
<span style="color: #009900;">		...</span>
<span style="color: #009900;">		<span style="color: #000000; font-weight: bold;">&lt;ClientSideEvents</span> <span style="color: #000066;">AppointmentsSelectionChanged</span>=<span style="color: #ff0000;">&quot;function(s, e) { OnAppointmentsSelectionChanged(s, e.appointmentIds);}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dx:ASPxScheduler<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:HiddenField</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;appointmentId&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            function OnAppointmentsSelectionChanged(s, appointmentIds) {
                $('#<span style="color: #009900;">&lt;%= appointmentId.ClientID %<span style="color: #000000; font-weight: bold;">&gt;</span></span>').val(appointmentIds);
            }
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This lets you grab the value from the code-behind (in my case by hooking the <em>ASPxScheduler1_PopupMenuShowing</em> event).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> ASPxScheduler1_PopupMenuShowing<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, PopupMenuShowingEventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        ASPxSchedulerPopupMenu menu <span style="color: #008000;">=</span> e<span style="color: #008000;">.</span><span style="color: #0000FF;">Menu</span><span style="color: #008000;">;</span>
        <span style="color: #008080; font-style: italic;">// Check whether an empty cell is clicked rather than an appointment.</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>menu<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Equals</span><span style="color: #008000;">&#40;</span>SchedulerMenuItemId<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultMenu</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		var rawSelectedBookingId <span style="color: #008000;">=</span> appointmentId<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// if it's recurring, you get something like 12_0</span>
                var selectedBookingId <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrWhiteSpace</span><span style="color: #008000;">&#40;</span>rawSelectedBookingId<span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span> <span style="color: #008000;">:</span> Convert<span style="color: #008000;">.</span><span style="color: #0000FF;">ToInt32</span><span style="color: #008000;">&#40;</span>rawSelectedBookingId<span style="color: #008000;">.</span><span style="color: #0000FF;">Split</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span><span style="color: #666666;">'_'</span><span style="color: #008000;">&#125;</span>, StringSplitOptions<span style="color: #008000;">.</span><span style="color: #0000FF;">RemoveEmptyEntries</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FirstOrDefault</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <em>selectedBookingId</em> in my case, is the ID of the database object for the user&#8217;s right click selection</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/10/01/devexpress-scheduler-id-of-repeating-appointment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Geocoding for Zip Code Lookups</title>
		<link>http://www.leghumped.com/blog/2011/05/22/jquery-geocoding-for-zip-code-lookups/</link>
		<comments>http://www.leghumped.com/blog/2011/05/22/jquery-geocoding-for-zip-code-lookups/#comments</comments>
		<pubDate>Sun, 22 May 2011 15:43:50 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[geocoding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=444</guid>
		<description><![CDATA[Forms which need a user&#8217;s address, or even just their country can be tedious to fill out, especially if you need to collect latitude and longitude. Yahoo&#8217;s Geolocation API can simplify the process by looking up latitude, longitude and country from a postal/zip code. The function below takes five arguments and uses jQuery to add [...]]]></description>
			<content:encoded><![CDATA[<p>Forms which need a user&#8217;s address, or even just their country can be tedious to fill out, especially if you need to collect latitude and longitude. Yahoo&#8217;s Geolocation API can simplify the process by looking up latitude, longitude and country from a postal/zip code. The function below takes five arguments and uses jQuery to add a click handler. When the button is clicked, an AJAX request is sent to the Yahoo geolocation API via jQuery, the the resulting XML is parsed and the form fields are populated. </p>
<p>This has the benefit of needing just one piece of data (postcode) instead of four. The one problem with this is that the <a href="https://developer.mozilla.org/en/Same_origin_policy_for_JavaScript">same origin policy</a> prevent making AJAX calls to a separate domain. Unfortunately, this means you need an intermediate web service hosted on the same domain as the page which passes on the request. This just needs to return a URL via cURL (PHP) or WebClient (ASP.NET).</p>
<p>Then in JavaScript, the result can be parsed from the returned XML (unfortunately, Yahoo&#8217;s API doesn&#8217;t currently support JSON).<br />
<span id="more-444"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #003366; font-weight: bold;">function</span> addGLookupPostCodeListener<span style="color: #009900;">&#40;</span>searchButtonId<span style="color: #339933;">,</span> postCodeFieldId<span style="color: #339933;">,</span> countryFieldId<span style="color: #339933;">,</span> txtLatitudeId<span style="color: #339933;">,</span> txtLongitudeId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #003366; font-weight: bold;">var</span> searchButton <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> searchButtonId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    searchButton.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        <span style="color: #003366; font-weight: bold;">var</span> thePostCode <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> postCodeFieldId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>thePostCode <span style="color: #339933;">===</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>
	            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
	            $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>type<span style="color: #339933;">:</span> <span style="color: #3366CC;">'POST'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'/API.asmx/LookupPostcode'</span><span style="color: #339933;">,</span>  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span> dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'xml'</span><span style="color: #339933;">,</span> data<span style="color: #339933;">:</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> postCode<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">encodeURI</span><span style="color: #009900;">&#40;</span>thePostCode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> xml <span style="color: #339933;">=</span> response<span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $xml <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>xml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> haveNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $country <span style="color: #339933;">=</span> $xml.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Country&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$country <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// populat country if it exists</span>
	                        haveNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">var</span> txtCountry <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> countryFieldId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>$country.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	                            <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'GB'</span><span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">// the API returns GB as the country code which is no good </span>
	                            txtCountry.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'United Kingdom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
	                            txtCountry.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$country.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	                    <span style="color: #009900;">&#125;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $latitude <span style="color: #339933;">=</span> $xml.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Latitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #003366; font-weight: bold;">var</span> $longitude <span style="color: #339933;">=</span> $xml.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Longitude&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$latitude <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">&amp;&amp;</span> $longitude <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// populate lat/long if they exist</span>
	                        haveNodes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">var</span> txtLatitude <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> txtLatitudeId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        <span style="color: #003366; font-weight: bold;">var</span> txtLongitude <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span> <span style="color: #339933;">+</span> txtLongitudeId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        txtLatitude.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$latitude.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                        txtLongitude.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>$longitude.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #009900;">&#125;</span>
	                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>haveNodes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">// if no nodes (due to invalid response or no data), show a message</span>
	                        searchButton.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span class=&quot;block&quot;&gt;Address not found&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	                    <span style="color: #009900;">&#125;</span>
	                <span style="color: #009900;">&#125;</span>
	            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2011/05/22/jquery-geocoding-for-zip-code-lookups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Draggable Resizable Div With jQuery</title>
		<link>http://www.leghumped.com/blog/2010/12/22/draggable-resizable-div-with-jquery/</link>
		<comments>http://www.leghumped.com/blog/2010/12/22/draggable-resizable-div-with-jquery/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 16:30:01 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=426</guid>
		<description><![CDATA[I&#8217;m a big fan of jQuery, but so far I&#8217;ve only used it for effects. I recently did a draggable, resizable football shirt customization widget for an ASP.NET site and ran into some problems on the way. It&#8217;s not quite as simple as just calling $(&#8216;#ele&#8217;).draggable().resizable(); due to a jQuery bug, so a bit of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of jQuery, but so far I&#8217;ve only used it for effects. I recently did a draggable, resizable football shirt customization widget for an ASP.NET site and ran into some problems on the way. It&#8217;s not quite as simple as just calling $(&#8216;#ele&#8217;).draggable().resizable(); due to a jQuery bug, so a bit of hackery is needed.</p>
<p>First, the controls to display the image which the user uploads.</p>
<p><span id="more-426"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:Panel</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;pnlUserImageDragContainer&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">CssClass</span>=<span style="color: #ff0000;">&quot;userImageContainer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:Panel</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;pnlUserImageContainer&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">CssClass</span>=<span style="color: #ff0000;">&quot;userImageResizeContainer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;asp:Image</span> <span style="color: #000066;">ID</span>=<span style="color: #ff0000;">&quot;imgUserImage&quot;</span> <span style="color: #000066;">runat</span>=<span style="color: #ff0000;">&quot;server&quot;</span> <span style="color: #000066;">CssClass</span>=<span style="color: #ff0000;">&quot;userImage&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/asp:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/asp:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So there&#8217;s a draggable panel, a resizable panel inside it and an image which scales inside that.</p>
<p><!-- more --></p>
<p>The JavaScript is registered when the page loads. When the image is dragged/resized, jQuery&#8217;s functions are used to grab the sizes of the panels and store them in textboxes on the form.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    StringBuilder jQueryBuffer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> StringBuilder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}')&quot;</span><span style="color: #339933;">,</span> pnlUserImageContainer.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;.resizable({  
                stop: function(e, ui) {
               		    //store the position of the resized image for later
                        var imageDiv = &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}'); &quot;</span><span style="color: #339933;">,</span> pnlUserImageContainer.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
                        &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}').val(imageDiv.width()); &quot;</span><span style="color: #339933;">,</span> txtCustomImageWidth.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
                        &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}').val(imageDiv.height()); &quot;</span><span style="color: #339933;">,</span> txtCustomImageHeight.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
&nbsp;
            		    // turn the background off
                        imageDiv.css({ border: '1px solid transparent', background: 'none' });
                },
            }).parent().draggable({ // the parent is the outer panel (the drag container)
                    stop: function(e, ui) {
                        var containerPos = &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}').position(); &quot;</span><span style="color: #339933;">,</span> pnlUserImageDragContainer.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
                        &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}').val(containerPos.top); &quot;</span><span style="color: #339933;">,</span> txtCustomImageTop.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
&nbsp;
                        // the position of the image inside the container (depends on the size as the inner container is centered)
                        var elementPos = &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}').position(); &quot;</span><span style="color: #339933;">,</span> pnlUserImageContainer.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
                        &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}').val(containerPos.left + elementPos.left); &quot;</span><span style="color: #339933;">,</span> txtCustomImageLeft.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
&nbsp;
                    },
                    &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; zIndex: '11', &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
            }).mouseover(function() { 
                // this is just eye candy for an overlay when the mouse moves over the container
                var imageDiv = &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}'); &quot;</span><span style="color: #339933;">,</span> pnlUserImageContainer.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
                imageDiv.css({ border: '1px solid #f00', background: 'url(&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span>ResolveUrl<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;~/images/dragoverlay.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;) repeat 0 0' })
            }).mouseout(function() { 
                // remove the eye candy onMouseOut
                var imageDiv = &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AppendFormat</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;$('#{0}'); &quot;</span><span style="color: #339933;">,</span> pnlUserImageContainer.<span style="color: #660066;">ClientID</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Append</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #3366CC;">&quot;
                imageDiv.css({ border: '1px solid transparent', background: 'none' });
            });</span></pre></div></div>

<p>The controls are ASP.NET controls not HTML elements because I access them from code, fundamentally it&#8217;s the JavaScript doing the legwork.</p>
<p>This lets a user drag the image around and resize it within the containing div.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/12/22/draggable-resizable-div-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kentico: Global Content Sections</title>
		<link>http://www.leghumped.com/blog/2010/11/17/kentico-global-content-sections/</link>
		<comments>http://www.leghumped.com/blog/2010/11/17/kentico-global-content-sections/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 16:19:16 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[kentico]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=420</guid>
		<description><![CDATA[I&#8217;ve been working with Kentico recently and I needed a section of text on the MasterPage ediatble by the admin, of which there was only one instance. The problem is, if you use a &#60;cms:CMSEditableRegion&#62;, you end up with one instance on every page as the property is stored on the page. In Umbraco you&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working with Kentico recently and I needed a section of text on the MasterPage ediatble by the admin, of which there was only one instance. The problem is, if you use a <em>&lt;cms:CMSEditableRegion&gt;</em>, you end up with one instance on every page as the property is stored on the page. In Umbraco you&#8217;d probably use a either page in the CMS specifically to hold the text or a new property on the root node.</p>
<p><span id="more-420"></span></p>
<p>In the end, I ended up creating a page in Kentico which was only used to hold the text for this section and using a literal on the MasterPage. You can load the page content with:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">PageInfo contactInfo <span style="color: #008000;">=</span> PageInfoProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPageInfo</span><span style="color: #008000;">&#40;</span>CMSContext<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentSiteName</span>, <span style="color: #666666;">&quot;/&quot;</span>, <span style="color: #666666;">&quot;en-GB&quot;</span>, <span style="color: #666666;">&quot;/Global-Sections/Contact-Info&quot;</span>, <span style="color: #FF0000;">369</span>, <span style="color: #0600FF; font-weight: bold;">true</span>, CMS<span style="color: #008000;">.</span><span style="color: #0000FF;">DataEngine</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ConnectionHelper</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetConnection</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
litContactInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> contactInfo<span style="color: #008000;">.</span><span style="color: #0000FF;">EditableRegions</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;contentpanel&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/11/17/kentico-global-content-sections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subscriptions with Paypal Express Checkout</title>
		<link>http://www.leghumped.com/blog/2010/11/09/subscriptions-paypal-express-checkout/</link>
		<comments>http://www.leghumped.com/blog/2010/11/09/subscriptions-paypal-express-checkout/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 11:26:03 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=417</guid>
		<description><![CDATA[The .NET documentation seems fairly sparese with examples for working PayPal API calls, so here&#8217;s my contribution. The CancelSubscription method may not be 100% working, but I believe the problem is with my Paypal account. You also need paypal_base.dll from the SDK. The methods are: SetExpressCheckout &#8211; Sets the token and returns a URL to [...]]]></description>
			<content:encoded><![CDATA[<p>The .NET documentation seems fairly sparese with examples for working PayPal API calls, so here&#8217;s my contribution. The CancelSubscription method may not be 100% working, but I believe the problem is with my Paypal account. You also need paypal_base.dll from the SDK. The methods are:</p>
<ul>
<li><strong>SetExpressCheckout</strong> &#8211; Sets the token and returns a URL to which to redirect the user.</li>
<li><strong>GetExpressCheckoutDetails</strong> &#8211; Checks whether a token is valid on returning from PayPal</li>
<li><strong>DoExpressCheckout</strong> &#8211; Initiates a payment</li>
<li><strong>CreateRecurringPaymentsProfileCode</strong> &#8211; Creates a subscription with an optional initial amount</li>
<li><strong>CancelSubscription</strong> &#8211; Cancels a subscription</li>
</ul>
<p><span id="more-417"></span></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// ShortcutExpressCheckout: The method that calls SetExpressCheckout API</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> SetExpressCheckout<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span> amt, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> token, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> retMsg<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> host <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;www.paypal.com&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bSandbox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        pendpointurl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;https://api-3t.sandbox.paypal.com/nvp&quot;</span><span style="color: #008000;">;</span>
        host <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;www.sandbox.paypal.com&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> baseUrl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://&quot;</span> <span style="color: #008000;">+</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Request</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Url</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Authority</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> returnUrlParts <span style="color: #008000;">=</span> WebConfigurationManager<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;PaypalReturnUrl&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
             cancelUrlParts <span style="color: #008000;">=</span> WebConfigurationManager<span style="color: #008000;">.</span><span style="color: #0000FF;">AppSettings</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;PaypalCancelUrl&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
    NVPCodec encoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;METHOD&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SetExpressCheckout&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;RETURNURL&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> returnURL<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;CANCELURL&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> cancelURL<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;AMT&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> amt<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;LOCALECODE&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;GB&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;CURRENCYCODE&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;GBP&quot;</span><span style="color: #008000;">;</span> 
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;VERSION&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;64.0&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;NOSHIPPING&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;1&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_BILLINGTYPE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;RecurringPayments&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_BILLINGAGREEMENTDESCRIPTION0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SubscriptionForGenuineBusiness&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> pStrrequestforNvp <span style="color: #008000;">=</span> encoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Encode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> pStresponsenvp <span style="color: #008000;">=</span> HttpCall<span style="color: #008000;">&#40;</span>pStrrequestforNvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    NVPCodec decoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    decoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Decode</span><span style="color: #008000;">&#40;</span>pStresponsenvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> strAck <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ACK&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;success&quot;</span> <span style="color: #008000;">||</span> strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;successwithwarning&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        token <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;TOKEN&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #6666cc; font-weight: bold;">string</span> ECURL <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;https://&quot;</span> <span style="color: #008000;">+</span> host <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;/cgi-bin/webscr?cmd=_express-checkout&quot;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;token=&quot;</span> <span style="color: #008000;">+</span> token<span style="color: #008000;">;</span>
&nbsp;
        retMsg <span style="color: #008000;">=</span> ECURL<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
        retMsg <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ErrorCode=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_ERRORCODE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_SHORTMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc2=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_LONGMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">///  Checks whether the user has a valid token.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Whether or not the action suceeded.&lt;/returns&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> GetExpressCheckoutDetails<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> token, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> PayerId, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> retMsg<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bSandbox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        pendpointurl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;https://api-3t.sandbox.paypal.com/nvp&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    NVPCodec encoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;METHOD&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;GetExpressCheckoutDetails&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;TOKEN&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> token<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;VERSION&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;64.0&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> pStrrequestforNvp <span style="color: #008000;">=</span> encoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Encode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> pStresponsenvp <span style="color: #008000;">=</span> HttpCall<span style="color: #008000;">&#40;</span>pStrrequestforNvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    NVPCodec decoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    decoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Decode</span><span style="color: #008000;">&#40;</span>pStresponsenvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> strAck <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ACK&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;success&quot;</span> <span style="color: #008000;">||</span> strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;successwithwarning&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
        retMsg <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ErrorCode=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_ERRORCODE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_SHORTMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc2=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_LONGMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">///Starts payment for a set amount</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;token&quot;&gt;&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param ref name=&quot;retMsg&quot;&gt;&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Whether or not the action suceeded.&lt;/returns&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> DoExpressCheckout<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> token, <span style="color: #6666cc; font-weight: bold;">string</span> PayerId, <span style="color: #6666cc; font-weight: bold;">string</span> amount, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> retMsg<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bSandbox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        pendpointurl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;https://api-3t.sandbox.paypal.com/nvp&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    NVPCodec encoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;METHOD&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;DoExpressCheckoutPayment&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;TOKEN&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> token<span style="color: #008000;">;</span>
     encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;VERSION&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;64.0&quot;</span><span style="color: #008000;">;</span>
     encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;PAYERID&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">=</span>PayerId<span style="color: #008000;">;</span>
     encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;PAYMENTACTION&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Sale&quot;</span><span style="color: #008000;">;</span>
     encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;AMT&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">=</span>amount<span style="color: #008000;">;</span>
     encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;CURRENCYCODE&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;GBP&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> pStrrequestforNvp <span style="color: #008000;">=</span> encoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Encode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> pStresponsenvp <span style="color: #008000;">=</span> HttpCall<span style="color: #008000;">&#40;</span>pStrrequestforNvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    NVPCodec decoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    decoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Decode</span><span style="color: #008000;">&#40;</span>pStresponsenvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> strAck <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ACK&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToLower</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;success&quot;</span> <span style="color: #008000;">||</span> strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;successwithwarning&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
        retMsg <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ErrorCode=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_ERRORCODE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_SHORTMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc2=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_LONGMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Create a PayPal subscription.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;retMsg&quot;&gt;Will contain either an error message or the Paypal ProfileID&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Whether or not the action suceeded. &lt;paramref name=&quot;retMsg&quot;/&gt; will contain either an error message or the Paypal ProfileID&lt;/returns&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CreateRecurringPaymentsProfileCode<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> token, <span style="color: #6666cc; font-weight: bold;">string</span> amount, DateTime profileDate, <span style="color: #6666cc; font-weight: bold;">string</span> billingPeriod, <span style="color: #6666cc; font-weight: bold;">string</span> billingFrequency, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> retMsg<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    NVPCallerServices caller <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCallerServices<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    IAPIProfile profile <span style="color: #008000;">=</span> ProfileFactory<span style="color: #008000;">.</span><span style="color: #0000FF;">createSignatureAPIProfile</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">APIUsername</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">APIUsername</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">APIPassword</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">APIPassword</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">APISignature</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">APISignature</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">Environment</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;sandbox&quot;</span><span style="color: #008000;">;</span>
    caller<span style="color: #008000;">.</span><span style="color: #0000FF;">APIProfile</span> <span style="color: #008000;">=</span> profile<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> host <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;www.paypal.com&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bSandbox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        pendpointurl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;https://api-3t.sandbox.paypal.com/nvp&quot;</span><span style="color: #008000;">;</span>
        host <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;www.sandbox.paypal.com&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    NVPCodec encoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;VERSION&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;64.0&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;METHOD&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;CreateRecurringPaymentsProfile&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;TOKEN&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> token<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;AMT&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> amount<span style="color: #008000;">;</span>
    <span style="color: #008080; font-style: italic;">//encoder[&quot;CURRENCYCODE&quot;] = &quot;GBP&quot;;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;PROFILESTARTDATE&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> profileDate<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;yyyy-MM-ddT00:00:00&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>   <span style="color: #008080; font-style: italic;">//Date format from server expects Ex: 2006-9-6T0:0:0</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;BILLINGPERIOD&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> billingPeriod<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;BILLINGFREQUENCY&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> billingFrequency<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;DESC&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;SubscriptionForGenuineBusiness&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;INITAMT&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> amount<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> pStrrequestforNvp <span style="color: #008000;">=</span> encoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Encode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    caller <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCallerServices<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    profile <span style="color: #008000;">=</span> ProfileFactory<span style="color: #008000;">.</span><span style="color: #0000FF;">createSignatureAPIProfile</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">APIUsername</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">APIUsername</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">APIPassword</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">APIPassword</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">APISignature</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">APISignature</span><span style="color: #008000;">;</span>
    profile<span style="color: #008000;">.</span><span style="color: #0000FF;">Environment</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;sandbox&quot;</span><span style="color: #008000;">;</span>
    caller<span style="color: #008000;">.</span><span style="color: #0000FF;">APIProfile</span> <span style="color: #008000;">=</span> profile<span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> pStresponsenvp <span style="color: #008000;">=</span> caller<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>pStrrequestforNvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    NVPCodec decoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    decoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Decode</span><span style="color: #008000;">&#40;</span>pStresponsenvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> strAck <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ACK&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">bool</span> success <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Success&quot;</span> <span style="color: #008000;">||</span> strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;SuccessWithWarning&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        success <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// check decoder[&quot;result&quot;]</span>
        retMsg <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ProfileID&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
        success <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        retMsg <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ErrorCode=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_ERRORCODE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_SHORTMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&amp;&quot;</span> <span style="color: #008000;">+</span>
            <span style="color: #666666;">&quot;Desc2=&quot;</span> <span style="color: #008000;">+</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;L_LONGMESSAGE0&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> success<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Cancels a subscription</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Whether or not the action suceeded.&lt;/returns&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CancelSubscription<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> profileId, <span style="color: #0600FF; font-weight: bold;">ref</span> <span style="color: #6666cc; font-weight: bold;">string</span> retMsg<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>bSandbox<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        pendpointurl <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;https://api-3t.sandbox.paypal.com/nvp&quot;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    NVPCodec encoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;METHOD&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;ManageRecurringPaymentsProfileStatus&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;PROFILEID&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> profileId<span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;NOTE&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Subscription cancelled&quot;</span><span style="color: #008000;">;</span>
    encoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ACTION&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Cancel&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> pStrrequestforNvp <span style="color: #008000;">=</span> encoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Encode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> pStresponsenvp <span style="color: #008000;">=</span> HttpCall<span style="color: #008000;">&#40;</span>pStrrequestforNvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    NVPCodec decoder <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NVPCodec<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    decoder<span style="color: #008000;">.</span><span style="color: #0000FF;">Decode</span><span style="color: #008000;">&#40;</span>pStresponsenvp<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> strAck <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;ACK&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">&#40;</span>strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;success&quot;</span> <span style="color: #008000;">||</span> strAck <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;successwithwarning&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span> <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008000;">&#123;</span>
        retMsg <span style="color: #008000;">=</span> decoder<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">??</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/11/09/subscriptions-paypal-express-checkout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blog4Umbraco and AJAX Comments</title>
		<link>http://www.leghumped.com/blog/2010/10/19/blog4umbraco-and-ajax-comments/</link>
		<comments>http://www.leghumped.com/blog/2010/10/19/blog4umbraco-and-ajax-comments/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 12:58:48 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[umbraco]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=413</guid>
		<description><![CDATA[Blog4Umbraco is probably one of the only ways to get a decent blog for Umbraco. I had a site which used some other JavaScript and lots of jQuery UI which I neeed to integrate, but as soon as I applied my MasterPage, the AJAX comment form broke. A quick search shows a few people have [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog4umbraco.codeplex.com/">Blog4Umbraco</a> is probably one of the only ways to get a decent blog for Umbraco. I had a site which used some other JavaScript and lots of jQuery UI which I neeed to integrate, but as soon as I applied my MasterPage, the AJAX comment form broke. A quick search shows a few people have had this problem, so I want to post my fix. It&#8217;s almost embarrassingly simple</p>
<p><span id="more-413"></span></p>
<p>In <em>/scripts/Blog4Umbraco/blog4umbraco.js</em>, there&#8217;s a SetGravatar method, which makes what as far as I can tell is an invalid request. Instead of calling <em>&#8220;/base/blog4umbraco/GetGravatarImage/&#8221; + s_email + &#8220;/80.aspx&#8221;</em>, changing the path to <em>&#8220;/base/blog4umbraco/GetGravatarImage/&#8221; + s_email + &#8220;.aspx&#8221;</em> fix the problem in my case. Ie:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SetGravatar<span style="color: #009900;">&#40;</span>s_imgId<span style="color: #339933;">,</span> s_email<span style="color: #339933;">,</span> i_size<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/base/blog4umbraco/GetGravatarImage/&quot;</span> <span style="color: #339933;">+</span> s_email <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.aspx&quot;</span><span style="color: #339933;">,</span>
       <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> avatar <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> s_imgId <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              <span style="color: #003366; font-weight: bold;">var</span> src <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://www.gravatar.com/avatar/&quot;</span> <span style="color: #339933;">+</span> data <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;?s=&quot;</span> <span style="color: #339933;">+</span> i_size<span style="color: #339933;">;</span>
              avatar.<span style="color: #660066;">src</span><span style="color: #009900;">&#40;</span>src<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
              avatar.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
       <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Maybe it&#8217;ll work for you too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/10/19/blog4umbraco-and-ajax-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Umbraco: Breadcrumb Trail</title>
		<link>http://www.leghumped.com/blog/2010/05/30/umbraco-breadcrumb-trail/</link>
		<comments>http://www.leghumped.com/blog/2010/05/30/umbraco-breadcrumb-trail/#comments</comments>
		<pubDate>Sun, 30 May 2010 14:00:18 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[umbraco]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=410</guid>
		<description><![CDATA[I&#8217;ve been using Umbraco recently, and always find it hard to find XSL templates or spend hours tweaking one when countless other people must have done the same thing, but not published the finished stylesheet. Below is a navigation breadcrumb template which prints a trail to the current page, starting with level 1. &#60;?xml version=&#34;1.0&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Umbraco recently, and always find it hard to find XSL templates or spend hours tweaking one when countless other people must have done the same thing, but not published the finished stylesheet.</p>
<p>Below is a navigation breadcrumb template which prints a trail to the current page, starting with level 1.<br />
<span id="more-410"></span></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE xsl:Stylesheet [</span>
<span style="color: #00bbdd;">	&lt;!ENTITY amp &quot;&amp;#38;&quot;&gt;</span>
    <span style="color: #009900;">&lt;!ENTITY nbsp <span style="color: #ff0000;">&quot;&amp;#x00A0;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;">&lt;!ENTITY raquo <span style="color: #ff0000;">&quot;&amp;#187;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
]&gt;
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span></span>
<span style="color: #009900;">	<span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:msxml</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xslt&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:msxsl</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xslt&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:umbraco.library</span>=<span style="color: #ff0000;">&quot;urn:umbraco.library&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">exclude-result-prefixes</span>=<span style="color: #ff0000;">&quot;msxml umbraco.library&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">omit-xml-declaration</span>=<span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;currentPage&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;breadcrumb&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$currentPage/ancestor::node [string(data [@alias='umbracoNaviHide']) != '1']&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;{umbraco.library:NiceUrl(@id)}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@nodeName&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@nodeName&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;@level != 0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #ddbb00;">&amp;raquo;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$currentPage/@nodeName&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/05/30/umbraco-breadcrumb-trail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework in Mednium Trust</title>
		<link>http://www.leghumped.com/blog/2010/03/08/entity-framework-in-mednium-trust/</link>
		<comments>http://www.leghumped.com/blog/2010/03/08/entity-framework-in-mednium-trust/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 18:47:56 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[entity framework]]></category>

		<guid isPermaLink="false">http://www.leghumped.com/blog/?p=403</guid>
		<description><![CDATA[ASP.NET and medium trust typically don&#8217;t get along well once you start using third party libraries. It really should, however, be easier to get the Entity Framework working on medium trust, and this had me baffled for a few hours trying to split the EDMX file and other fruitless solutions. To get this working I [...]]]></description>
			<content:encoded><![CDATA[<p>ASP.NET and medium trust typically don&#8217;t get along well once you start using third party libraries. It really should, however, be easier to get the Entity Framework working on medium trust, and this had me baffled for a few hours trying to split the EDMX file and other fruitless solutions.</p>
<p>To get this working I needed to:</p>
<ol>
<li>Move the EDMX to a separate assembly.</li>
<li>Set the EDMX metadata artifact processing to <em>&#8216;Embed in output assembly&#8217;</em>.</li>
<li>Add a reference in the site.</li>
<li>Change the connection string to

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ShopEntities&quot;</span> <span style="color: #000066;">connectionString</span>=<span style="color: #ff0000;">&quot;metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&amp;quot;Data Source=servername;Initial Catalog=dbname;User Id=username;Password=P@55word;MultipleActiveResultSets=True&amp;quot;&quot;</span> <span style="color: #000066;">providerName</span>=<span style="color: #ff0000;">&quot;System.Data.EntityClient&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

</li>
</ol>
<p>Which every guide claimed would work. There&#8217;s one more step if you have custom partial entity classes (in App_Code). If so, these also need to be moved to your output assembly, as you can&#8217;t split partial classes across assemblies. Lastly, change the namespace in your partial classes to the same as your output assembly, and everything should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2010/03/08/entity-framework-in-mednium-trust/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET: Remove from the cache using</title>
		<link>http://www.leghumped.com/blog/2009/07/25/asp-net-remove-from-the-cache-using/</link>
		<comments>http://www.leghumped.com/blog/2009/07/25/asp-net-remove-from-the-cache-using/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 10:09:50 +0000</pubDate>
		<dc:creator>Harry Jennerway</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://leghumped.com/blog/?p=360</guid>
		<description><![CDATA[<p>The Cache object in ASP.NET isn't like other collections, probably because it needs to be specialized so it doesn't make use of generics. Unfortunately, that makes it more difficult to work with. This small utility method removes an object from the cache by key using a predictate. You could easily modify it to compare either of the IDictionaryEnumerator's Key or Value properties.</p>
<pre lang="csharp">
/// <summary>
/// Removes an item from the cache using a Predictate to match the key.
/// </summary>
/// <param name="keyCriteria">The Predictate to use for each key to determine whether the entry should be removed.</param>
/// <summary>
/// Removes an item from the cache using a Predictate to match the key.
/// </summary>
/// <param name="keyCriteria">The Predictate to use for each key to determine whether the entry should be removed.</param>
</pre>]]></description>
			<content:encoded><![CDATA[<p>The Cache object in ASP.NET isn&#8217;t like other collections, probably because it needs to be specialized so it doesn&#8217;t make use of generics. Unfortunately, that makes it more difficult to work with. This small utility method removes an object from the cache by key using a predictate. You could easily modify it to compare either of the IDictionaryEnumerator&#8217;s Key or Value properties.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Removes an item from the cache using a Predictate to match the key.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;keyCriteria&quot;&gt;The Predictate to use for each key to determine whether the entry should be removed.&lt;/param&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// Removes an item from the cache using a Predictate to match the key.</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;keyCriteria&quot;&gt;The Predictate to use for each key to determine whether the entry should be removed.&lt;/param&gt;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RemoveFromCache<span style="color: #008000;">&#40;</span>Predicate<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> keyCriteria<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
	IDictionaryEnumerator enuma <span style="color: #008000;">=</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetEnumerator</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF; font-weight: bold;">while</span><span style="color: #008000;">&#40;</span>enuma<span style="color: #008000;">.</span><span style="color: #0000FF;">MoveNext</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>keyCriteria<span style="color: #008000;">&#40;</span>enuma<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
			HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Cache</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>enuma<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.leghumped.com/blog/2009/07/25/asp-net-remove-from-the-cache-using/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

