<?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:rssdatehelper="urn:rssdatehelper"><channel><title>BlogFodder</title><link>http://www.blogfodder.co.uk</link><pubDate>2012-01-21T08:39:14</pubDate><generator>umbraco</generator><description>General techie &amp; development ramblings, source code and random other things</description><language>en</language><item><title>Is Responsive Web Design A Fad?</title><link>http://www.blogfodder.co.uk/2012/1/21/is-responsive-web-design-a-fad</link><pubDate>Sat, 21 Jan 2012 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2012/1/21/is-responsive-web-design-a-fad</guid><description><![CDATA[ 
<p>Over the past few months I have been doing a lot of reading up
and watching of responsive web design tutorials.&nbsp; As I wanted
to implement the technique into a few of the sites I have developed
recently.</p>

<p>But as I trawled the net for 'How to' guides and started to test
sites I found (<em>Including industry advocates</em>) it got me
thinking, and I started to think it could actually have a negative
impact on your business.</p>

<p>I am now a 100% believer that mobile and tablet browsing (And
online ordering) is HUGE now, and growing year on year - And if you
haven't seen it, here is a great infograph from Kissmetrics about
this subject called 'Mobile Mania'.</p>

<p><a
href="http://blog.kissmetrics.com/mobile-mania/?wide=1">http://blog.kissmetrics.com/mobile-mania/?wide=1</a></p>

<p>But as I started to look at these sites that had implemented
RWD, I couldn't help but start to disagree with the notion that
using these techniques is the right way to go.</p>

<p>My thinking goes like this…</p>

<h2>Design</h2>

<p>You design a nice site , say based on the 960 grid - It looks
good, reads and lays out nicely.&nbsp; Then you have to start
chopping bits out and change spacing, squeezing columns headings
start to go on multiple lines etc.</p>

<p>It sort of destroys your design (<em>and if you work with
designers, you'll know how much they will appreciate that!</em>),
and takes away everything you have worked to create in the first
place.&nbsp; I realise the 'Mobile First' design gang will probably
jump in at this point, but unless your mobile traffic and
conversions seriously out weigh your 'desktop' users - Then in my
opinion its not the right way to go, you should be designing for
your main audience and giving them a display that's optimised for
them first.</p>

<p>I just think you end up with a site which doesn't really make
you stand out from the crowd, doesn't really resemble what the site
should look like and actually makes you look a little less
professional than your competition?</p>

<h2>Trust / Calls To Action</h2>

<p>Another thing which popped into my head is conversions and calls
to action.&nbsp; For sites that sell products and let people buy
through the site - Usually quite a lot of time is put into trying
to portray trust to the user, such things as secure shopping logos,
payment gateway logos, Seals (<em>Not the ones that swim in the Sea
<img src="/media/3126/Windows-Live-Writer_Is-Responsive-Web-Design_6B6C_wlEmoticon-smilewithtongueout_2.png" alt="Smile with tongue out" class="wlEmoticon wlEmoticon-smilewithtongueout" style="border-style: none;"/></em>), Awards etc.&nbsp;</p>

<p>In theory all these will either be lost, or manoeuvred further
down the page (<em>I'll get onto this more below</em>) so the users
are less likely to see them (If at all).&nbsp; This also goes for
your calls to action, if you have buttons or mini banners
positioned to try and entice the user to do what you want or get in
contact.</p>

<p>These are also very likely to get moved or replaced with actual
content, leaving me thinking that in theory you are less likely to
convert the user?</p>

<h2>Usability</h2>

<p>This is actually my biggest gripe with this new technique, and
maybe it is just me. But I like seeing a full site on my mobile, I
like being able to swipe my finger and navigate to specific
portions of the site.&nbsp; I like pinching and zooming in and
out&nbsp; and focusing where I want to.</p>

<p>I don't like having to scroll down and down and down, just to
read the first bit of content and then scroll all the way back up
to find the navigation.&nbsp; Again this is probably just my
preference, but I'm sure I can't be alone in thinking this can
I?</p>

<h2>Definitely Optimise For Mobile</h2>

<p>What I do believe in though is testing your site and optimising
it to work correctly on Mobiles (<em>Something I haven't done on
this one yet!!</em>) - As there are some easy CSS tweaks and
changes that will make your site look a lot better in most mobile
browsers.&nbsp;</p>

<p>As long as you take the time to do this testing, and it
functions correctly within a mobile browser (<em>Purchases works,
content forms work etc.</em>) then I'm not convinced that using
responsive web design is better, or will it help convert more
people into potential business.</p>

<p>Anyway, that's just my two pence worth…&nbsp; Love to hear your
thoughts about it below.</p>
]]></description></item><item><title>301 Redirect Multiple Domains In Umbraco</title><link>http://www.blogfodder.co.uk/2012/1/14/301-redirect-multiple-domains-in-umbraco</link><pubDate>Sat, 14 Jan 2012 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2012/1/14/301-redirect-multiple-domains-in-umbraco</guid><description><![CDATA[ 
<p>I thought I had already posted this up, but seems I'm going
mental and hadn't..</p>

<p>If you have a client site in which the client insists on having
tons of domains pointing at it, and you don't have access to ISAPI
rewrite to handle your redirects - you can actually 301 redirect
using the Umbraco UrlRewriting.config.</p>

<p>Just set these up for each domain you need, the attribute values
are pretty self explanatory.&nbsp; Obviously the
<strong>virtualUrl</strong> being the the domain you want to
redirect <strong>FROM</strong> and the
<strong>destinationUrl</strong> being the domain to redirect
<strong>TO</strong>.</p>

<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">add</span> <span
class="attr">name</span><span
class="kwrd">="RedirectLeeDomain"</span> <span
class="attr">redirectMode</span><span
class="kwrd">="Permanent"</span> <span
class="attr">redirect</span><span
class="kwrd">="Domain"</span> <span
class="attr">ignoreCase</span><span
class="kwrd">="true"</span><br />
<span class="attr">rewriteUrlParameter</span><span
class="kwrd">="IncludeQueryStringForRewrite"</span> <span
class="attr">virtualUrl</span><span
class="kwrd">="http://www.leedomain.co.uk/(.*)"</span> <span
class="attr">destinationUrl</span><span
class="kwrd">="http://www.n3o.co.uk/$1"</span> <span
class="kwrd">/&gt;</span>
</pre>

<p>You can use a similar rule to redirect non-www traffic to the
www (or vice versa), e.g:</p>

<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">add</span> <span
class="attr">name</span><span
class="kwrd">="RedirectNonWww"</span> <span
class="attr">redirectMode</span><span
class="kwrd">="Permanent"</span> <span
class="attr">redirect</span><span
class="kwrd">="Domain"</span> <span
class="attr">ignoreCase</span><span
class="kwrd">="true"</span><br />
<span class="attr">rewriteUrlParameter</span><span
class="kwrd">="IncludeQueryStringForRewrite"</span> <span
class="attr">virtualUrl</span><span
class="kwrd">="http://n3o.co.uk/(.*)"</span> <span
class="attr">destinationUrl</span><span
class="kwrd">="http://www.n3o.co.uk/$1"</span> <span
class="kwrd">/&gt;</span>
</pre>

<p>Simple as that… I wish I could take credit for this, but I
actually found it out from <a
href="http://twitter.com/attack_monkey">Tim</a> so tip of the hat
to him <img src="/media/3109/Windows-Live-Writer_6cef048f4efa_82CC_wlEmoticon-smile_2.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-style: none;"/></p>
]]></description></item><item><title>nForum v1.5 Released</title><link>http://www.blogfodder.co.uk/2012/1/12/nforum-v15-released</link><pubDate>Thu, 12 Jan 2012 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2012/1/12/nforum-v15-released</guid><description><![CDATA[ 
<p>Finally! I have released the latest version of nForum… v1.5… You
can download and install it via the nForum page below.</p>

<p><a
href="http://our.umbraco.org/projects/website-utilities/nforum">http://our.umbraco.org/projects/website-utilities/nforum</a></p>

<p>Also the code is on CodePlex so you can download and customise
(Or debug it!) however you need.&nbsp; Also for this version I have
added the Umbraco site and database backup within the solution for
the Umbraco install I used to create the package, and test it.</p>

<p><a
href="http://nforum.codeplex.com/SourceControl/list/changesets">http://nforum.codeplex.com/SourceControl/list/changesets</a></p>

<p>I'll try and outline some things below which I hope will help
people when installing, and any FAQ's I have received when user
testing.</p>

<p><em>NOTE: You cannot upgrade from a previous version to this
version, in theory you could do it manually but you'd need to do a
fresh install somewhere and then compare the two.</em></p>

<h2>Installation Overview</h2>

<p>I have put a little video together showing people nForum being
installed in an existing site, and showing some things that might
help when you try to install it yourself - Please do watch it.</p>

<object width="591" height="443"><param name="allowfullscreen"
value="true" />
<param name="allowscriptaccess" value="always" />
<param name="movie"
value="http://vimeo.com/moogaloop.swf?clip_id=34945384&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" />
<embed
src="http://vimeo.com/moogaloop.swf?clip_id=34945384&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00adef&amp;fullscreen=1&amp;autoplay=0&amp;loop=0"
 type="application/x-shockwave-flash" allowfullscreen="true"
allowscriptaccess="always" width="591" height="443" /></object> 

<h2>What Has Been Done In v1.5</h2>

<p>In short I have 'tried' to make it a little more robust, faster
and able to work with larger forums (1000's of nodes).&nbsp; But a
full list is below, doesn't look much in writing but if you look at
the source code you'll see a lot has changed.</p>

<p><strong>- Majority of the core codebase rewritten</strong><br />
<em>It no longer uses linq2umbraco but relies on Examine with a
Nodefactory backup, but still has a model structure which will make
it easy for you to grab the code and customise however you
need.</em><br />
<strong>- A lot of bug fixes from older version</strong><br />
<em>Hopefully fixes a lot of the install, and member issues from
the previous versions</em><br />
<strong>- Examine data provider with Nodefactory
backup</strong><br />
<em>As above, fully Examine/nodefactory powered - so if for some
reason you can't use Examine, you can't use this package</em><br />
<strong>- Multi lingual support</strong><br />
<em>All plain text from code behinds and classes are in Dictionary
items, but there are still plain text in the usercontrols/templates
- But you can add these to dictionary items through the Umbraco
admin and without having to use the source code.</em><br />
<strong>- Little UI tweaking</strong><br />
<em>Given the front end a little tweaking from a CSS point of
view</em></p>

<h2>FAQ</h2>

<p>I'll keep adding to this section over the next few weeks, but
one question came up below</p>

<p><em><strong>Q: In the back office, if you go into a post to look
at it, it's all HTML encoded, but it's a bit confusing for the
editors</strong></em></p>

<p><em>A: Posts should be edited in the front end, you just need to
mark the member as an admin in Umbraco - Then login as the user and
you can edit, delete and move topics around.&nbsp; The problem is
that Examine strips HTML, so the only way to get it to display
using Umbraco is to HTML encode it.&nbsp; So you can't use an RTE
or you'd see the same thing, only way round would be to write an
event to decode it before its displayed to the user I
guess?</em></p>

<h2>Checking Your nForum Install</h2>

<p>Previously I had a lot of people installing and either getting
timeouts, or saying things were missing - Below is a little
checklist, to make sure you have all the below and it explains what
the installer does.</p>

<p>1.) Check you have the Examine configs in, they are shown
below</p>

<p>Examine Index</p>

<pre class="csharpcode">
    <span class="kwrd">&lt;</span><span
class="html">IndexSet</span> <span class="attr">SetName</span><span
class="kwrd">="nForumEntrySet"</span> <span
class="attr">IndexPath</span><span
class="kwrd">="/App_Data/TEMP/ExamineIndexes/nForumEntryIndexSet/"</span><span
 class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">IndexAttributeFields</span><span
class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="id"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="Number"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="nodeName"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="updateDate"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="DateTime"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="createDate"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="DateTime"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="writerName"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="path"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="nodeTypeAlias"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="parentID"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="Number"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="sortOrder"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="Number"</span> <span
class="kwrd">/&gt;</span>          
        <span class="kwrd">&lt;/</span><span
class="html">IndexAttributeFields</span><span
class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">IndexUserFields</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategoryDescription"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategoryIsMainCategory"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategoryIsPrivate"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategoryPermissionKarmaAmount"</span> <span
class="attr">Type</span><span class="kwrd">="Number"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategoryPostPermissionKarmaAmount"</span> <span
class="attr">Type</span><span class="kwrd">="Number"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategorySubscribedList"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumCategoryParentID"</span> <span
class="kwrd">/&gt;</span>
            
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostContent"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostOwnedBy"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostLastEdited"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="DateTime"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostInReplyTo"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostIsSolution"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostIsTopicStarter"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostKarma"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="Number"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostUsersVoted"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumPostParentID"</span> <span
class="kwrd">/&gt;</span>
            
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicOwnedBy"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicClosed"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicSolved"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicParentCategoryID"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicIsSticky"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicSubscribedList"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="forumTopicLastPostDate"</span> <span
class="attr">EnableSorting</span><span
class="kwrd">="true"</span> <span class="attr">Type</span><span
class="kwrd">="DateTime"</span> <span class="kwrd">/&gt;</span>
            
        <span class="kwrd">&lt;/</span><span
