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

<channel>
	<title>Dave Russell &#187; .Net</title>
	<atom:link href="http://daverussell.co.za/wordpress/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://daverussell.co.za/wordpress</link>
	<description>Helping me remember and hopefully helping others at the same time.</description>
	<lastBuildDate>Thu, 14 Apr 2011 07:16:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Converting HTML to PDF using EvoPdf</title>
		<link>http://daverussell.co.za/wordpress/2011/04/14/converting-html-to-pdf-using-evopdf/</link>
		<comments>http://daverussell.co.za/wordpress/2011/04/14/converting-html-to-pdf-using-evopdf/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 07:14:47 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[evopdf]]></category>
		<category><![CDATA[pdf converter]]></category>

		<guid isPermaLink="false">http://daverussell.co.za/wordpress/?p=212</guid>
		<description><![CDATA[We have been using ABCpdf to generate PDFs on the fly of the page currently being browsed. It has given us years of service, but now with the new version of our site I have had to find an alternative solution as my page body gets styled out of sight and then moved into position [...]]]></description>
			<content:encoded><![CDATA[<p>We have been using ABCpdf to generate PDFs on the fly of the page currently being browsed. It has given us years of service, but now with the new version of our site I have had to find an alternative solution as my page body gets styled out of sight and then moved into position using jquery to change the left:-2000px to left:0px;. ABCpdf ignores javascript so I am getting a lovely half generated page in the PDF output.</p>
<p><img alt="The PDF generater that speaks javascript" src="http://www.evopdf.com/images/logo.jpg" title="EvoPdf" class="alignleft" width="310" height="90" />The only product I have found out there on the interwebs that understands javascript is <a href="http://www.evopdf.com">EvoPdf</a>. I have downloaded the zip file of 52mb done the install &#8211; which by the way could not be easier: add reference to dll, copy another, and then call the following method:</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">using</span> <span class="co3">EvoPdf.HtmlToPdf</span><span class="sy0">;</span></p>
<p><span class="kw1">private</span> <span class="kw1">void</span> ConvertURLToPDF<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">string</span> urlToConvert <span class="sy0">=</span> Request<span class="br0">&#91;</span><span class="st0">&quot;url&quot;</span><span class="br0">&#93;</span><span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; PdfConverter pdfConverter <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> PdfConverter<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">LicenseKey</span> <span class="sy0">=</span> <span class="st0">&quot;xxxxxxx&quot;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">PdfDocumentOptions</span>.<span class="me1">PdfPageSize</span> <span class="sy0">=</span> PdfPageSize.<span class="me1">A4</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">PdfDocumentOptions</span>.<span class="me1">PdfCompressionLevel</span> <span class="sy0">=</span> PdfCompressionLevel.<span class="me1">Normal</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">PdfDocumentOptions</span>.<span class="me1">PdfPageOrientation</span> <span class="sy0">=</span> PdfPageOrientation.<span class="me1">Portrait</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">PdfDocumentOptions</span>.<span class="me1">LiveUrlsEnabled</span> <span class="sy0">=</span> true<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">JavaScriptEnabled</span> <span class="sy0">=</span> true<span class="sy0">;</span> <span class="co1">//the important bit &#8211; waits for javascript</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">ConversionDelay</span> <span class="sy0">=</span> <span class="nu0">10</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">InterruptSlowJavaScript</span> <span class="sy0">=</span> false<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">PdfDocumentOptions</span>.<span class="me1">JpegCompressionEnabled</span> <span class="sy0">=</span> true<span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; pdfConverter.<span class="me1">PdfDocumentOptions</span>.<span class="me1">FitWidth</span> <span class="sy0">=</span> true<span class="sy0">;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">byte</span><span class="br0">&#91;</span><span class="br0">&#93;</span> pdfBytes <span class="sy0">=</span> pdfConverter.<span class="me1">GetPdfBytesFromUrl</span><span class="br0">&#40;</span>urlToConvert<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw5">System.<span class="me1">Web</span></span>.<span class="me1">HttpResponse</span> response <span class="sy0">=</span> <span class="kw5">System.<span class="me1">Web</span></span>.<span class="me1">HttpContext</span>.<span class="me1">Current</span>.<span class="me1">Response</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">Clear</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">AddHeader</span><span class="br0">&#40;</span><span class="st0">&quot;Content-Type&quot;</span>, <span class="st0">&quot;application/pdf&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">AddHeader</span><span class="br0">&#40;</span><span class="st0">&quot;Content-Disposition&quot;</span>, <span class="kw4">String</span>.<span class="me1">Format</span><span class="br0">&#40;</span><span class="st0">&quot;attachment; filename=Output.pdf; size={0}&quot;</span>, pdfBytes.<span class="me1">Length</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">BinaryWrite</span><span class="br0">&#40;</span>pdfBytes<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; response.<span class="me1">End</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>The license is a little hefty, but you can trail the full version to see if it suits your needs before dusting off the credit card &#8211; the only thing is the outputed PDF will have a watermark over it until you get a license.</p>
]]></content:encoded>
			<wfw:commentRss>http://daverussell.co.za/wordpress/2011/04/14/converting-html-to-pdf-using-evopdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax using .Net and jQuery &#8211; Revised and improved with help from Json</title>
		<link>http://daverussell.co.za/wordpress/2009/12/03/ajax-using-net-and-jquery-revised-and-improved-with-help-from-json/</link>
		<comments>http://daverussell.co.za/wordpress/2009/12/03/ajax-using-net-and-jquery-revised-and-improved-with-help-from-json/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 14:26:25 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://daverussell.co.za/wordpress/?p=76</guid>
		<description><![CDATA[I previously wrote a post outlining a simpler method of making asynchronous calls with jQuery. It turns out that in practice that method was exactly that &#8211; too simple. It works fine when you only need one value back, but if you need to work with something a little more complex then try out my [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://daverussell.co.za/wordpress/2009/07/28/ajax-using-dotnet-and-jquery/">previously wrote a post</a> outlining a simpler method of making asynchronous calls with <a href="http://www.jquery.com">jQuery</a>. It turns out that in practice that method was exactly that &#8211; too simple. It works fine when you only need one value back, but if you need to work with something a little more complex then try out my new method that uses a <a href="http://json.org">JSON object</a>.  So the basic overview is as follows: </p>
<ol>
<li>create an object server-side on page load and add it to the DOM</li>
<li>populate the object using javascript</li>
<li>pass it back to a webservice using jquery&#8217;s ajax method and json</li>
<li>use the new object serverside and pass it back</li>
</ol>
<p>Ok, so lets get started by creating the object in your webservice:</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw4">class</span> Person<br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">string</span> Name <span class="br0">&#123;</span> get<span class="sy0">;</span> set<span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">string</span> ContactNumber <span class="br0">&#123;</span> get<span class="sy0">;</span> set<span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">string</span> Description <span class="br0">&#123;</span> get<span class="sy0">;</span> set<span class="sy0">;</span> <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
<p>Then in your page load you can inject this object into the DOM:</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;">var objPerson <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Webservice.<span class="me1">Person</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
var js <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> JavaScriptSerializer<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
Page.<span class="me1">ClientScript</span>.<span class="me1">RegisterArrayDeclaration</span><span class="br0">&#40;</span><span class="st0">&quot;_person&quot;</span>, js.<span class="me1">Serialize</span><span class="br0">&#40;</span>objPerson<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>Now you can use this object with javascript:</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;">&#8230;</p>
<p><span class="kw2">function</span> AjaxMethodJSON<span class="br0">&#40;</span>serviceFn<span class="sy0">,</span> paramArray<span class="sy0">,</span> successFn<span class="sy0">,</span> errorFn<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; $.<span class="me1">ajax</span><span class="br0">&#40;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; type<span class="sy0">:</span> <span class="st0">&quot;POST&quot;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; url<span class="sy0">:</span> serviceFn<span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; contentType<span class="sy0">:</span> <span class="st0">&quot;application/json; charset=utf-8&quot;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; data<span class="sy0">:</span> <span class="st0">&quot;{&#8216;clientobject&#8217;:&quot;</span> <span class="sy0">+</span> JSON.<span class="me1">stringify</span><span class="br0">&#40;</span>paramArray<span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;}&quot;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataType<span class="sy0">:</span> <span class="st0">&quot;json&quot;</span><span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; success<span class="sy0">:</span> successFn<span class="sy0">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; error<span class="sy0">:</span> errorFn<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><br />
<span class="sy0">;</span></p>
<p>&#8230;<br />
$<span class="br0">&#40;</span><span class="st0">&quot;#btnSubmit&quot;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; objPerson.<span class="kw3">Name</span> <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">&#8216;#txtName&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; objPerson.<span class="me1">ContactNumber</span> <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">&#8216;#txtContactNumber&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; objPerson.<span class="me1">Description</span> <span class="sy0">=</span> $<span class="br0">&#40;</span><span class="st0">&#8216;#txtDescription&#8217;</span><span class="br0">&#41;</span>.<span class="me1">val</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; AjaxMethodJSON<span class="br0">&#40;</span><span class="st0">&quot;/webservices/Webservice.asmx/UpdatePerson&quot;</span><span class="sy0">,</span> objPerson<span class="sy0">,</span> AjaxSuccessStep<span class="sy0">,</span> AjaxFailed<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>If you have been paying attention you may be thinking &#8211; stringify? The official explanation from <a href="http://www.json.org/js.html">json.org</a>: If the stringify method sees an object that contains a toJSON method, it calls that method, and stringifies the value returned. This allows an object to determine its own JSON representation. So remember to add a reference to <a href="http://www.json.org/js.html">json2.js</a> upstream from this code.</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="kw2">function</span> AjaxSuccessStep<span class="br0">&#40;</span>result<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>result <span class="sy0">!=</span> <span class="kw2">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> obj <span class="sy0">=</span> result.<span class="me1">d</span><span class="sy0">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; objPerson <span class="sy0">=</span> JSON.<span class="me1">parse</span><span class="br0">&#40;</span>obj<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="co1">//got the updated object back, now you can &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><br />
<span class="co1">//do some more stuff with it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
<p>There you go. This works very well when you are stepping through a wizard and updating a few fields with each step.</p>
]]></content:encoded>
			<wfw:commentRss>http://daverussell.co.za/wordpress/2009/12/03/ajax-using-net-and-jquery-revised-and-improved-with-help-from-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tech-Ed Day 2</title>
		<link>http://daverussell.co.za/wordpress/2009/08/04/tech-ed-day-2/</link>
		<comments>http://daverussell.co.za/wordpress/2009/08/04/tech-ed-day-2/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 08:47:45 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://davidrussellr.wordpress.com/?p=47</guid>
		<description><![CDATA[What a full day &#8211; to be honest its all a blur. But fear not I tweeted up a storm and will revisit this post and update once the dust has settled. Suffice to say there were some awesome talks (and some not so awesome ). I seized a gap in lectures in the afternoon [...]]]></description>
			<content:encoded><![CDATA[<p>What a full day &#8211; to be honest its all a blur. But fear not<a title="Tweet Tweet" href="http://www.twitter.com/daverussellr" target="_blank"> I tweeted up a storm</a> and will revisit this post and update once the dust has settled. Suffice to say there were some awesome talks (and some not so awesome <img src='http://daverussell.co.za/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p>
<p>I seized a gap in lectures in the afternoon and took my sedatory body for a run along the beachfront and a dip in the ocean. What a pleasure to just go for a swim and not fear loosing extraneous body bits to frostbite &#8211; and this is in the middle of &#8216;winter&#8217;. Turns out I needed the mental refresh as I headed back to attend a session by Gail Shaw on Query hints &#8211; I know nothing about sql in comparison to her. mercy.</p>
<p>I got taken out for dinner by the gang at <a title="IS Partners" href="http://www.ispartners.co.za/" target="_blank">IS Partners</a> to a great little italian place on Florida Road, which seems to be Durban&#8217;s version of Kloof street. Shot guys, I had a really good evening &#8211; if Cape Town ever ends up under water due to global warming &#8211; I will come and see if I can be of any value.</p>
]]></content:encoded>
			<wfw:commentRss>http://daverussell.co.za/wordpress/2009/08/04/tech-ed-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tech-Ed 2009</title>
		<link>http://daverussell.co.za/wordpress/2009/08/03/tech-ed-2009/</link>
		<comments>http://daverussell.co.za/wordpress/2009/08/03/tech-ed-2009/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 09:58:19 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://davidrussellr.wordpress.com/?p=45</guid>
		<description><![CDATA[So here I am, Durban by the sea, for the 09 instalment of Microsoft&#8217;s Tech-Ed. I have not been in Durbs for many years, but there&#8217;s something about the place that agrees with me, stepping of the plane you are welcomed by a thick blanket of humidy &#8211; and it&#8217;s the middle of winter. I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-44" title="Mad Street Names" src="http://davidrussellr.files.wordpress.com/2009/08/dsc002451.jpg?w=300" alt="Mad Street Names" width="300" height="225" />So here I am, Durban by the sea, for the 09 instalment of Microsoft&#8217;s Tech-Ed. I have not been in Durbs for many years, but there&#8217;s something about the place that agrees with me, stepping of the plane you are welcomed by a thick blanket of humidy &#8211; and it&#8217;s the middle of winter. I bought a great book to keep me company on the long flight (which included a stop in the friendly city), its inspirational to read stories where people have taken hold of dreams and not let situations deter then from success.</p>
<p>I met Ugene from lightstone (?) on the flight who was also on the way to the event. He was a dead give away &#8211; after taking an hour to totally absorb every word he computer mag the whipped out his laptop and plugged himself into a movie. I introduced myself and guessed his reason for traveling to Durban and was right. Turns out that he has been to the last seven tech-eds. Grief, he deserves an award of some sort &#8211; matching microsoft mousepads or something. He was totally amped and said the parties are not to be missed.. I smiled and nodded, but remained a little sceptical.</p>
<p>The opening keynote had all the expected elements: big audio visuals, microsoft evangelism, a couple google bashing jokes and demos that mostly worked. There were some very cool things, the ones that come to mind are:<br />
Visual Studio 2010<br />
Control click to auto generate new methods and properties<br />
Windows 7<br />
making use of gestures<br />
Project Gemini (Donald Farmer)<br />
100 million rows in excel, sorted and filtered instantaniously.<br />
Expression Blend Sketching storyboards</p>
<p>I had dinner with my brother, Gavin, and was introduced to Gail Shaw &#8211; one of two Microsoft sql mvp&#8217;s in the country. It is so amusing to see uber geeks getting there annual chance to be rock stars amongst the few people that actually get what they do. After spending some time with the guys from IS partners, I called it a night made my way back to the city lodge in the warm drizzle.</p>
<p>Tomorrow it begins in ernest with sessions every hour from eight till five. Hoping to get a gap to go for a dip in the warm ocean&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://daverussell.co.za/wordpress/2009/08/03/tech-ed-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax using .Net and jQuery</title>
		<link>http://daverussell.co.za/wordpress/2009/07/28/ajax-using-dotnet-and-jquery/</link>
		<comments>http://daverussell.co.za/wordpress/2009/07/28/ajax-using-dotnet-and-jquery/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 11:50:10 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[less bloat]]></category>
		<category><![CDATA[more goodness]]></category>

		<guid isPermaLink="false">http://davidrussellr.wordpress.com/?p=34</guid>
		<description><![CDATA[I am not a fan of the classic method of implementing ajax in .net &#8211; scriptmanagers and updatepanels. The load on the front end is pretty big (100kb+), especially considering local bandwidth restrictions and challenges. So I set out to find a better way as one does when one feels that something is not quite [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a fan of the classic method of implementing ajax in .net &#8211; scriptmanagers and updatepanels. The load on the front end is pretty big (100kb+), especially considering local bandwidth restrictions and challenges. So I set out to find a better way as one does when one feels that something is not quite right.</p>
<p>So it turns out that jQuery comes to the rescue &#8211; again.</p>
<div class="codesnip-container" >
<div class="html4strict codesnip" style="font-family:monospace;"><span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;clickme1&quot;</span>&gt;</span>whats the time? (using code behind)<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;clickme2&quot;</span>&gt;</span>whats the time? (using a webservice)<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;result&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;border:1px solid red;padding:5px;&quot;</span>&gt;</span>nothing yet<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/div.html"><span class="kw2">div</span></a>&gt;</span><br />
<span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;/js/v4/jquery.132.min.js&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span> <span class="sc2">&lt;<a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>// <span class="sc2">&lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span></span><br />
<span class="sc2">function AjaxSucceeded<span class="br0">&#40;</span>result<span class="br0">&#41;</span> <span class="br0">&#123;</span>$<span class="br0">&#40;</span><span class="st0">&#8216;#result&#8217;</span><span class="br0">&#41;</span>.html<span class="br0">&#40;</span><span class="st0">&quot;good &quot;</span> + result.d<span class="br0">&#41;</span>;<span class="br0">&#125;</span></span><br />
<span class="sc2">function AjaxFailed<span class="br0">&#40;</span>result<span class="br0">&#41;</span> <span class="br0">&#123;</span>$<span class="br0">&#40;</span><span class="st0">&#8216;#result&#8217;</span><span class="br0">&#41;</span>.html<span class="br0">&#40;</span><span class="st0">&quot;bad &quot;</span> + result.d<span class="br0">&#41;</span>;<span class="br0">&#125;</span></span></p>
<p><span class="sc2">function AjaxMethod<span class="br0">&#40;</span>serviceFn, paramArray, successFn, errorFn<span class="br0">&#41;</span> <span class="br0">&#123;</span></span><br />
<span class="sc2"> &nbsp; &nbsp;var paramList <span class="sy0">=</span> <span class="st0">&#8221;</span>;</span><br />
<span class="sc2"> &nbsp; &nbsp;if <span class="br0">&#40;</span>paramArray.length &gt;</span> 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i <span class="sc2">&lt; paramArray.length; i +<span class="sy0">=</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if <span class="br0">&#40;</span>paramList.length &gt;</span> 0) paramList += &#8216;,&#8217;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; paramList += &#8216;&quot;&#8217; + paramArray[i] + &#8216;&quot;:&quot;&#8217; + paramArray[i + 1] + &#8216;&quot;&#8217;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; paramList = &#8216;{&#8216; + paramList + &#8216;}&#8217;;</p>
<p>&nbsp; &nbsp; $.ajax({<br />
&nbsp; &nbsp; &nbsp; &nbsp; type: &quot;POST&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; url: serviceFn,<br />
&nbsp; &nbsp; &nbsp; &nbsp; contentType: &quot;application/json; charset=utf-8&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; data: paramList,<br />
&nbsp; &nbsp; &nbsp; &nbsp; dataType: &quot;json&quot;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; success: successFn,<br />
&nbsp; &nbsp; &nbsp; &nbsp; error: errorFn<br />
&nbsp; &nbsp; })<br />
;}</p>
<p>$(document).ready(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(&#8216;#clickme2&#8242;).click(function() { AjaxMethod(&quot;/webservices/webservice.asmx/GetDate&quot;, [], AjaxSucceeded, AjaxFailed); });<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(&#8216;#clickme1&#8242;).click(function() { AjaxMethod(window.location.pathname + &quot;/GetDate&quot;, [], AjaxSucceeded, AjaxFailed); });<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
// ]]&gt;<span class="sc2">&lt;<span class="sy0">/</span><a href="http://december.com/html/4/element/script.html"><span class="kw2">script</span></a>&gt;</span></div>
</div>
<p>Using a webservice (clickme2 event):</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>ScriptService<span class="br0">&#93;</span><br />
<span class="br0">&#91;</span>WebService<span class="br0">&#40;</span><span class="kw1">Namespace</span> <span class="sy0">=</span> <span class="st0">&quot;http://tempuri.org/&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="br0">&#91;</span>WebServiceBinding<span class="br0">&#40;</span>ConformsTo <span class="sy0">=</span> WsiProfiles.<span class="me1">BasicProfile1_1</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">class</span> WebService <span class="sy0">:</span> <span class="kw5">System.<span class="me1">Web</span>.<span class="me1">Services</span></span>.<span class="me1">WebService</span><br />
<span class="br0">&#123;</span><br />
<span class="br0">&#91;</span>WebMethod<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw4">string</span> GetDate<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">return</span> DateTime.<span class="me1">Now</span>.<span class="me1">ToLocalTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>And the code behind  (clickme1 event)::</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>WebMethod<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">string</span> GetDate<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">return</span> DateTime.<span class="me1">Now</span>.<span class="me1">ToLocalTime</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>And there you go &#8211; ajax functionality without the bloat. This code has yet to make it into the harsh light of a production environment, but I have successfully used it to return not just one value, but xml data too (see example below), which opens up huge possibilities for front end goodness. The method below makes use of caching which increases performance hugely, but that&#8217;s a topic for another day.</p>
<div class="codesnip-container" >
<div class="javascript codesnip" style="font-family:monospace;"><span class="kw2">function</span> ShowMyPosts<span class="br0">&#40;</span>result<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> output <span class="sy0">=</span> <span class="st0">&quot;&quot;</span><span class="sy0">;</span></p>
<p>$<span class="br0">&#40;</span>result.<span class="me1">d</span><span class="br0">&#41;</span>.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&#8216;item&#8217;</span><span class="br0">&#41;</span>.<span class="me1">each</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
<span class="kw2">var</span> title<span class="sy0">=</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">attr</span><span class="br0">&#40;</span><span class="st0">&#8216;title&#8217;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw2">var</span> link<span class="sy0">=</span> $<span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span>.<span class="me1">find</span><span class="br0">&#40;</span><span class="st0">&#8216;link&#8217;</span><span class="br0">&#41;</span>.<span class="me1">text</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
output <span class="sy0">+=</span> <span class="st0">&quot;<br />
&lt;div&gt;&quot;</span> <span class="sy0">+</span> title <span class="sy0">+</span> <span class="st0">&quot; : &quot;</span> <span class="sy0">+</span> title<span class="sy0">+</span> <span class="st0">&quot; : &quot;</span> <span class="sy0">+</span> link <span class="sy0">+</span> <span class="st0">&quot;&lt;/div&gt;<br />
&quot;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>$<span class="br0">&#40;</span><span class="st0">&#8216;#result&#8217;</span><span class="br0">&#41;</span>.<span class="me1">html</span><span class="br0">&#40;</span>output<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></p>
<p>$<span class="br0">&#40;</span>document<span class="br0">&#41;</span>.<span class="me1">ready</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
$<span class="br0">&#40;</span><span class="st0">&#8216;#clickme3&#8242;</span><span class="br0">&#41;</span>.<span class="me1">click</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> AjaxMethod<span class="br0">&#40;</span>window.<span class="me1">location</span>.<span class="me1">pathname</span> <span class="sy0">+</span> <span class="st0">&quot;/GetXML&quot;</span><span class="sy0">,</span> <span class="br0">&#91;</span><span class="st0">&quot;url&quot;</span><span class="sy0">,</span> <span class="st0">&quot;http://davidrussellr.wordpress.com/feed/&quot;</span><span class="sy0">,</span> <span class="st0">&quot;cachename&quot;</span><span class="sy0">,</span> <span class="st0">&quot;test2&quot;</span><span class="br0">&#93;</span><span class="sy0">,</span> ShowMyPosts<span class="sy0">,</span> AjaxFailed<span class="br0">&#41;</span><span class="sy0">;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</div>
<p>And the code behind:</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>WebMethod<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">string</span> GetXML<span class="br0">&#40;</span><span class="kw4">string</span> url, <span class="kw4">string</span> cachename<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
XmlDocument xmlDoc <span class="sy0">=</span> FetchXML.<span class="me1">ReturnXmlDoc</span><span class="br0">&#40;</span>url, cachename<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw1">return</span> xmlDoc.<span class="me1">InnerXml</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://daverussell.co.za/wordpress/2009/07/28/ajax-using-dotnet-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net, HTML mails and embedded images</title>
		<link>http://daverussell.co.za/wordpress/2009/07/28/net-html-mails-and-embedded-images/</link>
		<comments>http://daverussell.co.za/wordpress/2009/07/28/net-html-mails-and-embedded-images/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 10:50:27 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[embedded images]]></category>
		<category><![CDATA[html email]]></category>

		<guid isPermaLink="false">http://davidrussellr.wordpress.com/?p=22</guid>
		<description><![CDATA[So recently I needed to take an image uploaded by the client and embed it into an email as part of a &#8216;send to a friend&#8217; type piece of functionality. After much trial and error I managed to put all the pieces together &#8211; the tricky bit is taking an image that only lives in [...]]]></description>
			<content:encoded><![CDATA[<p>So recently I needed to take an image uploaded by the client and embed it into an email as part of a &#8216;send to a friend&#8217; type piece of functionality. After much trial and error I managed to put all the pieces together &#8211; the tricky bit is taking an image that only lives in memory, attaching it to an email and then referencing that image from the html.</p>
<p>So here goes: (ImageData in the example method is the base64 encoded image data that was uploaded)</p>
<div class="codesnip-container" >
<div class="csharp codesnip" style="font-family:monospace;"><span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">bool</span> SendHTMLMailWithEmbeddedImage<span class="br0">&#40;</span><span class="kw4">string</span> ContactEmail, <span class="kw4">string</span> FriendEmail, <span class="kw4">string</span> ImageData<span class="br0">&#41;</span></p>
<p><span class="br0">&#123;</span></p>
<p><span class="kw1">try</span><br />
<span class="br0">&#123;</span></p>
<p><span class="kw4">byte</span><span class="br0">&#91;</span><span class="br0">&#93;</span> imageBytes <span class="sy0">=</span> Base64DecodeString<span class="br0">&#40;</span>ImageData<span class="br0">&#41;</span><span class="sy0">;</span><br />
MemoryStream memorystream <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> MemoryStream<span class="br0">&#40;</span>imageBytes<span class="br0">&#41;</span><span class="sy0">;</span><br />
memorystream.<span class="me1">Seek</span><span class="br0">&#40;</span>0, SeekOrigin.<span class="me1">Begin</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw5">System.<span class="me1">Drawing</span></span>.<span class="me1">Image</span> img <span class="sy0">=</span> ByteArrayToImage<span class="br0">&#40;</span>imageBytes<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>MailMessage emailEnquiry <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> MailMessage<span class="br0">&#40;</span>ContactEmail, FriendEmail<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>emailEnquiry.<span class="me1">Subject</span> <span class="sy0">=</span> <span class="st0">&quot;here&#8217;s a gripping email&quot;</span><span class="sy0">;</span><br />
emailEnquiry.<span class="me1">IsBodyHtml</span> <span class="sy0">=</span> true<span class="sy0">;</span><br />
Attachment objAttachment <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> Attachment<span class="br0">&#40;</span>memorystream, <span class="st0">&quot;AnAttachedImage.jpg&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
emailEnquiry.<span class="me1">Attachments</span>.<span class="me1">Add</span><span class="br0">&#40;</span>objAttachment<span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw4">String</span> ContentID <span class="sy0">=</span> <span class="st0">&quot;TheAttachedImage&quot;</span><span class="sy0">;</span><br />
objAttachment.<span class="me1">ContentId</span> <span class="sy0">=</span> ContentID<span class="sy0">;</span></p>
<p>StringBuilder sb <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>sb.<span class="me1">Append</span><span class="br0">&#40;</span><span class="st0">&quot;&#8230;lots of html here..&amp;lt;img src=&#8217;cid:&quot;</span> <span class="sy0">+</span> ContentID <span class="sy0">+</span> <span class="st0">&quot;&#8217;&amp;gt;&#8230;ending off with lots of html here too&#8230;&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>emailEnquiry.<span class="me1">Body</span> <span class="sy0">=</span> sb.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></p>
<p>SmtpClient sendEnquiry <span class="sy0">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> SmtpClient<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
sendEnquiry.<span class="me1">Host</span> <span class="sy0">=</span> WebConfigUtil.<span class="me1">GetAppSetting</span><span class="br0">&#40;</span><span class="st0">&quot;MySmtpServerName&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
sendEnquiry.<span class="me1">Send</span><span class="br0">&#40;</span>emailEnquiry<span class="br0">&#41;</span><span class="sy0">;</span></p>
<p><span class="kw1">return</span> true<span class="sy0">;</span></p>
<p><span class="br0">&#125;</span></p>
<p><span class="kw1">catch</span> <span class="br0">&#40;</span>Exception er<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>HttpContext.<span class="me1">Current</span>.<span class="me1">IsDebuggingEnabled</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
<span class="kw1">return</span> false<span class="sy0">;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw1">else</span><br />
<span class="kw1">throw</span> er<span class="sy0">;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p>So there you go. I have simplified the method in this example by taking out logging etc, so hopefully it still works / makes sense. The part that took the longest to fathom was making the link between the attached image and the rendered html using the &#8220;cid:&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://daverussell.co.za/wordpress/2009/07/28/net-html-mails-and-embedded-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