class="html">IndexUserFields</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">IncludeNodeTypes</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="ForumCategory"</span><span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="ForumPost"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="ForumTopic"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">Name</span><span
class="kwrd">="Forum"</span> <span
class="kwrd">/&gt;</span>         
        <span class="kwrd">&lt;/</span><span
class="html">IncludeNodeTypes</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">ExcludeNodeTypes</span> <span
class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span
class="html">IndexSet</span><span class="kwrd">&gt;</span>
</pre>

<p>Examine Searcher</p>

<pre class="csharpcode">
      <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">name</span><span
class="kwrd">="nForumEntrySearcher"</span> <span
class="attr">type</span><span
class="kwrd">="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"</span> 
             <span class="attr">indexSet</span><span
class="kwrd">="nForumEntrySet"</span> <span
class="attr">analyzer</span><span
class="kwrd">="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"</span><span
 class="kwrd">/&gt;</span>
</pre>

<p>Examine Indexer</p>

<pre class="csharpcode">
        <span class="kwrd">&lt;</span><span
class="html">add</span> <span class="attr">name</span><span
class="kwrd">="nForumEntryIndexer"</span>
           <span class="attr">type</span><span
class="kwrd">="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"</span>
           <span class="attr">dataService</span><span
class="kwrd">="UmbracoExamine.DataServices.UmbracoDataService, UmbracoExamine"</span>
           <span class="attr">indexSet</span><span
class="kwrd">="nForumEntrySet"</span>
           <span class="attr">supportUnpublished</span><span
class="kwrd">="false"</span>
           <span class="attr">supportProtected</span><span
class="kwrd">="false"</span>
           <span class="attr">runAsync</span><span
class="kwrd">="true"</span>
           <span class="attr">interval</span><span
class="kwrd">="10"</span>
           <span class="attr">analyzer</span><span
class="kwrd">="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"</span>
           <span class="attr">enableDefaultEventHandler</span><span
class="kwrd">="true"</span><span class="kwrd">/&gt;</span>
</pre>

 

<p>2.) Check the ForumMember Group and Type has been created</p>

<p><a
href="/media/3061/Windows-Live-Writer_nForum-v1.5-Released_898D_membertype-group.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="membertype-group" border="0" alt="membertype-group"
src="/media/3066/Windows-Live-Writer_nForum-v1.5-Released_898D_membertype-group_thumb.jpg"
 width="165" height="152" /></a></p>

<p>Then check the member type properties are all present</p>

<p><a
href="/media/3071/Windows-Live-Writer_nForum-v1.5-Released_898D_member-type_2.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="member-type" border="0" alt="member-type"
src="/media/3076/Windows-Live-Writer_nForum-v1.5-Released_898D_member-type_thumb_1.jpg"
 width="524" height="377" /></a></p>

<p>3.) Check you have all the correct templates, scripts and CSS
files</p>

<p><a
href="/media/3081/Windows-Live-Writer_nForum-v1.5-Released_898D_filesnforum_2.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="filesnforum" border="0" alt="filesnforum"
src="/media/3086/Windows-Live-Writer_nForum-v1.5-Released_898D_filesnforum_thumb_1.jpg"
 width="252" height="583" /></a></p>

<p>4.) Check all the document types have been created</p>

<p><a
href="/media/3091/Windows-Live-Writer_nForum-v1.5-Released_898D_nforumdoctypes.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="nforumdoctypes" border="0" alt="nforumdoctypes"
src="/media/3096/Windows-Live-Writer_nForum-v1.5-Released_898D_nforumdoctypes_thumb.jpg"
 width="202" height="209" /></a></p>

<p>5.) Check the nforum binaries are in the bin</p>

<p>nForum.dll<br />
nForum.BusinessLogic.dll<br />
AntiXSSLibrary.dll<br />
AntiXSSLibrary.xml<br />
HtmlSanitizationLibrary.dll<br />
HtmlSanitizationLibrary.xml</p>

<p>6.) If everything seems to be in place, then grab the source
code related to this release of nForum on codeplex - put it in
debug, update the build events in the project to copy over to your
website.</p>

<p>And then debug/step through using Visual studio by attaching to
process - If you are not sure how to do this, there are loads of
tutorials about</p>

<p><a
href="http://www.google.co.uk/search?aq=0&amp;oq=umbraco+attac&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=debug+attach+process+video">
http://www.google.co.uk/search?aq=0&amp;oq=umbraco+attac&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=debug+attach+process+video</a></p>

<h2>Installing Into An Existing Site</h2>

<p>Please watch the video above and you'll see it installed into an
existing site, but if you are installing into an existing site…</p>

<p>You will need to take some things from the ForumMaster template
and update some links - If you open the
<strong>ForumMaster.master</strong> in Visual Studio you will see
comments about this like the below</p>

<pre class="csharpcode">
        <span class="kwrd">&lt;</span><span
class="html">asp:LoginView</span> <span class="attr">ID</span><span
class="kwrd">="lvLoginTopMenu"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span><span
class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span
class="html">AnonymousTemplate</span><span class="kwrd">&gt;</span>
        <span class="asp">&lt;%</span>
            <span
class="rem">//#### DEVEOPERS - READ ME &amp; THEN DELETE ME ####</span>
            <span
class="rem">//If you are going to move the forum into your own Master page,</span> 
            <span
class="rem">//You need to update the links below to point the the correct pages within the forum</span>
            <span
class="rem">//##############################################</span>
        <span class="asp">%&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">a</span> <span class="attr">href</span><span
class="kwrd">="/forum-login.aspx"</span><span
class="kwrd">&gt;</span>Login<span class="kwrd">&lt;/</span><span
class="html">a</span><span class="kwrd">&gt;</span> / <span
class="kwrd">&lt;</span><span class="html">a</span> <span
class="attr">href</span><span
class="kwrd">="/forum-register.aspx"</span><span
class="kwrd">&gt;</span>Register<span
class="kwrd">&lt;/</span><span class="html">a</span><span
class="kwrd">&gt;</span>            
            <span class="kwrd">&lt;/</span><span
class="html">AnonymousTemplate</span><span
class="kwrd">&gt;</span>            
        <span class="kwrd">&lt;/</span><span
class="html">asp:LoginView</span><span class="kwrd">&gt;</span>
</pre>

<p>I hope this covers a bit more to help people out.</p>
]]></description></item><item><title>Any Tutorials You Want To See?</title><link>http://www.blogfodder.co.uk/2012/1/1/any-tutorials-you-want-to-see</link><pubDate>Sun, 01 Jan 2012 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2012/1/1/any-tutorials-you-want-to-see</guid><description><![CDATA[ 
<p>A big happy new year to you all <img src="/media/3044/Windows-Live-Writer_Any-Tutorials-You-Want-To-See_870A_wlEmoticon-smile_2.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-style: none;"/>… As its a new year, I have been trying to sort out
a lot of my personal sites and one of the sites I'm getting into
shape is this blog.</p>

<p>Over the break, I have put up a few beginner targeted Umbraco
based posts, but I'd like to mix it up and maybe do some more
videos and a few more complex tutorials - So I thought I'd open it
to the community and find out exactly what sorts of things you guys
n' girls might like to see on here?&nbsp; I'm guessing a lot more
v5 stuff?&nbsp; More videos? Any specific things using Umbraco or
NopCommerce?</p>
]]></description></item><item><title>Umbraco Membership Templates</title><link>http://www.blogfodder.co.uk/2011/12/31/umbraco-membership-templates</link><pubDate>Sat, 31 Dec 2011 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2011/12/31/umbraco-membership-templates</guid><description><![CDATA[ 
<p>Creating a private/membership area in your Umbraco site really
is a piece of cake - If you don't know how to restrict public
access to a node (And its children) then I suggest you have a quick
look through the ' <a
href="http://our.umbraco.org/projects/website-utilities/editors-manual">
Umbraco Editors Guide</a>' for more in depth information.</p>

<p>But in short, to create a private membership area you firstly
need to make sure you have a 'member group' setup in members
section (<strong>For the templates below I have created a
membergroup in Umbraco called 'SiteMembers'</strong>) - And then
just browse to the section/nodes in your site you want to restrict
access to and right click and choose public access &gt; Role Based
Protection and assign the SiteMembers role to have access.</p>

<p><a
href="/media/3012/Windows-Live-Writer_Getting-Up--Running-With-A-Membership-Ar_C572_role.jpg">
<img src="/media/3017/Windows-Live-Writer_Getting-Up--Running-With-A-Membership-Ar_C572_role_thumb.jpg" width="382" height="190" alt="role" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p><a
href="/media/3022/Windows-Live-Writer_Getting-Up--Running-With-A-Membership-Ar_C572_role2.jpg">
<img src="/media/3027/Windows-Live-Writer_Getting-Up--Running-With-A-Membership-Ar_C572_role2_thumb.jpg" width="380" height="342" alt="role2" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<h2>Templates</h2>

<p>Once you have this done, you need to have a few things to make
it work - To help speed this along I have made some templates which
you can use below.&nbsp; Each of the below is a usercontrol and
added as a macro in the website, and once added will give you full
register, login and forgotten password functionality. Its all been
setup to use the JQuery validate too, so you need to make sure you
have that in your main template ready if you want to use it.</p>

<p><strong>**IMPORTANT**: These are just stripped out templates to
get you going, you NEED to add your own security logic to check the
users input for things like XSS attacks etc…</strong></p>

<h2>Register Template</h2>

<p>This has macro parameters which you'll need to add to the macro,
its just for redirecting to the member to a page after successful
registration</p>

<h4>ASCX</h4>

<pre class="csharpcode">
<span
class="asp">&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Register.ascx.cs" Inherits="Register" %&gt;</span>

<span class="kwrd">&lt;</span><span class="html">div</span> <span
class="attr">id</span><span
class="kwrd">="registersubscriberform"</span><span
class="kwrd">&gt;</span>

    <span class="kwrd">&lt;</span><span class="html">p</span><span
class="kwrd">&gt;</span>All items marked with a * are mandatory<span
 class="kwrd">&lt;/</span><span class="html">p</span><span
class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span
class="html">asp:Literal</span> <span class="attr">ID</span><span
class="kwrd">="litError"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formholder"</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span
class="kwrd">&gt;&lt;</span><span class="html">label</span> <span
class="attr">for</span><span
class="kwrd">="&lt;%= tbUsername.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Username*<span
class="kwrd">&lt;/</span><span class="html">label</span><span
class="kwrd">&gt;&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">asp:TextBox</span> <span
class="attr">ToolTip</span><span
class="kwrd">="Enter username"</span> <span
class="attr">CssClass</span><span
class="kwrd">="required"</span> <span class="attr">ID</span><span
class="kwrd">="tbUsername"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">ClientIDMode</span><span
class="kwrd">="Static"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span
class="kwrd">&gt;&lt;</span><span class="html">label</span> <span
class="attr">for</span><span
class="kwrd">="&lt;%= tbEmail.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Email*<span class="kwrd">&lt;/</span><span
class="html">label</span><span class="kwrd">&gt;&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">asp:TextBox</span> <span
class="attr">ToolTip</span><span
class="kwrd">="Enter email"</span> <span
class="attr">CssClass</span><span
class="kwrd">="required email"</span> <span
class="attr">ID</span><span class="kwrd">="tbEmail"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">ClientIDMode</span><span
class="kwrd">="Static"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span
class="kwrd">&gt;&lt;</span><span class="html">label</span> <span
class="attr">for</span><span
class="kwrd">="&lt;%= tbPassword.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Password*<span
class="kwrd">&lt;/</span><span class="html">label</span><span
class="kwrd">&gt;&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">asp:TextBox</span> <span
class="attr">ToolTip</span><span
class="kwrd">="Enter a password"</span> <span
class="attr">CssClass</span><span
class="kwrd">="required"</span> <span class="attr">ID</span><span
class="kwrd">="tbPassword"</span> <span
class="attr">TextMode</span><span
class="kwrd">="Password"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">ClientIDMode</span><span
class="kwrd">="Static"</span> <span class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span
class="kwrd">&gt;&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">asp:Button</span> <span class="attr">ID</span><span
class="kwrd">="btnRegister"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">Text</span><span class="kwrd">="Register"</span> <span
class="attr">OnClick</span><span
class="kwrd">="RegisterPlayer"</span> <span
class="kwrd">/&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

<span class="kwrd">&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
</pre>

<h4>CodeBehind</h4>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Web.Security;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> umbraco;
<span class="kwrd">using</span> umbraco.BusinessLogic;
<span class="kwrd">using</span> umbraco.cms.businesslogic.member;

    <span class="kwrd">public</span> <span
class="kwrd">partial</span> <span
class="kwrd">class</span> Register : UserControl
    {
        <span class="rem">// Macro Parameters</span>
        <span class="kwrd">public</span> <span
class="kwrd">int</span> SuccessfulLoginPage { get; set; }

        <span class="rem">// Member Type &amp; Group</span>
        <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> MembersType = <span
class="str">"SiteMembers"</span>;
        <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> MembersGroup = <span
class="str">"SiteMembers"</span>;

        <span class="rem">// Error format</span>
        <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> ErrorFormat = <span
class="str">"&lt;p class=\"formerror\"&gt;{0}&lt;/p&gt;"</span>;

        <span class="kwrd">protected</span> <span
class="kwrd">void</span> RegisterPlayer(<span
class="kwrd">object</span> sender, EventArgs e)
        {
            <span
class="rem">// Do some server side checks just to be on the safe side</span>
            <span class="kwrd">if</span> (<span
class="kwrd">string</span>.IsNullOrWhiteSpace(tbEmail.Text) | <span
class="kwrd">string</span>.IsNullOrWhiteSpace(tbPassword.Text) | <span
 class="kwrd">string</span>.IsNullOrWhiteSpace(tbUsername.Text))
            {
                litError.Text = <span
class="kwrd">string</span>.Format(ErrorFormat, <span
class="str">"Please complete all fields"</span>);
                <span class="kwrd">return</span>;
            }                

            <span
class="rem">// Check the user isn't already registered</span>
            <span
class="kwrd">if</span> (Member.GetMemberFromEmail(tbEmail.Text) == <span
 class="kwrd">null</span> &amp;&amp; Member.GetMemberFromLoginName(tbUsername.Text) == <span
 class="kwrd">null</span>)
            {
                <span
class="rem">// Set the member type and group</span>
                var mt = MemberType.GetByAlias(MembersType);
                var addToMemberGroup = MemberGroup.GetByName(MembersGroup);

                <span
class="rem">//create the member, and set the password and email</span>
                var m = Member.MakeNew(tbUsername.Text, mt, <span
class="kwrd">new</span> User(0));
                m.Password = tbPassword.Text;
                m.Email = tbEmail.Text;

                <span
class="rem">// Add the member to the group</span>
                m.AddGroup(addToMemberGroup.Id);

                <span class="rem">//Save member</span>
                m.Save();

                <span
class="rem">//Generate member Xml Cache</span>
                m.XmlGenerate(<span
class="kwrd">new</span> System.Xml.XmlDocument());

                <span class="rem">// NOTE: This Is Optional</span>
                <span class="rem">// Login the user</span>
                FormsAuthentication.SetAuthCookie(tbUsername.Text, <span
 class="kwrd">false</span>);

                <span
class="rem">// Redirect to successful page (Usually their profile or member page)</span>
                Response.Redirect(library.NiceUrl(SuccessfulLoginPage));
            }
            <span class="kwrd">else</span>
            {
                <span
class="rem">// Error, member already exists with email or username used</span>
                litError.Text = <span
class="kwrd">string</span>.Format(ErrorFormat, <span
class="str">"User already exists"</span>);
            }
        }
    }
</pre>

<h2>Login Template</h2>

<p>Again this has macro parameters which you'll need to add to the
macro, its just for redirecting to the member to a page after
successful login</p>

<h4>ASCX</h4>

<pre class="csharpcode">
<span
class="asp">&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Login.ascx.cs" Inherits="Login" %&gt;</span>

<span class="kwrd">&lt;</span><span
class="html">asp:Literal</span> <span class="attr">ID</span><span
class="kwrd">="litError"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="kwrd">/&gt;</span>
<span class="kwrd">&lt;</span><span
class="html">asp:Login</span> <span
class="attr">RenderOuterTable</span><span
class="kwrd">="false"</span> <span class="attr">ID</span><span
class="kwrd">="ctlLogin"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">OnLoginError</span><span
class="kwrd">="OnLoginError"</span> <span
class="attr">onloggedin</span><span
class="kwrd">="OnLoggedIn"</span> <span
class="attr">RememberMeSet</span><span
class="kwrd">="True"</span> <span
class="attr">VisibleWhenLoggedIn</span><span
class="kwrd">="False"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span
class="html">LayoutTemplate</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">id</span><span
class="kwrd">="login"</span><span
class="kwrd">&gt;</span>           
             
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formholder"</span><span class="kwrd">&gt;</span>

            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span
class="kwrd">&gt;&lt;</span><span class="html">label</span><span
class="kwrd">&gt;</span>Username<span
class="kwrd">&lt;/</span><span class="html">label</span><span
class="kwrd">&gt;&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="UserName"</span> <span
class="attr">CssClass</span><span
class="kwrd">="textbox required"</span> <span
class="attr">ToolTip</span><span
class="kwrd">="Enter username"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span><span
class="kwrd">&gt;&lt;/</span><span
class="html">asp:TextBox</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span
class="kwrd">&gt;&lt;</span><span class="html">label</span><span
class="kwrd">&gt;</span>Password<span
class="kwrd">&lt;/</span><span class="html">label</span><span
class="kwrd">&gt;&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="Password"</span> <span
class="attr">CssClass</span><span
class="kwrd">="textbox required"</span> <span
class="attr">ToolTip</span><span
class="kwrd">="Enter password"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">TextMode</span><span
class="kwrd">="Password"</span> <span class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>           

            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span class="kwrd">&gt;</span><span
class="attr">&amp;nbsp;</span><span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span
class="html">asp:CheckBox</span> <span class="attr">ID</span><span
class="kwrd">="RememberMe"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">Text</span><span
class="kwrd">="Keep me logged in"</span> <span
class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
            
            <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formrow"</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formleft"</span><span class="kwrd">&gt;</span><span
class="attr">&amp;nbsp;</span><span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
                <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">class</span><span
class="kwrd">="formright"</span><span class="kwrd">&gt;</span>
                    <span class="kwrd">&lt;</span><span
class="html">asp:Button</span> <span class="attr">ID</span><span
class="kwrd">="LoginButton"</span> <span
class="attr">CssClass</span><span
class="kwrd">="loginButton"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">CommandName</span><span
class="kwrd">="Login"</span> <span class="attr">Text</span><span
class="kwrd">="Login"</span> <span class="kwrd">/&gt;</span> <span
class="kwrd">/&gt;</span>
                <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

            <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>

    <span class="kwrd">&lt;/</span><span
class="html">LayoutTemplate</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span
class="html">asp:Login</span><span class="kwrd">&gt;</span>
</pre>

<h4>CodeBehind</h4>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> umbraco;
<span class="kwrd">using</span> umbraco.cms.businesslogic.member;

    <span class="kwrd">public</span> <span
class="kwrd">partial</span> <span
class="kwrd">class</span> Login : UserControl
    {
        <span class="rem">// Macro Parameters</span>
        <span class="kwrd">public</span> <span
class="kwrd">int</span> SuccessfulLoginPage { get; set; }

        <span class="rem">// Error format</span>
        <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> ErrorFormat = <span
class="str">"&lt;p class=\"formerror\"&gt;{0}&lt;/p&gt;"</span>;

        <span
class="rem">// If there is an error logging in, this method will fire and put the error in the error lit</span>
        <span class="kwrd">protected</span> <span
class="kwrd">void</span> OnLoginError(<span
class="kwrd">object</span> sender, EventArgs e)
        {
            litError.Text = <span
class="kwrd">string</span>.Format(ErrorFormat, ctlLogin.FailureText);
        }

        <span
class="rem">// This fires once the user has successfuly logged in</span>
        <span class="kwrd">protected</span> <span
class="kwrd">void</span> OnLoggedIn(<span
class="kwrd">object</span> sender, EventArgs e)
        {
            <span class="rem">// ** OPTIONAL! **</span>
            <span
class="rem">// You can do some custom logic here to check if user is banned or something similar</span>
            <span class="rem">// Get the user</span>
            var m = Member.GetMemberFromLoginName(ctlLogin.UserName);
            <span class="rem">// ** OPTIONAL! **</span>

            <span
class="rem">// Send the user to the correct authenticated page, once successfully logged in</span>
            Response.Redirect(library.NiceUrl(SuccessfulLoginPage));
        }
    }
</pre>

<h2>Forgotten Password Template</h2>

<p>The from email is stored as a constant in the code behind,
change this as you need - Usually this is a site wide setting I
have on the home node.</p>

<p><strong>NOTE:</strong> To use this, you need to make sure that
'<strong>enablePasswordReset</strong>' in your web.config is set to
'<strong>true</strong>'</p>

<h4>ASCX</h4>

<pre class="csharpcode">
<span
class="asp">&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ForgotPassword.ascx.cs" Inherits="ForgotPassword" %&gt;</span>

<span class="kwrd">&lt;</span><span class="html">p</span><span
class="kwrd">&gt;</span>Enter your email address<span
class="kwrd">&lt;/</span><span class="html">p</span><span
class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span
class="html">asp:Literal</span> <span class="attr">ID</span><span
class="kwrd">="litError"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="kwrd">/&gt;</span>
<span class="kwrd">&lt;</span><span class="html">p</span><span
class="kwrd">&gt;&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="tbEmail"</span> <span class="attr">runat</span><span
class="kwrd">="server"</span><span
class="kwrd">&gt;&lt;/</span><span
class="html">asp:TextBox</span><span class="kwrd">&gt;</span> 
<span class="kwrd">&lt;</span><span
class="html">asp:Button</span> <span class="attr">ID</span><span
class="kwrd">="btnSubmit"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">Text</span><span
class="kwrd">="Send Password"</span> <span
class="attr">onclick</span><span
class="kwrd">="BtnSubmitClick"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">p</span><span
class="kwrd">&gt;</span>
</pre>

<h4>CodeBehind</h4>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Text.RegularExpressions;
<span class="kwrd">using</span> System.Web.Security;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> umbraco;
<span class="kwrd">using</span> umbraco.cms.businesslogic.member;

<span class="kwrd">public</span> <span
class="kwrd">partial</span> <span
class="kwrd">class</span> ForgotPassword : UserControl
{
    <span class="rem">// Error format</span>
    <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> ErrorFormat = <span
class="str">"&lt;p class=\"formerror\"&gt;{0}&lt;/p&gt;"</span>;

    <span class="rem">// From Email Address</span>
    <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> FromEmail = <span
class="str">"noreply@mywebsite.com"</span>;

    <span class="kwrd">protected</span> <span
class="kwrd">void</span> BtnSubmitClick(<span
class="kwrd">object</span> sender, EventArgs e)
    {
        <span
class="rem">// Try and get the member from the email address entered</span>
        var cMember = Member.GetMemberFromEmail(tbEmail.Text);

        <span
class="rem">// Check we have a member with that email address</span>
        <span class="kwrd">if</span> (cMember != <span
class="kwrd">null</span>)
        {
            <span class="rem">// Found the user</span>
            <span
class="rem">// Generate a password which we'll email the member</span>
            var password = Membership.GeneratePassword(10, 1);
            password = Regex.Replace(password, <span
class="str">@"[^a-zA-Z0-9]"</span>, m =&gt; <span
class="str">"9"</span>);

            <span
class="rem">// Change the password to the new generated one above</span>
            var member = Membership.GetUser(cMember.LoginName);
            member.ChangePassword(member.ResetPassword(), password);

            <span class="rem">// Save the password/member</span>
            cMember.Save();

            <span class="rem">// update the XML cache</span> 
            cMember.XmlGenerate(<span
class="kwrd">new</span> System.Xml.XmlDocument());

            <span
class="rem">// Now email the member their password</span>
            var sb = <span class="kwrd">new</span> StringBuilder();
            sb.AppendFormat(<span
class="kwrd">string</span>.Format(<span
class="str">"&lt;p&gt;Please find your new password below to access the site&lt;/p&gt;"</span>));
            sb.AppendFormat(<span
class="str">"&lt;p&gt;&lt;b&gt;{0}&lt;/b&gt;&lt;/p&gt;"</span>, password);
            library.SendMail(FromEmail, cMember.Email, <span
class="str">"Password Reset"</span>, sb.ToString(), <span
class="kwrd">true</span>);

            <span
class="rem">// Disable the button to stop them pressing it again</span>
            btnSubmit.Enabled = <span class="kwrd">false</span>;

            <span class="rem">// Show a message to the user</span>
            litError.Text = <span
class="kwrd">string</span>.Format(ErrorFormat, <span
class="str">"Password Sent"</span>);
        }
        <span class="kwrd">else</span>
        {
            <span
class="rem">// Can't find a user with that email</span>
            litError.Text = <span
class="kwrd">string</span>.Format(ErrorFormat, <span
class="str">"Can't find a user with that email address"</span>);
        }
    }
}
</pre>

<h2>Styles</h2>

<p>A few styles just to make it look nice from the start - You
don't have to use these obviously.</p>

<pre class="csharpcode">
.formholder { overflow:hidden; width:800px;}
.formrow { padding:5px 0; clear:both; float:left; width:100%; clear:both; }
.formleft { float:left; width:30%; margin:0; line-height:20px; font-size:1.4em; padding:8px 0 0 0; }
.formright { float:right; width:59%; }
.formrow input[type=text], .formrow input[type=password] { padding:6px; width:250px; }
.formrow input[type=submit], .formrow input[type=button] { padding:3px 7px; cursor:pointer; }
.formrow select { padding:6px; width:255px; }
.formrow label.error { margin:0 0 0 10px;}<br />
p.formerror { font-weight: bold;color: red;}
</pre>
]]></description></item><item><title>Simple Contact Form Template For Umbraco</title><link>http://www.blogfodder.co.uk/2011/12/30/simple-contact-form-template-for-umbraco</link><pubDate>Fri, 30 Dec 2011 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2011/12/30/simple-contact-form-template-for-umbraco</guid><description><![CDATA[ 
<p>Sometimes when creating a new site for a client or a personal
site, you just need a simple and quick contact form that you can
just plugin or easily extend.</p>

<p>So below is a very simple template for you to use if you are
looking for just that, its a usercontrol with a few styles and a
couple of macro parameters.</p>

<h2>ASCX</h2>

<pre class="csharpcode">
<span
class="asp">&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContactForm.ascx.cs" Inherits="ContactForm" %&gt;</span>

<span class="kwrd">&lt;</span><span
class="html">asp:Literal</span> <span class="attr">ID</span><span
class="kwrd">="litError"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="kwrd">/&gt;</span>
<span class="kwrd">&lt;</span><span class="html">div</span> <span
class="attr">id</span><span
class="kwrd">="maincontactform"</span><span
class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">dl</span><span
class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dt</span><span class="kwrd">&gt;&lt;</span><span
class="html">label</span> <span class="attr">for</span><span
class="kwrd">="&lt;%=tbName.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Name*<span class="kwrd">&lt;/</span><span
class="html">label</span><span class="kwrd">&gt;&lt;/</span><span
class="html">dt</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dd</span><span class="kwrd">&gt;&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="tbName"</span> <span class="attr">runat</span><span
class="kwrd">="server"</span> <span
class="attr">CssClass</span><span
class="kwrd">="mftextbox"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">dd</span><span
class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">dt</span><span class="kwrd">&gt;&lt;</span><span
class="html">label</span> <span class="attr">for</span><span
class="kwrd">="&lt;%=tbEmail.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Email*<span class="kwrd">&lt;/</span><span
class="html">label</span><span class="kwrd">&gt;&lt;/</span><span
class="html">dt</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dd</span><span class="kwrd">&gt;&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="tbEmail"</span> <span class="attr">runat</span><span
class="kwrd">="server"</span> <span
class="attr">CssClass</span><span
class="kwrd">="mftextbox"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">dd</span><span
class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">dt</span><span class="kwrd">&gt;&lt;</span><span
class="html">label</span> <span class="attr">for</span><span
class="kwrd">="&lt;%=tbPhone.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Phone*<span class="kwrd">&lt;/</span><span
class="html">label</span><span class="kwrd">&gt;&lt;/</span><span
class="html">dt</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dd</span><span class="kwrd">&gt;&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="tbPhone"</span> <span class="attr">runat</span><span
class="kwrd">="server"</span> <span
class="attr">CssClass</span><span
class="kwrd">="mftextbox"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">dd</span><span
class="kwrd">&gt;</span>
        
        <span class="kwrd">&lt;</span><span
class="html">dt</span><span class="kwrd">&gt;&lt;</span><span
class="html">label</span> <span class="attr">for</span><span
class="kwrd">="&lt;%=tbCountry.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Country<span class="kwrd">&lt;/</span><span
class="html">label</span><span class="kwrd">&gt;&lt;/</span><span
class="html">dt</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dd</span><span class="kwrd">&gt;&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="tbCountry"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">CssClass</span><span
class="kwrd">="mftextbox"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">dd</span><span
class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">dt</span><span class="kwrd">&gt;&lt;</span><span
class="html">label</span> <span class="attr">for</span><span
class="kwrd">="&lt;%=tbEnquiry.ClientID %&gt;"</span><span
class="kwrd">&gt;</span>Enquiry<span class="kwrd">&lt;/</span><span
class="html">label</span><span class="kwrd">&gt;&lt;/</span><span
class="html">dt</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dd</span><span class="kwrd">&gt;&lt;</span><span
class="html">asp:TextBox</span> <span class="attr">ID</span><span
class="kwrd">="tbEnquiry"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">TextMode</span><span
class="kwrd">="MultiLine"</span> <span
class="attr">Rows</span><span class="kwrd">="10"</span> <span
class="attr">CssClass</span><span
class="kwrd">="mftextboxmulti"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">dd</span><span
class="kwrd">&gt;</span>
        
        <span class="kwrd">&lt;</span><span
class="html">dt</span><span class="kwrd">&gt;&lt;/</span><span
class="html">dt</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">dd</span><span class="kwrd">&gt;&lt;</span><span
class="html">asp:Button</span> <span class="attr">ID</span><span
class="kwrd">="btnSubmit"</span> <span
class="attr">runat</span><span class="kwrd">="server"</span> <span
class="attr">Text</span><span class="kwrd">="Submit"</span> <span
class="attr">onclick</span><span
class="kwrd">="BtnSubmitClick"</span> <span
class="attr">CssClass</span><span
class="kwrd">="mfsubmitbutton"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">dd</span><span
class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span
class="html">dl</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
</pre>

<h2>CodeBehind</h2>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> umbraco;

    <span class="kwrd">public</span> <span
class="kwrd">partial</span> <span
class="kwrd">class</span> ContactForm : UserControl
    {
        <span class="rem">// Macro Parameters</span>
        <span class="kwrd">public</span> <span
class="kwrd">string</span> EmailAddress { get; set; }
        <span class="kwrd">public</span> <span
class="kwrd">int</span> ThankYouPage { get; set; }

        <span
class="rem">// Hold a couple of formatting strings for use later</span>
        <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> ErrorFormat = <span
class="str">"&lt;p class=\"formerror\"&gt;{0}&lt;/p&gt;"</span>;
        <span class="kwrd">private</span> <span
class="kwrd">const</span> <span
class="kwrd">string</span> EmailLineFormat = <span
class="str">"&lt;p&gt;&lt;strong&gt;{0}&lt;/strong&gt;: {1}&lt;/p&gt;"</span>;

        <span class="kwrd">protected</span> <span
class="kwrd">void</span> BtnSubmitClick(<span
class="kwrd">object</span> sender, EventArgs e)
        {
            <span
class="rem">// Quick check for mandatory fields</span>
            <span class="kwrd">if</span>(<span
class="kwrd">string</span>.IsNullOrWhiteSpace(tbName.Text) | <span
class="kwrd">string</span>.IsNullOrWhiteSpace(tbEmail.Text) | <span
class="kwrd">string</span>.IsNullOrWhiteSpace(tbPhone.Text))
            {
                <span
class="rem">// Found an empty field, return error</span>
                litError.Text = <span
class="kwrd">string</span>.Format(ErrorFormat, <span
class="str">"Please complete all mandatory fields"</span>);
                <span class="kwrd">return</span>;
            }

            <span class="rem">// No errors create email</span>
            var email = <span
class="kwrd">new</span> StringBuilder();
            email.AppendFormat(EmailLineFormat, <span
class="str">"Name"</span>, tbName.Text);
            email.AppendFormat(EmailLineFormat, <span
class="str">"Email"</span>, tbEmail.Text);
            email.AppendFormat(EmailLineFormat, <span
class="str">"Phone"</span>, tbPhone.Text);
            email.AppendFormat(EmailLineFormat, <span
class="str">"Country"</span>, tbCountry.Text);
            email.AppendFormat(tbEnquiry.Text);

            <span class="rem">// Send the email</span>
            library.SendMail(EmailAddress, EmailAddress, <span
class="str">"Contact Form Enquiry"</span>, email.ToString(), <span
class="kwrd">true</span>);

            <span class="rem">// Redirect to thank you page</span>
            Response.Redirect(library.NiceUrl(ThankYouPage));
        }
    }
</pre>

<h2>Styles</h2>

<pre class="csharpcode">
/*--- Contact Form ---*/
dl { margin:12px 0; }
dt { padding:4px 0; font-weight:bold; }
dd { font-style:italic; padding:4px 0; }
.mftextbox { width:80%; padding:5px; font-size:20px; }
.mftextboxmulti { width:80%; padding:5px; font-size:12px; }
.mfsubmitbutton { font-size: 1.2em; padding: 3px 9px;}
p.formerror { font-weight: bold;color: red;}
</pre>

<p>That's it… Just add the macro parameters to your macro like
below so it will work properly, add the email address you want the
form to be sent to and also the thank you page to redirect the user
to on successful sending.</p>

<p><strong>NOTE: Don't forget, to use the
umbraco.library.SendMail() you must have some SMTP settings in your
web.config or it won't send.</strong></p>

<p><a
href="/media/2970/Windows-Live-Writer_Simple-Contact-Form-Template-For-Umbraco_8913_contactform.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="contactform" border="0" alt="contactform"
src="/media/2975/Windows-Live-Writer_Simple-Contact-Form-Template-For-Umbraco_8913_contactform_thumb.jpg"
 width="422" height="403" /></a></p>

<p><a
href="/media/2980/Windows-Live-Writer_Simple-Contact-Form-Template-For-Umbraco_8913_contactform2.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="contactform2" border="0" alt="contactform2"
src="/media/2985/Windows-Live-Writer_Simple-Contact-Form-Template-For-Umbraco_8913_contactform2_thumb.jpg"
 width="421" height="76" /></a></p>

<p>&nbsp;</p>

<p>Hopefully you'll end up with the below</p>

<p>&nbsp;</p>

<p><a
href="/media/2990/Windows-Live-Writer_Simple-Contact-Form-Template-For-Umbraco_8913_finished-form.jpg">
<img
style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px"
 title="finished-form" border="0" alt="finished-form"
src="/media/2995/Windows-Live-Writer_Simple-Contact-Form-Template-For-Umbraco_8913_finished-form_thumb.jpg"
 width="411" height="445" /></a></p>
]]></description></item><item><title>Umbraco Image Helper Class</title><link>http://www.blogfodder.co.uk/2011/12/29/umbraco-image-helper-class</link><pubDate>Thu, 29 Dec 2011 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2011/12/29/umbraco-image-helper-class</guid><description><![CDATA[ 
<p>Its been a busy few months, so I have not had much time to blog
but I have been building up a list of short&nbsp; and (hopefully)
helpful little blog posts.</p>

<p>I have been really getting into Umbraco Razor recently, and on a
site we have just finished where we had a lot of images we were
pulling out dynamically from the media section and they had to be
resized differently.&nbsp; So I created this little image helper
class which uses a mixture of Examine &amp; Imagegen to make a
really easy way to get images without too much of a performance
hit.</p>

<p><strong>NOTE:</strong> You <a
href="http://our.umbraco.org/projects/website-utilities/imagegen">need
to have Imagegen</a> installed to use this</p>

<p>It allows you to optionally resize if you want, also greyscale
if you want (Greyscale is an imagegen pro option) and all you pass
in is the Media ID - You simple call it in your Razor Macros like
so</p>

<p><strong>Get Image Fast - No Resize Or GreyScale</strong></p>

<pre class="csharpcode">
@ImageHelper.ReturnResizedImage(Convert.ToInt32(MEDIAID), <span
class="kwrd">null</span>)
</pre>

<p><strong>Get Resized Image To 300px width</strong></p>

<pre class="csharpcode">
@ImageHelper.ReturnResizedImage(Convert.ToInt32(MEDIAID), 300)
</pre>

<p><strong>Get Resized Image To 300px &amp; GreyScale
It</strong></p>

<pre class="csharpcode">
@ImageHelper.ReturnResizedImage(Convert.ToInt32(MEDIAID), 300, <span
 class="kwrd">true</span>)
</pre>

<h2>The Class</h2>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Xml.XPath;
<span class="kwrd">using</span> Examine;
<span class="kwrd">using</span> umbraco;

    <span class="kwrd">public</span> <span
class="kwrd">static</span> <span
class="kwrd">class</span> ImageHelper
    {
        <span class="rem">/// &lt;summary&gt;</span>
        <span
class="rem">/// Returns a resized image quickly, optional resize and also optional greyscales it</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span
class="rem">/// &lt;param name="mediaid"&gt;Umbraco Media ID&lt;/param&gt;</span>
        <span
class="rem">/// &lt;param name="size"&gt;Optional width if you want to resize&lt;/param&gt;</span>
        <span
class="rem">/// &lt;param name="greyscale"&gt;Optional greyscale&lt;/param&gt;</span>
        <span
class="rem">/// &lt;returns&gt;Full Url of image with imagegen parameters&lt;/returns&gt;</span>
        <span class="kwrd">public</span> <span
class="kwrd">static</span> <span
class="kwrd">string</span> ReturnResizedImage(<span
class="kwrd">int</span> mediaid, <span
class="kwrd">int</span>? size, <span
class="kwrd">bool</span> greyscale = <span
class="kwrd">false</span>)
        {
            <span class="kwrd">if</span> (mediaid &lt;= 0) <span
class="kwrd">return</span> <span class="kwrd">null</span>;

            <span class="kwrd">const</span> <span
class="kwrd">string</span> imageResizeFormat = <span
class="str">"/ImageGen.ashx?image={0}"</span>;
            <span class="kwrd">const</span> <span
class="kwrd">string</span> grayScaleFormat = <span
class="str">"&amp;ColorMode=Grayscale"</span>;
            var widthFormat = <span
class="kwrd">string</span>.Concat(<span
class="str">"&amp;width="</span>, size);
            var newImageUrl = GetUmbracoMedia(mediaid).Values[<span
class="str">"umbracoFile"</span>];

            <span class="kwrd">if</span> (size == <span
class="kwrd">null</span> &amp; !greyscale)
            {
                <span class="kwrd">return</span> newImageUrl;
            }

            <span class="kwrd">if</span> (size != <span
class="kwrd">null</span>)
            {
                newImageUrl = <span
class="kwrd">string</span>.Concat(<span
class="kwrd">string</span>.Format(imageResizeFormat, newImageUrl), widthFormat);
            }

            <span class="kwrd">if</span> (greyscale)
            {
                newImageUrl = <span
class="kwrd">string</span>.Concat(newImageUrl, grayScaleFormat);
            }

            <span class="kwrd">return</span> newImageUrl;

        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span
class="rem">/// Fastest way to get media from Umbraco</span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span
class="rem">/// &lt;param name="id"&gt;&lt;/param&gt;</span>
        <span
class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span class="kwrd">private</span> <span
class="kwrd">static</span> MediaValues GetUmbracoMedia(<span
class="kwrd">int</span> id)
        {
            <span
class="rem">//first check in Examine as this is WAY faster</span>
            var criteria = ExamineManager.Instance.SearchProviderCollection[<span
 class="str">"InternalSearcher"</span>].CreateSearchCriteria(<span
class="str">"media"</span>);
            var filter = criteria.Id(id);
            var results = ExamineManager.Instance.SearchProviderCollection[<span
 class="str">"InternalSearcher"</span>].Search(filter.Compile());
            <span class="kwrd">if</span> (results.Any())
            {
                <span class="kwrd">return</span> <span
class="kwrd">new</span> MediaValues(results.First());
            }

            var media = library.GetMedia(id, <span
class="kwrd">false</span>);
            <span class="kwrd">if</span> (media != <span
class="kwrd">null</span> &amp;&amp; media.Current != <span
class="kwrd">null</span>)
            {
                media.MoveNext();
                <span class="kwrd">return</span> <span
class="kwrd">new</span> MediaValues(media.Current);
            }

            <span class="kwrd">return</span> <span
class="kwrd">null</span>;
        }
    }

    <span
class="preproc">#region</span> Helper Media Values Class - Taken from Shannons blog (I think)
    <span class="kwrd">class</span> MediaValues
    {
        <span
class="kwrd">public</span> MediaValues(XPathNavigator xpath)
        {
            <span class="kwrd">if</span> (xpath == <span
class="kwrd">null</span>) <span class="kwrd">throw</span> <span
class="kwrd">new</span> ArgumentNullException(<span
class="str">"xpath"</span>);
            Name = xpath.GetAttribute(<span
class="str">"nodeName"</span>, <span class="str">""</span>);
            Values = <span
class="kwrd">new</span> Dictionary&lt;<span
class="kwrd">string</span>, <span class="kwrd">string</span>&gt;();
            var result = xpath.SelectChildren(XPathNodeType.Element);
            <span class="kwrd">while</span> (result.MoveNext())
            {
                <span
class="kwrd">if</span> (result.Current != <span
class="kwrd">null</span> &amp;&amp; !result.Current.HasAttributes)
                {
                    Values.Add(result.Current.Name, result.Current.Value);
                }
            }
        }

        <span
class="kwrd">public</span> MediaValues(SearchResult result)
        {
            <span class="kwrd">if</span> (result == <span
class="kwrd">null</span>) <span class="kwrd">throw</span> <span
class="kwrd">new</span> ArgumentNullException(<span
class="str">"result"</span>);
            Name = result.Fields[<span
class="str">"nodeName"</span>];
            Values = result.Fields;
        }

        <span class="kwrd">public</span> <span
class="kwrd">string</span> Name { get; <span
class="kwrd">private</span> set; }
        <span class="kwrd">public</span> IDictionary&lt;<span
class="kwrd">string</span>, <span
class="kwrd">string</span>&gt; Values { get; <span
class="kwrd">private</span> set; }
    } 
    <span class="preproc">#endregion</span>
</pre>
]]></description></item><item><title>Extending The Google Maps Property Editor In Umbraco V5</title><link>http://www.blogfodder.co.uk/2011/11/22/extending-the-google-maps-property-editor-in-umbraco-v5</link><pubDate>Tue, 22 Nov 2011 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2011/11/22/extending-the-google-maps-property-editor-in-umbraco-v5</guid><description><![CDATA[ 
<p>In the previous blog post we created a <a
href="/2011/11/21/creating-a-google-map-property-editor-for-umbraco-v5">
fairly simple Google maps property editor</a>, but as we all know
when creating property editors/datatypes things are never as clean
cut as that and you have the need for things like prevalues to
configure you property editor/datatype and maybe even doing some
sort of custom logic before Umbraco saves the values from your
editor.</p>

<p>So I thought even though the previous Google map property editor
is working, and is fully functional as is - We might as well cover
some of these scenarios and extend it… And as you will have seen so
far, its so easy to do!</p>

<h2>Change Values Before Save</h2>

<p>There may be occasions where you need to edit or tweak the
values of your property editor before Umbraco serializes them, and
saves them to the DB.&nbsp; So to show an example of this I thought
I would add a new hidden field, which before the values are saved
would concatenate the longitude and latitude into a format like so
'51.5454, -41.25668' so we can use it directly in the JavaScript in
the front end and not have to worry about getting individual
values.</p>

<p>Lets first open up our
<strong>'GoogleMapEditorModel.cs'</strong> and add a new hidden
field.</p>

<pre class="csharpcode">
        [HiddenInput(DisplayValue = <span
class="kwrd">false</span>)]
        <span class="kwrd">public</span> <span
class="kwrd">string</span> LatLongCombined { get; set; }
</pre>

<p>That's it, we have somewhere to store this value - Now we just
need to override an inbuilt method called 'GetSerializedValue'
which will allow us to change and edit values before they are
saved. So under our newly added 'LatLongCombined' property in your
code add the following:</p>

<pre class="csharpcode">
        <span class="kwrd">public</span> <span
class="kwrd">override</span> IDictionary&lt;<span
class="kwrd">string</span>, <span
class="kwrd">object</span>&gt; GetSerializedValue()
        {
            <span class="kwrd">if</span> (Lat != <span
class="kwrd">null</span> &amp;&amp; Long != <span
class="kwrd">null</span>)
            {
                LatLongCombined = <span
class="kwrd">string</span>.Concat(Lat, <span
class="str">", "</span>, Long);
            }
            <span class="kwrd">return</span> <span
class="kwrd">base</span>.GetSerializedValue();
        }
</pre>

<p>As you can see we are just concatenating the other property
values into the format we want and saving them to the new property,
but you could do anything in here really? Maybe call an external
web service or do more complex logic dependant on your needs.</p>

<p>Obviously we can now update our homepage razor code to reflect
this by removing the var lat &amp; long we initially added and
update the following line of the JavaScript to (Don't forget to
actually load the backend first and save and publish the home page
or you'll get a key error in the front end)</p>

<pre class="csharpcode">
var myLatlng = <span
class="kwrd">new</span> google.maps.LatLng(@Html.Raw(Model.Field&lt;<span
 class="kwrd">string</span>&gt;(<span
class="str">"gMap"</span>, <span
class="str">"LatLongCombined"</span>).ToString()));
</pre>

<p>As the meercat would say.. Simples..</p>

<h2>Adding PreValues</h2>

<p>For more complex property editors that might require Api keys or
lots of configuration settings, prevalues are a must - And again
the v5 team have made it super easy to do this using the same
principles as the actual editor itself using a Model to
scaffold/dictate your UI.&nbsp; You just create a class as you did
for the EditorModel again keeping a naming convention like so
'GoogleMap<strong>PreValueModel</strong>.cs' appending
PreValueModel at the end.&nbsp; Create this file and add the
following code, as you can see its almost exactly the same as the
EditorModel apart from we inherit from 'PreValueModel' instaead of
'EditorModel'</p>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.ComponentModel;
<span
class="kwrd">using</span> System.ComponentModel.DataAnnotations;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span
class="kwrd">using</span> Umbraco.Cms.Web.Model.BackOffice.PropertyEditors;

<span
class="kwrd">namespace</span> Umbraco.Cms.Web.PropertyEditors.GoogleMap
{
    <span class="kwrd">public</span> <span
class="kwrd">class</span> GoogleMapPreValueModel : PreValueModel
    {
        [Required(ErrorMessage = <span
class="str">@"Zoom level missing"</span>)]
        [DisplayName(<span
class="str">@"Set the initial zoom level of your map"</span>)]
        <span class="kwrd">public</span> <span
class="kwrd">int</span> GoogleMapZoomLevel { get; set; }
    }
}
</pre>

<p>Before this will just work, we do need to tell the
PropertyEditor that we have prevalues and to make sure they are
available to us from within our property editor.&nbsp; To do this
we just need to <a
href="/2011/11/21/creating-a-google-map-property-editor-for-umbraco-v5">
expand on what we did in the previous post</a>.</p>

<h3>GoogleMapEditorModel</h3>

<p>Open up 'GoogleMapEditorModel.cs' and update the main class line
to the following (We are just appending the type
&lt;GoogleMapPreValueModel&gt; to the EditorModel class we were
inheriting from)</p>

<pre class="csharpcode">
<span class="kwrd">public</span> <span
class="kwrd">class</span> GoogleMapEditorModel : EditorModel&lt;GoogleMapPreValueModel&gt;
</pre>

<p>And then add the following constructor just underneath</p>

<pre class="csharpcode">
<span
class="kwrd">public</span> GoogleMapEditorModel(GoogleMapPreValueModel preValues) : <span
 class="kwrd">base</span>(preValues)
{
}
</pre>

<h3>GoogleMapEditor</h3>

<p>Finally we just need to do the same thing to the Editor, so
update the following line (Again we are adding the PreValueModel
type to the PropertyEditor)</p>

<pre class="csharpcode">
<span class="kwrd">public</span> <span
class="kwrd">class</span> GoogleMapEditor : PropertyEditor&lt;GoogleMapEditorModel<strong>, GoogleMapPreValueModel</strong>&gt;
</pre>

<p>You will know be prompted in Visual Studio to update the
implemented interface members, you can either follow the VS prompt
or copy and paste the following</p>

<pre class="csharpcode">
        <span class="kwrd">public</span> <span
class="kwrd">override</span> GoogleMapEditorModel CreateEditorModel(GoogleMapPreValueModel preValues)
        {
            <span class="kwrd">return</span> <span
class="kwrd">new</span> GoogleMapEditorModel(preValues);
        }

        <span class="kwrd">public</span> <span
class="kwrd">override</span> GoogleMapPreValueModel CreatePreValueEditorModel()
        {
            <span class="kwrd">return</span> <span
class="kwrd">new</span> GoogleMapPreValueModel();
        }
</pre>

<p>And that be it me ol'friend! If you build and load up the
solution you'll see the following on your property editor in the
developer section</p>

<p><a
href="/media/2840/Windows-Live-Writer_Extending-Google-Maps-Property-Editor-In_856B_prevalue-settings.jpg">
<img src="/media/2845/Windows-Live-Writer_Extending-Google-Maps-Property-Editor-In_856B_prevalue-settings_thumb.jpg" width="398" height="163" alt="prevalue-settings" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p><strong>TIP!: You might have to delete your temporary ASP.NET
files to get the prevalues to show.</strong></p>

<h2>Custom View For PreValues</h2>

<p>I'm not going to do this as I think its a bit pointless for this
example, but again you can have a custom view for your Pre Values
if you wish and again its the exact same concept as the custom view
for the property editor (Nifty hey). See the previous post for more
details, but in short you just need to create the following view in
your 'Views' folder</p>

<p><strong>GoogleMapPreValueEditor.cshtml</strong></p>

<p>At the top of this view add the following</p>

<pre class="csharpcode">
@inherits WebViewPage&lt;Umbraco.Cms.Web.PropertyEditors.GoogleMap.GoogleMapPreValueModel&gt;
</pre>

<p>And in the <strong>'GoogleMapPreValueModel.cs'</strong> class,
decorate it with the following to tell Umbraco its using an
embedded view (Again exactly the same as we did for the main
property editor)</p>

<pre class="csharpcode">
[EmbeddedView(<span
class="str">"Umbraco.Cms.Web.PropertyEditors.GoogleMap.Views.GoogleMapPreValueEditor.cshtml"</span>, <span
 class="str">"Umbraco.Cms.Web.PropertyEditors"</span>)]
</pre>

<p>See the custom view in the previous post on how to access the
properties of the model.</p>

<h2>Changing PreValues Before Save</h2>

<p>So I haven't actually used this one, but it seems just like on
the property editor you can override the same method (Although its
a little different)</p>

<pre class="csharpcode">
        <span class="kwrd">public</span> <span
class="kwrd">override</span> <span
class="kwrd">string</span> GetSerializedValue()
        {
            <span class="kwrd">return</span> <span
class="kwrd">base</span>.GetSerializedValue();
        }
</pre>

<p>I'll have to have a play with this further but at the moment I
couldn't think of a reason for using it - so have a play and see if
it works for you</p>

<h2>Actually Using The PreValue Values</h2>

<p>Anyway, so we'll skip the above two items and just use the
standard preValue model for showing and saving the settings (Zoom
level in our case) - What we want to do now is set the zoom level
for the map in our view.&nbsp; To do this you access prevalue
values in your editor like so:</p>

<h3>@Model.PreValueModel.<em>PropertyName</em></h3>

<p>So in our case we would get the zoom level like this</p>

<p>@Model.PreValueModel.GoogleMapZoomLevel</p>

<p>Now in our example the Zoom level is in the JavaScript, so for
us to be able to use this we need to set another global JS variable
in our custom editor view (Just under var latval in the JS script
tag)</p>

<pre class="csharpcode">
    <span
class="kwrd">var</span> zoomLevel = @Model.PreValueModel.GoogleMapZoomLevel;
    <span class="kwrd">if</span>(zoomLevel &lt;= 0) {
        zoomLevel = 16;
    }
</pre>

<p>Now open up your 'gMap.js' file and changed the zoom: variable
at the top from 'zoom: 16' to:</p>

<pre class="csharpcode">
zoom: zoomLevel,
</pre>

<p>Save, build and run…</p>

<p><strong>TIP!: You might have to delete your temporary ASP.NET
files to get this to show</strong></p>

<p>And that's it <img src="/media/2850/Windows-Live-Writer_Extending-Google-Maps-Property-Editor-In_856B_wlEmoticon-smile_2.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-style: none;"/> … Have a play changing the zoom value settings, and
you'll see the zoom level change… As Mr Ramsey would say, Google
Map Property Editor... Done!</p>

<p>Hopefully you'll agree this is a great step forward from v4.</p>
]]></description></item><item><title>Creating A Google Map Property Editor For Umbraco v5</title><link>http://www.blogfodder.co.uk/2011/11/21/creating-a-google-map-property-editor-for-umbraco-v5</link><pubDate>Mon, 21 Nov 2011 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2011/11/21/creating-a-google-map-property-editor-for-umbraco-v5</guid><description><![CDATA[ 
<p>If you want to follow this little tutorial then download the
current V5 source by <a
href="/2011/11/5/get-yourself-setup-to-play-with-umbraco-v5">following
my previous post</a>, and get yourself set up and the source
running.&nbsp; This post will focus more on the Umbraco
fundamentals/code than the underlying JS code that makes the Google
Map Geocode and Marker Move etc.. If you want more info on that
then <a
href="/2011/11/19/an-autocomplete-geocoding-google-map-with-draggable-marker">
see the Google Map Post</a>.</p>

<p>As with most blog posts, I will explain things in my own way so
the terminology may not be 100% correct, but I hope at the end of
this post you should be able to easily create your property
editor.&nbsp; also before I start if you are coming from Umbraco v4
and want to know what the hell a property editor is… Well its sort
of the new name for DataTypes.</p>

<h2>References</h2>

<p>Before I start there are some good references, albeit things are
still changing so they may need to be updated</p>

<p><em><strong>Wiki post</strong></em><br />
 <a
href="http://jupiter.umbraco.org/Developing%20Property%20Editors.ashx">
http://jupiter.umbraco.org/Developing%20Property%20Editors.ashx</a></p>

<p><em><strong>Tim's Post</strong></em><br />
 <a
href="http://www.nibble.be/?p=104">http://www.nibble.be/?p=104</a></p>

<p><em><strong>MVC validation data annotations</strong></em><br />
 Lastly I would highly recommend you read up about MVC validation
data annotations, as you use these for the EditorModel and
prevalueModel model</p>

<p><a
href="http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs">
http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs</a></p>

<h2>Simple Example</h2>

<p>When I started messing around, I found the simplest example of a
property editor was to open up the v5 source and go to the
'Umbraco.Cms.Web.PropertyEditors' project and open up the TrueFalse
property editor.&nbsp; As you can see this is a very, very simple
property editor and is made of two files 'TrueFalseEditor' and
'TrueFalseEditorModel'.&nbsp; Notice the naming convention of
<em><strong>PropertyName</strong></em>Editor and
<em><strong>PropertyName</strong></em>EditorModel, this is kept
throughout.</p>

<p><a
href="/media/2757/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_true-false1.jpg">
<img src="/media/2762/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_true-false1_thumb.jpg" width="335" height="121" alt="true-false1" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p><a
href="/media/2767/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_true-false2.jpg">
<img src="/media/2772/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_true-false2_thumb.jpg" width="509" height="114" alt="true-false2" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p>The only file that's really doing anything here is the
'TrueFalseEditorModel', if you open it up you can see its a simple
class with a public bool property (Decorated with data annotations
- See link in references above) and it inherits from 'EditorModel'
- That's it, which is why its called the 'Model' (I look at this
like scaffolding in MVC, I guess its probably the something similar
under the hood?).&nbsp;</p>

<p>It literally is the model of your property editor, in this case
with are just trying to display something which enables a user to
choose and save a true/false value.&nbsp; So when this bool
property in your model is picked up by Umbraco, it will render it
as a checkbox in the view. The second file 'TrueFalseEditor' in
this case is just used to return your EditorModel to Umbraco and
also has some identifiers in the decoration, it has a unique GUID
which is the ID, an alias and a name - But in short all you need to
know for this example is that it returns your EditorModel which is
rendered as a checkbox.</p>

<p>So if we changed the property named 'Value' in the Model from a
bool to say a string, then in the admin it would get rendered as
textbox… Same if we changed it from a bool to say an int, it would
get rendered as a textbox that only accepts an integer! Yes
validation is all handled for you! Pretty cool hey…</p>

<h4><em><strong>TIPS</strong></em>:</h4>

<p>1) I'm not sure on the terminology here, but Property editors
are fully compiled meaning that if you have any assets (Custom
Views, JS &amp; CSS files etc…) they need to be marked as embedded
resource so they are compiled into the DLL. We'll cover this again
but to do this you just 'right click' on the files and go to
'properties' and change build action to embedded resource (see
below)</p>

<p><a
href="/media/2777/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_embedded.jpg">
<img src="/media/2782/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_embedded_thumb.jpg" width="319" height="88" alt="embedded" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p>2) Whether this will be sorted on full release or not I don't
know, because I don't know if its an MVC or Umbraco thing. But if
you make some changes to your property editor, or add some more
resource files it doesn't always show up when Umbraco is run.&nbsp;
To kick the changes into effect you need to delete you ASP.NET temp
files and then rebuild the solution (Bit of a pain but not a show
stopper).</p>

<h2>Structure</h2>

<p>As you will see from other Property Editors in the v5 source the
file/folder structure is pretty simple - Two folders:</p>

<p><strong>Views<br />
 Resources</strong></p>

<p>Which hold what the say on the tin… any custom views go into the
Views folder and your resources (CSS, JS, Images) go into the
Resources folder.&nbsp; all you classes then go in the root of the
editor folder, using the naming convention I mentioned above. Again
don't forget any views/resources added have to marked as 'embedded
resource' or your property editor won't work.</p>

<h2>The gMap Model</h2>

<p>I have to say, (and I hope you'll agree after reading the above)
making a quick, simple'ish custom datatype in v5 really is a breeze
- I love the way you can just create your model class and don't
have to worry about creating the UI or worry about how to save the
values… It just works.&nbsp; But for our Google Map property editor
we need to add some custom code to the view, so we can show the
map, autocomplete textbox for locations and a few other things.</p>

<p>But again, the v5 guys have made doing this SUPER easy!&nbsp;
Before we do that we still need to create our base model and editor
class.&nbsp; So just like the other property editors, open up the
v5 source and in the 'Umbraco.Cms.Web.PropertyEditors' project
create a folder called 'GoogleMap' and create the following
files</p>

<p>Views (Folder)<br />
 Resources (Folder)<br />
 GoogleMapEditor.cs<br />
 GoogleMapEditorModel.cs</p>

<p><a
href="/media/2787/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_startstructure.jpg">
<img src="/media/2792/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_startstructure_thumb.jpg" width="272" height="212" alt="startstructure" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p>Now we just need to add the properties to our Model - Lets work
our what we need, and then we can relate that to the model - All I
want to store is:</p>

<ul>
<li>The Location The Users Types In (<em>string</em>)</li>

<li>The longitude from the gMaps GeoCoding (<em>User doesn't use
these, so they can ben hidden</em>)</li>

<li>The latitude from the gMaps GeoCoding (<em>User doesn't use
these, so they can ben hidden</em>)</li>
</ul>

<p>Based on this I'll create both the editor and editorModel just
like its been done in the simple TrueFalse example above:</p>

<p><strong>Open GoogleMapEditorModel.cs and add</strong></p>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.ComponentModel;
<span
class="kwrd">using</span> System.ComponentModel.DataAnnotations;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Web.Mvc;
<span class="kwrd">using</span> Umbraco.Cms.Web.EmbeddedViewEngine;
<span
class="kwrd">using</span> Umbraco.Cms.Web.Model.BackOffice.PropertyEditors;
<span
class="kwrd">using</span> Umbraco.Cms.Web.PropertyEditors.Tags;

<span
class="kwrd">namespace</span> Umbraco.Cms.Web.PropertyEditors.GoogleMap
{
    <span class="kwrd">public</span> <span
class="kwrd">class</span> GoogleMapEditorModel : EditorModel
    {

        [Required(ErrorMessage = <span
class="str">"Postcode/location is required"</span>)]
        <span class="kwrd">public</span> <span
class="kwrd">string</span> Postcode { get; set; }

        [HiddenInput(DisplayValue = <span
class="kwrd">false</span>)]
        <span class="kwrd">public</span> <span
class="kwrd">string</span> Long { get; set; }

        [HiddenInput(DisplayValue = <span
class="kwrd">false</span>)]
        <span class="kwrd">public</span> <span
class="kwrd">string</span> Lat { get; set; }

    }
}
</pre>

<p>I'm not going to go into detail about the attributes I have
decorated the properties with, as I mentioned above you need to go
and read up about 'MVC validation data annotations' as they are an
MVC thing not a specific Umbraco thing.&nbsp; But I hope just be
looking at the code you get the idea of what they are doing.</p>

<p><strong>Open GoogleMapEditor.cs and add</strong></p>

<pre class="csharpcode">
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Linq;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Web.UI;
<span
class="kwrd">using</span> Umbraco.Cms.Web.Model.BackOffice.PropertyEditors;

<span
class="kwrd">namespace</span> Umbraco.Cms.Web.PropertyEditors.GoogleMap
{
    [PropertyEditor(<span
class="str">"E8FA2010-D72E-4F13-9C88-9B79F8466934"</span>, <span
class="str">"GoogleMap"</span>, <span
class="str">"GoogleMap"</span>)]
    <span class="kwrd">public</span> <span
class="kwrd">class</span> GoogleMapEditor : PropertyEditor&lt;GoogleMapEditorModel&gt;
    {
        <span class="kwrd">public</span> <span
class="kwrd">override</span> GoogleMapEditorModel CreateEditorModel()
        {
            <span class="kwrd">return</span> <span
class="kwrd">new</span> GoogleMapEditorModel();
        }

    }
}
</pre>

<p>As you can see a very simple bit of code… And you could now
build this code, and it would work (So to speak) but you would see
a textbox that required some text in the admin and it would have
two hidden inputs which would do nothing! Awesome hey! What we need
to do now is add a custom view to start making this work.</p>

<h2>Adding A Custom View</h2>

<p>To add a custom view for our property editor we just need to
create the view in the 'Views' folder and mark the Editor Model as
an 'EmbeddedView' with the path to the view.&nbsp; So lets do that,
create your View and add it into the views folder keeping the same
naming convention as the actual editor.</p>

<p><strong>GoogleMapEditor.cshtml</strong></p>

<p>And copy and paste the following in and save it</p>

<pre class="csharpcode">
@inherits WebViewPage&lt;Umbraco.Cms.Web.PropertyEditors.GoogleMap.GoogleMapEditorModel&gt;
@<span class="kwrd">using</span> Umbraco.Cms.Web;
@<span class="kwrd">using</span> ClientDependency.Core;
@<span class="kwrd">using</span> ClientDependency.Core.Mvc;
@<span class="kwrd">using</span> System.Web.Helpers;
@<span class="kwrd">using</span> System.Web.Mvc;
@<span class="kwrd">using</span> System.Web.Mvc.Ajax;
@<span class="kwrd">using</span> System.Web.Mvc.Html;
@<span class="kwrd">using</span> System.Web.Routing;
@<span class="kwrd">using</span> System.Web.WebPages;
@<span class="kwrd">using</span> Microsoft.Web.Mvc;
@<span
class="kwrd">using</span> Umbraco.Cms.Web.PropertyEditors.GoogleMap
</pre>

<p>Now in your EditorModel class you just need to decorate the
class with the following (<em>NAMESPACES ARE CASE SENSITIVE, so
make sure you double check them - This has caught me out
before</em>)</p>

<pre class="csharpcode">
    [EmbeddedView(<span
class="str">"Umbraco.Cms.Web.PropertyEditors.GoogleMap.Views.GoogleMapEditor.cshtml"</span>, <span
 class="str">"Umbraco.Cms.Web.PropertyEditors"</span>)]
    <span class="kwrd">public</span> <span
class="kwrd">class</span> GoogleMapEditorModel : EditorModel
</pre>

<p>Hopefully you can see the two main things we have done here, in
the view we have added the '@inherits WebViewPage&lt;&gt;' and on
the EditorModel added '[EmbeddedView()]' I think these are pretty
self explanatory so won't go into anymore detail on these.&nbsp;
But in short, the your telling the view to use the EditorModel as
the 'model' in the view so you have access to all the properties
and also just making sure Umbraco knows that the EditorModel is now
an EmbeddedView with the path to it.</p>

<p>Now things are going to move a little faster here because we are
just going to add the HTML, JS &amp; CSS… Again I mentioned at the
beginning of the blog I wasn't going to go into much detail about
the Google Map stuff as its all in my previous post.&nbsp; So with
that, open up your new custom view and replace it with the
following and save it:</p>

<pre class="csharpcode">
@inherits WebViewPage&lt;Umbraco.Cms.Web.PropertyEditors.GoogleMap.GoogleMapEditorModel&gt;
@<span class="kwrd">using</span> Umbraco.Cms.Web;
@<span class="kwrd">using</span> ClientDependency.Core;
@<span class="kwrd">using</span> ClientDependency.Core.Mvc;
@<span class="kwrd">using</span> System.Web.Helpers;
@<span class="kwrd">using</span> System.Web.Mvc;
@<span class="kwrd">using</span> System.Web.Mvc.Ajax;
@<span class="kwrd">using</span> System.Web.Mvc.Html;
@<span class="kwrd">using</span> System.Web.Routing;
@<span class="kwrd">using</span> System.Web.WebPages;
@<span class="kwrd">using</span> Microsoft.Web.Mvc;
@<span
class="kwrd">using</span> Umbraco.Cms.Web.PropertyEditors.GoogleMap

&lt;script type=<span class="str">"text/javascript"</span>&gt;
    var PostCodeid = <span
class="str">"#@Html.IdFor(x =&gt; Model.Postcode)"</span>;
    var longval = <span
class="str">"#@Html.IdFor(x =&gt; Model.Long)"</span>;
    var latval = <span
class="str">"#@Html.IdFor(x =&gt; Model.Lat)"</span>;
&lt;/script&gt;
&lt;script type=<span
class="str">"text/javascript"</span> src=<span
class="str">"http://maps.google.com/maps/api/js?sensor=false"</span>&gt;&lt;/script&gt;
@{ 
Html
.RequiresJsResource(<span
class="kwrd">typeof</span>(GoogleMapEditor), <span
class="str">"Umbraco.Cms.Web.PropertyEditors.GoogleMap.Resources.gMap.js"</span>)
.RequiresCssResource(<span
class="kwrd">typeof</span>(GoogleMapEditor), <span
class="str">"Umbraco.Cms.Web.PropertyEditors.GoogleMap.Resources.gMap.css"</span>);
}

&lt;p&gt;@Html.TextBoxFor(x =&gt; Model.Postcode, <span
class="kwrd">new</span> { @<span class="kwrd">class</span> = <span
class="str">"postcode"</span> }) &lt;input type=<span
class="str">"submit"</span> id=<span
class="str">"findbutton"</span> <span
class="kwrd">value</span>=<span
class="str">"Find"</span> /&gt;&lt;/p&gt;

&lt;p&gt;@Html.TextBox(<span
class="str">"latTextBox"</span>, Model.Lat, <span
class="kwrd">new</span> { @<span class="kwrd">class</span> = <span
class="str">"latTextBox"</span>, @<span
class="kwrd">readonly</span> =  <span
class="str">"readonly"</span> }) @Html.TextBox(<span
class="str">"longTextBox"</span>, Model.Long, <span
class="kwrd">new</span> { @<span class="kwrd">class</span> = <span
class="str">"longTextBox"</span>, @<span
class="kwrd">readonly</span> = <span
class="str">"readonly"</span> })&lt;/p&gt;

&lt;div id=<span class="str">"geomap"</span> style=<span
class="str">"width: 350px; height: 350px;"</span>&gt;
    &lt;p&gt;
        Loading Please Wait...&lt;/p&gt;
&lt;/div&gt;

@Html.HiddenFor(x =&gt; Model.Lat)
@Html.HiddenFor(x =&gt; Model.Long)
</pre>

<p>As this is a simple view, you should be able to see what
everything is - I'll break down what's on the page starting from
the top</p>

<ul>
<li>We have some global JS variables which get the ID's of elements
we use in our JS code</li>

<li>Reference the Google maps API</li>

<li>Reference the two asset files which we'll add in the next
section (JS &amp; CSS)<br />
 <strong><em>- TIP: Whenever adding resources, note that the
namespace IS case sensitive</em></strong></li>

<li>HTML for the view (Showing the textbox, a find button, two
general textboxes to show the Long &amp; Lat, Div for the map and
the two hidden fields to store the Long &amp; Lat)</li>
</ul>

<p><strong>REMEMBER:</strong> Now we are done, mark this view as an
embedded resource (Right click, properties, build action = embedded
resource)</p>

<h2>Adding Resources</h2>

<p>In this property editor with have two asset/resource files - One
JavaScript file with all the logic to interact with GoogleMaps and
a very simple CSS file just so you can see the autocomplete
dropdown and a bit of other styling.&nbsp; Add the JS &amp; CSS
file in your 'Resources' folder like so&nbsp; 'gMap.css &amp;
gMap.js'</p>

<p><a
href="/media/2797/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_full-structure.jpg">
<img src="/media/2802/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_full-structure_thumb.jpg" width="244" height="148" alt="full-structure" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;"/></a></p>

<p>Now add the contents of them</p>

<h3>gMap.css</h3>

<pre class="csharpcode">
.ui-autocomplete { background-color: white; width: 300px; border: 1px solid #cfcfcf; list-style-type: none; padding-left: 0px; font-family: Arial, Helvetica, sans-serif; cursor: pointer; font-size: 12px; }
.ui-menu-item { padding: 4px 0; }
#geomap { border: 1px #ccc solid;}
input.latTextBox, input.longTextBox { width: 120px !Important;}
</pre>

<h3>gMap.js</h3>

<pre class="csharpcode">
<span class="kwrd">var</span> geocoder;
<span class="kwrd">var</span> map;
<span class="kwrd">var</span> marker;

<span class="kwrd">function</span> initialize() {
    <span class="rem">//MAP</span>
    <span class="kwrd">var</span> initialLat = $(latval).val();
    <span class="kwrd">var</span> initialLong = $(longval).val();
    <span class="kwrd">if</span> (initialLat == <span
class="str">''</span>) {
        initialLat = <span class="str">"51.773071843208115"</span>;
        initialLong = <span
class="str">"-1.6568558468750325"</span>;
    }
    <span class="kwrd">var</span> latlng = <span
class="kwrd">new</span> google.maps.LatLng(initialLat, initialLong);
    <span class="kwrd">var</span> options = {
        zoom: 16,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    map = <span
class="kwrd">new</span> google.maps.Map(document.getElementById(<span
 class="str">"geomap"</span>), options);

    geocoder = <span
class="kwrd">new</span> google.maps.Geocoder();    

    marker = <span class="kwrd">new</span> google.maps.Marker({
        map: map,
        draggable: <span class="kwrd">true</span>,
        position: latlng
    });

    google.maps.<span
class="kwrd">event</span>.addListener(marker, <span
class="str">"dragend"</span>, <span
class="kwrd">function</span> (<span class="kwrd">event</span>) {
        <span class="kwrd">var</span> point = marker.getPosition();
        map.panTo(point);
    });
    
};

$(document).ready(<span class="kwrd">function</span> () {

    initialize();

    $(<span class="kwrd">function</span> () {
        $(PostCodeid).autocomplete({
            <span
class="rem">//This bit uses the geocoder to fetch address values</span>
            source: <span
class="kwrd">function</span> (request, response) {
                geocoder.geocode({ <span
class="str">'address'</span>: request.term }, <span
class="kwrd">function</span> (results, status) {
                    response($.map(results, <span
class="kwrd">function</span> (item) {
                        <span class="kwrd">return</span> {
                            label: item.formatted_address,
                            value: item.formatted_address
                        };
                    }));
                });
            }
        });
    });

    $(<span class="str">'#findbutton'</span>).click(<span
class="kwrd">function</span> (e) {
        <span
class="kwrd">var</span> address = $(PostCodeid).val();
        geocoder.geocode({ <span
class="str">'address'</span>: address }, <span
class="kwrd">function</span> (results, status) {
            <span
class="kwrd">if</span> (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                marker.setPosition(results[0].geometry.location);
                $(latval).val(marker.getPosition().lat());
                $(longval).val(marker.getPosition().lng());
                $(<span
class="str">"input.latTextBox"</span>).val(marker.getPosition().lat());
                $(<span
class="str">"input.longTextBox"</span>).val(marker.getPosition().lng());
            } <span class="kwrd">else</span> {
                alert(<span
class="str">"Geocode was not successful for the following reason: "</span> + status);
            }
        });
        e.preventDefault();
    });

    <span
class="rem">//Add listener to marker for reverse geocoding</span>
    google.maps.<span
class="kwrd">event</span>.addListener(marker, <span
class="str">'drag'</span>, <span class="kwrd">function</span> () {
        geocoder.geocode({ <span
class="str">'latLng'</span>: marker.getPosition() }, <span
class="kwrd">function</span> (results, status) {
            <span
class="kwrd">if</span> (status == google.maps.GeocoderStatus.OK) {
                <span class="kwrd">if</span> (results[0]) {
                    <span
class="rem">//$('#address').val(results[0].formatted_address);</span>
                    $(latval).val(marker.getPosition().lat());
                    $(longval).val(marker.getPosition().lng());
                    $(<span
class="str">"input.latTextBox"</span>).val(marker.getPosition().lat());
                    $(<span
class="str">"input.longTextBox"</span>).val(marker.getPosition().lng());
                }
            }
        });
    });

});
</pre>

<p><strong>Lastly…</strong></p>

<p>After adding any resources you need mark them in the editor as a
WebResource so they get included in the binary, add the following
two lines <strong>above</strong> the <em>'namespace
Umbraco.Cms.Web.PropertyEditors.GoogleMap'</em> line in your
'<em>GoogleMapEditor.cs'</em> file</p>

<pre class="csharpcode">
[assembly: WebResource(<span
class="str">"Umbraco.Cms.Web.PropertyEditors.GoogleMap.Resources.gMap.js"</span>, <span
 class="str">"application/x-javascript"</span>)]
[assembly: WebResource(<span
class="str">"Umbraco.Cms.Web.PropertyEditors.GoogleMap.Resources.gMap.css"</span>, <span
 class="str">"text/css"</span>, PerformSubstitution = <span
class="kwrd">true</span>)]
</pre>

<p><strong>AGAIN REMEMBER:</strong> Now we are done, always mark
ALL your resources (And custom views) as an embedded resource
(Right click, properties, build action = embedded resource)</p>

<h2>See It In Action</h2>

<p>Ok now we have our Property Editor pretty much done, you just
need to build the site (Actually just click the run button to fire
it up) add it to your site as you would do a datatype in a normal
Umbraco site (In the developer section).&nbsp; Add the GoogleMap
Property Editor to the 'Homepage' document type and name it 'gMap',
save and when you view the admin UI you should see the
following:</p>

<p><a
href="/media/2807/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_example-backend.jpg">
<img src="/media/2812/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_example-backend_thumb.jpg" width="271" height="321" alt="example-backend" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;"/></a></p>

<p>Now type and address or postcode and you should start to see the
autocomplete kick in, once you have selected an address click find
to geoCode it - And to fine tune the position drag the marker
around to suit. Then save and publish.</p>

<h2>Using In the Front End</h2>

<p>Getting the values out is very easy in the front end, you just
use the following extension method</p>

<pre class="csharpcode">
Model.Field&lt;<span class="kwrd">string</span>&gt;(<span
class="str">"PropertyAlias"</span>, <span
class="str">"ValueAlias"</span>)
</pre>

<p>Where property Alias is the actual alias of the <strong>property
we added to the DocType</strong> (In our case 'gMap') and
'ValueAlias' is the name of the properties you added in your
<strong>EditorModel</strong> (Ours are 'Postcode, Long &amp; Lat').
So to use these in the front end, we'll just throw the map in the
'Homepage' template.</p>

<p>Open up the template and at the top, under
<strong>'ViewBag.Title'</strong> add the following</p>

<pre class="csharpcode">
    var Long = Model.Field&lt;<span
class="kwrd">string</span>&gt;(<span
class="str">"gMap"</span>, <span class="str">"Long"</span>);
    var Lat = Model.Field&lt;<span
class="kwrd">string</span>&gt;(<span
class="str">"gMap"</span>, <span class="str">"Lat"</span>);
</pre>

<p>And now above the first H2 title add the following:</p>

<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">h2</span><span
class="kwrd">&gt;</span>Google Map<span
class="kwrd">&lt;/</span><span class="html">h2</span><span
class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span
class="html">script</span> <span class="attr">type</span><span
class="kwrd">="text/javascript"</span> <span
class="attr">src</span><span
class="kwrd">="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"</span><span
 class="kwrd">&gt;&lt;/</span><span class="html">script</span><span
class="kwrd">&gt;</span>
&lt;script type=<span
class="str">"text/javascript"</span> src=<span
class="str">"http://maps.google.com/maps/api/js?sensor=false"</span>&gt;&lt;/script&gt;
&lt;script type=<span class="str">"text/javascript"</span>&gt;
    <span class="kwrd">function</span> initialize() {
        <span class="kwrd">var</span> myLatlng = <span
class="kwrd">new</span> google.maps.LatLng(@Html.Raw(Lat.ToString()), @Html.Raw(Long.ToString()));
        <span class="kwrd">var</span> myOptions = {
            zoom: 13,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        <span class="kwrd">var</span> map = <span
class="kwrd">new</span> google.maps.Map(document.getElementById(<span
 class="str">"contactmap"</span>), myOptions);

        <span class="kwrd">var</span> homestring = <span
class="str">'Your Location'</span>;
        <span class="kwrd">var</span> homeinfowindow = <span
class="kwrd">new</span> google.maps.InfoWindow({ content: homestring });
        <span class="kwrd">var</span> homemarker = <span
class="kwrd">new</span> google.maps.Marker({
            position: myLatlng,
            map: map
        });
        google.maps.<span
class="kwrd">event</span>.addListener(homemarker, <span
class="str">'click'</span>, <span class="kwrd">function</span> () {
            homeinfowindow.open(map, homemarker);
        });

    }

    $(document).ready(<span class="kwrd">function</span> () {
        initialize();
    });
<span class="kwrd">&lt;/</span><span
class="html">script</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;</span><span class="html">div</span> <span
class="attr">id</span><span class="kwrd">="contactmap"</span> <span
class="attr">style</span><span
class="kwrd">="width:400px; height: 300px; border:2px #ccc solid;"</span><span
 class="kwrd">&gt;&lt;/</span><span class="html">div</span><span
class="kwrd">&gt;</span>
</pre>

<p>Tada..</p>

<p><a
href="/media/2817/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_example-font-end.jpg">
<img src="/media/2822/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_example-font-end_thumb.jpg" width="354" height="291" alt="example-font-end" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;"/></a></p>

<p>As you can see its very simple, and maybe not how you would do
it in a real site but it shows you how to get your values back out
in a view - I hope this blog post helps you get started playing
with property editors, and please let me know your comments below,
and if I have missed or got something wrong.</p>

<h2>Extending Further…</h2>

<p>In the next post we'll be extending this property editor by
adding pre-values, manipulating the content before we save it and a
few other things.</p>

<p>Happy Coding <img src="/media/2827/Windows-Live-Writer_Creating-A-Google-Map-Property-Editor-Fo_58FC_wlEmoticon-smile_2.png" alt="Smile" class="wlEmoticon wlEmoticon-smile" style="border-style: none;"/></p>
]]></description></item><item><title>An Autocomplete Geocoding Google Map With Draggable Marker</title><link>http://www.blogfodder.co.uk/2011/11/19/an-autocomplete-geocoding-google-map-with-draggable-marker</link><pubDate>Sat, 19 Nov 2011 00:00:00 GMT</pubDate><guid>http://www.blogfodder.co.uk/2011/11/19/an-autocomplete-geocoding-google-map-with-draggable-marker</guid><description><![CDATA[ 
<p>While tinkering and trying to get a Google Map property editor
working working for Umbraco v5, I actually ended up writing more
JavaScript to get it working - And thought the code is actually
pretty useful for any app and not just as an Umbraco DataType.</p>

<p><strong>So what does this actually do?</strong></p>

<ol>
<li>Has an autocomplete text box that you can either choose from
the location results, or just type in a postcode</li>

<li>When you click find it takes the address, postcode whatever and
Geocodes it</li>

<li>Then adds a draggable marker on the map and also stores the
long &amp; lat in hidden values</li>

<li>If you drag the marker, it saves the new long &amp; lat in the
hidden values</li>
</ol>

<p><a
href="/media/2729/Windows-Live-Writer_Creating-A-Draggable-Google-Map-Marker_728A_goog-map_2.jpg">
<img src="/media/2734/Windows-Live-Writer_Creating-A-Draggable-Google-Map-Marker_728A_goog-map_thumb.jpg" width="343" height="372" alt="goog-map" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;"/></a></p>

<p><a
href="/media/2739/Windows-Live-Writer_Creating-A-Draggable-Google-Map-Marker_728A_goo-draggable_2.jpg">
<img src="/media/2744/Windows-Live-Writer_Creating-A-Draggable-Google-Map-Marker_728A_goo-draggable_thumb.jpg" width="341" height="370" alt="goo-draggable" border="0" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;"/></a></p>

<h2>HTML / styles</h2>

<p>Very simple bit of HTML and some basic styles so you can see the
autocomplete dropdown on the textbox, textbox for the
address/postcode and a find button. div to show the map and the two
hidden inputs to store the long and lats in</p>

<pre class="csharpcode">
        <span class="kwrd">&lt;</span><span
class="html">style</span><span class="kwrd">&gt;</span>
            .ui-autocomplete {
                background-color: white;
                width: 300px;
                border: 1px solid #cfcfcf;
                list-style-type: none;
                padding-left: 0px; font-family:Arial, Helvetica, sans-serif; cursor:pointer; font-size:12px;
            }
            .ui-menu-item {padding:3px 0;}
        <span class="kwrd">&lt;/</span><span
class="html">style</span><span class="kwrd">&gt;</span>

        <span class="kwrd">&lt;</span><span
class="html">p</span><span class="kwrd">&gt;&lt;</span><span
class="html">input</span> <span class="attr">class</span><span
class="kwrd">="postcode"</span> <span class="attr">id</span><span
class="kwrd">="Postcode"</span> <span class="attr">name</span><span
class="kwrd">="Postcode"</span> <span class="attr">type</span><span
class="kwrd">="text"</span><span class="kwrd">&gt;</span> <span
class="kwrd">&lt;</span><span class="html">input</span> <span
class="attr">type</span><span class="kwrd">="submit"</span> <span
class="attr">id</span><span class="kwrd">="findbutton"</span> <span
class="attr">value</span><span class="kwrd">="Find"</span> <span
class="kwrd">/&gt;&lt;/</span><span class="html">p</span><span
class="kwrd">&gt;</span>
        
        <span class="kwrd">&lt;</span><span
class="html">div</span> <span class="attr">id</span><span
class="kwrd">="geomap"</span> <span class="attr">style</span><span
class="kwrd">="width:400px; height:400px;"</span><span
class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span><span
class="html">p</span><span
class="kwrd">&gt;</span>Loading Please Wait...<span
class="kwrd">&lt;/</span><span class="html">p</span><span
class="kwrd">&gt;</span>
        <span class="kwrd">&lt;/</span><span
class="html">div</span><span class="kwrd">&gt;</span>
        
        <span class="kwrd">&lt;</span><span
class="html">input</span> <span class="attr">id</span><span
class="kwrd">="hidLat"</span> <span class="attr">name</span><span
class="kwrd">="hidLat"</span> <span class="attr">type</span><span
class="kwrd">="hidden"</span> <span class="attr">value</span><span
class="kwrd">=""</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span
class="html">input</span> <span class="attr">id</span><span
class="kwrd">="hidLong"</span> <span class="attr">name</span><span
class="kwrd">="hidLong"</span> <span class="attr">type</span><span
class="kwrd">="hidden"</span> <span class="attr">value</span><span
class="kwrd">=""</span><span class="kwrd">&gt;</span>     
</pre>

<h2>JavaScript</h2>

<p>We use the google maps API, Jquery &amp; Jquery UI which we can
get from the google CDN. In the initialise method I have added in
some default values so when the map first loads it has a marker by
default, you can obviously remove all this.</p>

<pre class="csharpcode">
        &lt;script type=<span
class="str">"text/javascript"</span> src=<span
class="str">"http://maps.google.com/maps/api/js?sensor=false"</span>&gt;&lt;/script&gt;
        &lt;script type=<span
class="str">"text/javascript"</span> src=<span
class="str">"https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"</span>&gt;&lt;/script&gt;
        &lt;script type=<span
class="str">"text/javascript"</span> src=<span
class="str">"https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"</span>&gt;&lt;/script&gt;                
        &lt;script type=<span
class="str">"text/javascript"</span>&gt;
        <span class="kwrd">var</span> PostCodeid = <span
class="str">"#Postcode"</span>;
        <span class="kwrd">var</span> longval = <span
class="str">"#hidLong"</span>;
        <span class="kwrd">var</span> latval = <span
class="str">"#hidLat"</span>;
        <span class="kwrd">var</span> geocoder;
        <span class="kwrd">var</span> map;
        <span class="kwrd">var</span> marker;

        <span class="kwrd">function</span> initialize() {
            <span class="rem">//MAP</span>
            <span
class="kwrd">var</span> initialLat = $(latval).val();
            <span
class="kwrd">var</span> initialLong = $(longval).val();
            <span class="kwrd">if</span> (initialLat == <span
class="str">''</span>) {
                initialLat = <span
class="str">"51.773071843208115"</span>;
                initialLong = <span
class="str">"-1.6568558468750325"</span>;
            }
            <span class="kwrd">var</span> latlng = <span
class="kwrd">new</span> google.maps.LatLng(initialLat, initialLong);
            <span class="kwrd">var</span> options = {
                zoom: 16,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
        
            map = <span
class="kwrd">new</span> google.maps.Map(document.getElementById(<span
 class="str">"geomap"</span>), options);
        
            geocoder = <span
class="kwrd">new</span> google.maps.Geocoder();    
        
            marker = <span
class="kwrd">new</span> google.maps.Marker({
                map: map,
                draggable: <span class="kwrd">true</span>,
                position: latlng
            });
        
            google.maps.<span
class="kwrd">event</span>.addListener(marker, <span
class="str">"dragend"</span>, <span
class="kwrd">function</span> (<span class="kwrd">event</span>) {
                <span
class="kwrd">var</span> point = marker.getPosition();
                map.panTo(point);
            });
            
        };
        
        $(document).ready(<span class="kwrd">function</span> () {
        
            initialize();
        
            $(<span class="kwrd">function</span> () {
                $(PostCodeid).autocomplete({
                    <span
class="rem">//This bit uses the geocoder to fetch address values</span>
                    source: <span
class="kwrd">function</span> (request, response) {
                        geocoder.geocode({ <span
class="str">'address'</span>: request.term }, <span
class="kwrd">function</span> (results, status) {
                            response($.map(results, <span
class="kwrd">function</span> (item) {
                                <span class="kwrd">return</span> {
                                    label: item.formatted_address,
                                    value: item.formatted_address
                                };
                            }));
                        });
                    }
                });
            });
        
            $(<span class="str">'#findbutton'</span>).click(<span
class="kwrd">function</span> (e) {
                <span
class="kwrd">var</span> address = $(PostCodeid).val();
                geocoder.geocode({ <span
class="str">'address'</span>: address }, <span
class="kwrd">function</span> (results, status) {
                    <span
class="kwrd">if</span> (status == google.maps.GeocoderStatus.OK) {
                        map.setCenter(results[0].geometry.location);
                        marker.setPosition(results[0].geometry.location);
                        $(latval).val(marker.getPosition().lat());
                        $(longval).val(marker.getPosition().lng());
                    } <span class="kwrd">else</span> {
                        alert(<span
class="str">"Geocode was not successful for the following reason: "</span> + status);
                    }
                });
                e.preventDefault();
            });
        
            <span
class="rem">//Add listener to marker for reverse geocoding</span>
            google.maps.<span
class="kwrd">event</span>.addListener(marker, <span
class="str">'drag'</span>, <span class="kwrd">function</span> () {
                geocoder.geocode({ <span
class="str">'latLng'</span>: marker.getPosition() }, <span
class="kwrd">function</span> (results, status) {
                    <span
class="kwrd">if</span> (status == google.maps.GeocoderStatus.OK) {
                        <span class="kwrd">if</span> (results[0]) {
                            $(latval).val(marker.getPosition().lat());
                            $(longval).val(marker.getPosition().lng());
                        }
                    }
                });
            });
        
        });

    &lt;/script&gt;
</pre>

<p>Just grab all the code above, throw it in a HTML file and open
it in your favorite browser and you'll see how it works</p>
]]></description></item></channel></rss>

