<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>An Original Idea</title>
	<atom:link href="http://anoriginalidea.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://anoriginalidea.wordpress.com</link>
	<description>The ongoing software adventures of Julian Biddle</description>
	<lastBuildDate>Tue, 21 May 2013 10:07:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='anoriginalidea.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>An Original Idea</title>
		<link>http://anoriginalidea.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://anoriginalidea.wordpress.com/osd.xml" title="An Original Idea" />
	<atom:link rel='hub' href='http://anoriginalidea.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Its time.  I&#8217;m making a stand. MyNamingConventionManifesto.</title>
		<link>http://anoriginalidea.wordpress.com/2013/05/21/its-time-im-making-a-stand-mynamingconventionmanifesto/</link>
		<comments>http://anoriginalidea.wordpress.com/2013/05/21/its-time-im-making-a-stand-mynamingconventionmanifesto/#comments</comments>
		<pubDate>Tue, 21 May 2013 10:07:09 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[namingconventions]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://anoriginalidea.wordpress.com/?p=418</guid>
		<description><![CDATA[Variable names, filenames and other technical names.  Hungarian notion, abbreviations, verbosity, camel case and mixed case.  How many of my projects have used mixtures of these conventions?  How often do I forget what abbrev I usd???? ?!It_never_ends!?    no-longer    I-AM-SICK-OF-IT! _this_has_to_stop &#60;rant&#62;It is time to do away with inconsistency forever.  &#60;/rant&#62; I am happy [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=418&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Variable names, filenames and other technical names.  Hungarian notion, abbreviations, verbosity, camel case and mixed case.  How many of my projects have used mixtures of these conventions?  How often do I forget what abbrev I usd????</p>
<p>?!It_never_ends!?   </p>
<p>no-longer   </p>
<p>I-AM-SICK-OF-IT!</p>
<p>_this_has_to_stop</p>
<p>&lt;rant&gt;It is time to do away with inconsistency forever.  &lt;/rant&gt;</p>
<p>I am happy to comply with the conventions of a language (eg in .net mixed case is used for public attributes and properties whereas camel case is used for parameters) or the conventions of an existing project, but if there isn&#8217;t any, MyNamingConventionManifesto comes into play.</p>
<p>The decisions are around:</p>
<p>CASE (Upper, Lower, Mixed or Camel Case) </p>
<p>DELIMITER (None, Minus, Underscore or Space)</p>
<p>PREFIX</p>
<p>SUFFIX</p>
<p>So, I hereby declare that my naming convention will not use prefixes or suffixes, neither will it use delimiters.  In short, this is:</p>
<p style="text-align:center;"><strong>MyNamingConventionManifesto </strong></p>
<p> </p>
<p>ThankyouThatWillBeAll</p>
<p> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/418/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/418/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=418&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2013/05/21/its-time-im-making-a-stand-mynamingconventionmanifesto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple object dumping extension method for CSharp</title>
		<link>http://anoriginalidea.wordpress.com/2013/04/22/simple-object-dumping-extension-method-for-csharp/</link>
		<comments>http://anoriginalidea.wordpress.com/2013/04/22/simple-object-dumping-extension-method-for-csharp/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 00:37:10 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://anoriginalidea.wordpress.com/?p=412</guid>
		<description><![CDATA[Here&#8217;s a useful little extension method I created to dump fields and properties to the console of an object in CSharp.   It demonstrates simple reflection and extension method syntax.     public static class ObjectExtensions { public static void DumpProperties(this object obj) { Console.WriteLine(obj.GetType().Name); Console.WriteLine("{"); foreach (var fld in obj.GetType().GetFields()) { Console.WriteLine(String.Format("{0} = \"{1}\"", [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=412&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a useful little extension method I created to dump fields and properties to the console of an object in CSharp.  </p>
<p>It demonstrates simple reflection and extension method syntax.</p>
<p> </p>
<p> </p>
<pre>public static class ObjectExtensions<br /> {</pre>
<pre>public static void DumpProperties(this object obj)<br /> {<br /> Console.WriteLine(obj.GetType().Name);<br /> Console.WriteLine("{");<br /> foreach (var fld in obj.GetType().GetFields())<br /> {<br /> Console.WriteLine(String.Format("{0} = \"{1}\"", fld.Name, fld.GetValue(obj)));<br /> }<br /> foreach (var prop in obj.GetType().GetProperties())<br /> {<br /> if(prop.CanRead) Console.WriteLine(String.Format("{0} = \"{1}\"", prop.Name,prop.GetValue(obj, null)));<br /> }<br /> Console.WriteLine("}");<br /> }<br /> }</pre>
<p> </p>
<p> </p>
<p> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/412/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/412/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=412&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2013/04/22/simple-object-dumping-extension-method-for-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a an instance in EC2 with .net and passing parameters</title>
		<link>http://anoriginalidea.wordpress.com/2012/12/18/creating-a-an-instance-in-ec2-with-net-and-passing-parameters/</link>
		<comments>http://anoriginalidea.wordpress.com/2012/12/18/creating-a-an-instance-in-ec2-with-net-and-passing-parameters/#comments</comments>
		<pubDate>Tue, 18 Dec 2012 01:05:36 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://anoriginalidea.wordpress.com/?p=404</guid>
		<description><![CDATA[When starting an Amazon EC2 instance, you can pass something called &#8220;user metadata&#8221;.  This can be a file or values.  These values are not stored in an environmental variable or file on the new instance, but can instead be retrieved by doing a HTTP Get to a &#8220;special&#8221; IP address to retrieve those values. For [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=404&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When starting an Amazon EC2 instance, you can pass something called &#8220;user metadata&#8221;.  This can be a file or values.  These values are not stored in an environmental variable or file on the new instance, but can instead be retrieved by doing a HTTP Get to a &#8220;special&#8221; IP address to retrieve those values.</p>
<p>For example:</p>
<p>1.  Create the instance</p>
<pre><code>RunInstancesResponse response = Client.RunInstances(new RunInstancesRequest()
  .WithImageId(ami_id)
  .WithInstanceType(instance_type)
  .WithKeyName(YOUR_KEYPAIR_NAME)
  .WithMinCount(1)
  .WithMaxCount(max_number_of_instances)
  .WithUserData(Convert.ToBase64String(Encoding.UTF8.GetBytes(bootScript.Replace("\r", ""))))
);</code></pre>
<p>2.  In a startup script on the instance, make a call like this:</p>
<pre><strong><code>GET http://169.254.169.254/latest/user-data</code></strong>
1234,fred,reboot,true | 4512,jimbo, | 173,,,</pre>
<p>See the links below for further info</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Links</p>
<p><a href="http://stackoverflow.com/questions/7420368/how-to-start-an-amazon-ec2-instance-programmatically-in-net" rel="nofollow">http://stackoverflow.com/questions/7420368/how-to-start-an-amazon-ec2-instance-programmatically-in-net</a></p>
<p><a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html" rel="nofollow">http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/404/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=404&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2012/12/18/creating-a-an-instance-in-ec2-with-net-and-passing-parameters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>
	</item>
		<item>
		<title>What every phonegap developer on windows phone 7 needs</title>
		<link>http://anoriginalidea.wordpress.com/2012/01/06/what-every-phonegap-developer-on-windows-phone-7-needs/</link>
		<comments>http://anoriginalidea.wordpress.com/2012/01/06/what-every-phonegap-developer-on-windows-phone-7-needs/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 08:26:19 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anoriginalidea.wordpress.com/2012/01/06/what-every-phonegap-developer-on-windows-phone-7-needs/</guid>
		<description><![CDATA[  Error logging!  An unfortunate side effect of developing apps in Javascript in mobile IE9 is that there doesn&#8217;t appear to be any error dialogs. Try the following Javascript:   // provide our own console if it does not exist, huge dev aid!if (typeof window.console == &#8220;undefined&#8221;) { window.console = { log: function (str) { [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=389&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p> </p>
<p>Error logging!  An unfortunate side effect of developing apps in Javascript in mobile IE9 is that there doesn&#8217;t appear to be any error dialogs.</p>
<p>Try the following Javascript:</p>
<p> </p>
<p><em>// provide our own console if it does not exist, huge dev aid!</em><br /><em>if (typeof window.console == &#8220;undefined&#8221;) {</em><br /><em> window.console = { log: function (str) { window.external.Notify(str); } };</em><br /><em>}</em></p>
<p><em>// output any errors to console log, created above.</em><br /><em>window.onerror = function (msg,url,linenumber) {</em><br /><em> console.log(&#8220;Error ::&#8221; + msg + &#8221; in &#8221; + url + &#8221; at line &#8221; + linenumber); </em><br /><em>};</em></p>
<p><em>console.log(&#8220;Installed console ! &#8220;);</em></p>
<p>This also gives you a &#8220;console.log&#8221; for free.</p>
<p> </p>
<p>Enjoy!</p>
<p> </p>
<p> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/389/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/389/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=389&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2012/01/06/what-every-phonegap-developer-on-windows-phone-7-needs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>
	</item>
		<item>
		<title>Aspect Oriented Programming in Javascript</title>
		<link>http://anoriginalidea.wordpress.com/2012/01/01/aspect-oriented-programming-in-javascript/</link>
		<comments>http://anoriginalidea.wordpress.com/2012/01/01/aspect-oriented-programming-in-javascript/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 00:07:33 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://anoriginalidea.wordpress.com/?p=372</guid>
		<description><![CDATA[&#160; In designing javascript for modularity and &#8220;separation of concerns&#8221;, I was pleasantly surprised to discover a way of implementing AOP (Aspect Oriented Programming) in Javascript. &#160; AOP can be useful for automatically &#8220;wrapping&#8221; methods to provide tracing, error logging or caching. In this example, we are &#8220;wrapping&#8221; a method to show an alert when a method starts [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=372&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>In designing javascript for modularity and &#8220;separation of concerns&#8221;, I was pleasantly surprised to discover a way of implementing <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming">AOP </a>(Aspect Oriented Programming) in Javascript.</p>
<p>&nbsp;</p>
<p>AOP can be useful for automatically &#8220;wrapping&#8221; methods to provide tracing, error logging or caching.</p>
<p>In this example, we are &#8220;wrapping&#8221; a method to show an alert when a method starts and finishes:</p>
<pre>$.aop.around({ target: homelinksModel, method: 'get' }
 , function (invocation) {</pre>
<pre style="padding-left:30px;">alert("Method Call");
 
var ret = return invocation.proceed(); // This line calls the original method</pre>
<pre style="padding-left:30px;">alert("After Call");
return ret;
});</pre>
<p>I used it for caching using <a href="http://westcoastlogic.com/lawnchair/">Lawnchair </a> (an abstraction around local storage on client browsers).  It is designed to cache the result of data calls to the server.</p>
<pre>$.aop.around({ target: homelinksModel, method: 'get' }
 , function (invocation) {</pre>
<pre style="padding-left:30px;">var lc = new Lawnchair(function () { });</pre>
<pre style="padding-left:30px;">var keyName = 'homelinksModel' + invocation.method;</pre>
<pre style="padding-left:30px;">
var rec;</pre>
<pre style="padding-left:30px;">lc.get(keyName, function (ret) {</pre>
<pre style="padding-left:30px;">if (ret == null) {
    res = invocation.proceed()
    lc.save({ key: keyName, value: res });
    rec = res;</pre>
<pre style="padding-left:30px;"> }
 else {
 rec = ret.value;
 }</pre>
<pre style="padding-left:30px;">});</pre>
<pre style="padding-left:30px;">return rec;
}); // &lt;/aop&gt;</pre>
<p>I&#8217;m still learning Lawnchair, so there&#8217;s probably better ways of implementing this, but I thought a &#8220;useful&#8221; example might be helpful.</p>
<p>Peter Chung has an <a href="http://unitstep.net/blog/2009/03/31/aspect-oriented-programming/">excellent article</a> about Jquery AOP if you&#8217;d like to learn more.</p>
<p>There&#8217;s not alot of recent &#8220;action&#8221; around AOP in the Javascript space (Google Search).   I suspect that either some of it&#8217;s functionality is automatically part of jQuery or that the Javascript world isn&#8217;t mature enough yet to care much.    Perhaps it&#8217;s the former.</p>
<p>Over the past few days I&#8217;ve had a marvelous time implementing the MVVM pattern in Javascript.  I&#8217;m discovering all my favourite technologies are there, such as object databases (Lawnchair), binding (Knockout) and much more.  I hope to be blogging more about some of these soon.</p>
<p><strong>Links</strong></p>
<ul>
<li>JQuery AOP Plugin - <a href="http://code.google.com/p/jquery-aop/">http://code.google.com/p/jquery-aop/</a></li>
<li><a href="http://unitstep.net/blog/2009/03/31/aspect-oriented-programming/">http://unitstep.net/blog/2009/03/31/aspect-oriented-programming/</a></li>
<li>Using JQuery AOP Plugin to stop WordPress Tracking on DOM objects - <a href="http://blog.futtta.be/2011/11/16/applying-javascript-aop-magic-to-stop-3rd-party-tracking-in-wordpress/">http://blog.futtta.be/2011/11/16/applying-javascript-aop-magic-to-stop-3rd-party-tracking-in-wordpress/</a></li>
<li>List of Javascript AOP Frameworks - <a href="http://stackoverflow.com/questions/1005486/javascript-aop-libraries">http://stackoverflow.com/questions/1005486/javascript-aop-libraries</a></li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/372/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/372/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=372&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2012/01/01/aspect-oriented-programming-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>
	</item>
		<item>
		<title>Returning data from an MVC method with a small cute ActionResult</title>
		<link>http://anoriginalidea.wordpress.com/2011/06/17/returning-data-from-an-mvc-method-with-a-small-cute-actionresult/</link>
		<comments>http://anoriginalidea.wordpress.com/2011/06/17/returning-data-from-an-mvc-method-with-a-small-cute-actionresult/#comments</comments>
		<pubDate>Fri, 17 Jun 2011 13:11:45 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[.net Framework]]></category>
		<category><![CDATA[ccsharp]]></category>
		<category><![CDATA[xmlresult]]></category>
		<category><![CDATA[xmlserialization]]></category>

		<guid isPermaLink="false">https://anoriginalidea.wordpress.com/2011/06/17/returning-data-from-an-mvc-method-with-a-small-cute-actionresult/</guid>
		<description><![CDATA[In order return data from an MVC method, Microsoft provide a useful ActionResult object called JSONResult.&#160; JSONResult exposes a convenient Data property that you can use to serialize an object to JSON. Here’s how it can be used: var res = new JsonResult(); res.JsonRequestBehavior = JsonRequestBehavior.AllowGet; res.Data = someObject; return res; Pretty easy to use.&#160;&#160; [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=369&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://anoriginalidea.files.wordpress.com/2011/06/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2011/06/image_thumb.png?w=244&#038;h=193" width="244" height="193" /></a></p>
<p>In order return data from an MVC method, Microsoft provide a useful ActionResult object called JSONResult.&#160; JSONResult exposes a convenient Data property that you can use to serialize an object to JSON.</p>
<p>Here’s how it can be used:</p>
<p><em>var res = new JsonResult();     <br />res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;      <br />res.Data = someObject;      <br />return res;</em></p>
<p>Pretty easy to use.&#160;&#160; Unfortunately there’s no matching XMLResult class if you want to return a scrap of XML instead.&#160; In the MVCContrib project on codeplex there’s an XMLResult, but it’s event signature is slightly different.</p>
<p>I’ve modified this class to provide the same signature.&#160; </p>
<p>Here’s the usage:</p>
<p><em>var res = new XmlResult();     <br />res.Data = someObject;      <br />return res;      <br /></em></p>
<p>Here’s the class:</p>
<p><em>using System.Web.Mvc;     <br />using System.Xml.Serialization;</em></p>
<p><em>namespace Sample     <br />{      <br />&#160;&#160;&#160; /// &lt;summary&gt;      <br />&#160;&#160;&#160; /// Action result that serializes the specified object into XML and outputs it to the response stream.      <br />&#160;&#160;&#160; /// &lt;/summary&gt;      <br />&#160;&#160;&#160; public class XmlResult : ActionResult      <br />&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; private object _objectToSerialize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; private XmlAttributeOverrides _xmlAttribueOverrides;</em></p>
<p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// Creates a new instance of the XmlResult class.      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;param name=&quot;objectToSerialize&quot;&gt;The object to serialize to XML.&lt;/param&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public XmlResult()      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></p>
<p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// Creates a new instance of the XmlResult class.      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;param name=&quot;objectToSerialize&quot;&gt;The object to serialize to XML.&lt;/param&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public XmlResult(object objectToSerialize)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _objectToSerialize = objectToSerialize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></p>
<p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// Creates a new instance of the XMLResult class.      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;param name=&quot;objectToSerialize&quot;&gt;The object to serialize to XML.&lt;/param&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;param name=&quot;xmlAttributeOverrides&quot;&gt;&lt;/param&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public XmlResult(object objectToSerialize, XmlAttributeOverrides xmlAttributeOverrides)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _objectToSerialize = objectToSerialize;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _xmlAttribueOverrides = xmlAttributeOverrides;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></p>
<p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// The object to be serialized to XML.      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public object Data      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { return _objectToSerialize; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _objectToSerialize = value;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</em></p>
<p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;summary&gt;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// Serialises the object that was passed into the constructor to XML and writes the corresponding XML to the result stream.      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;/summary&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; /// &lt;param name=&quot;context&quot;&gt;The controller context for the current request.&lt;/param&gt;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; public override void ExecuteResult(ControllerContext context)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (_objectToSerialize != null)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var xs = (_xmlAttribueOverrides == null) ?      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new XmlSerializer(_objectToSerialize.GetType()) :      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new XmlSerializer(_objectToSerialize.GetType(), _xmlAttribueOverrides);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; context.HttpContext.Response.ContentType = &quot;text/xml&quot;;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; xs.Serialize(context.HttpContext.Response.Output, _objectToSerialize);      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br />&#160;&#160;&#160; }      <br />}      </em></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=369&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2011/06/17/returning-data-from-an-mvc-method-with-a-small-cute-actionresult/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>

		<media:content url="http://anoriginalidea.files.wordpress.com/2011/06/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Data Uris&#8211;A way of embedding images in your html page or UIWebView</title>
		<link>http://anoriginalidea.wordpress.com/2011/05/24/data-urisa-way-of-embedding-images-in-your-html-page-or-uiwebview/</link>
		<comments>http://anoriginalidea.wordpress.com/2011/05/24/data-urisa-way-of-embedding-images-in-your-html-page-or-uiwebview/#comments</comments>
		<pubDate>Mon, 23 May 2011 22:41:14 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[datauri]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[objectivec]]></category>

		<guid isPermaLink="false">https://anoriginalidea.wordpress.com/2011/05/24/data-urisa-way-of-embedding-images-in-your-html-page-or-uiwebview/</guid>
		<description><![CDATA[Currently I’m investigating ways of using&#160; UIWebView to render a user interface.&#160;&#160; I’d like to re-purpose some server side html form rendering logic so that it can be resused on the iPhone, Android and Windows Phone.&#160; Modern forms incorporate more than simple form elements however.&#160; They may include data, such as images. By default, the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=361&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://anoriginalidea.files.wordpress.com/2011/05/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2011/05/image_thumb1.png?w=209&#038;h=244" width="209" height="244" /></a></p>
<p>Currently I’m investigating ways of using&#160; UIWebView to render a user interface.&#160;&#160; </p>
<p>I’d like to re-purpose some server side html form rendering logic so that it can be resused on the iPhone, Android and Windows Phone.&#160; </p>
<p>Modern forms incorporate more than simple form elements however.&#160; They may include data, such as images.</p>
<p>By default, the UIWebview supports images in the “bundle” and images in the documents area.&#160; </p>
<p>What if I want to create images in memory, then display these in the HTML?</p>
<p>An little known feature of many modern web browsers (including Webkit) is datauris.&#160; A <a href="http://en.wikipedia.org/wiki/Data_URI_scheme">datauri</a> allows data to be embedded in a webpage where a url would usually be.</p>
<p>Here’s an example:</p>
<pre>&lt;img src=&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==&quot; alt=&quot;Red dot&quot; /&gt;</pre>
<pre><font face="Verdana">There are disadvantages however, which are the obvious effect this will have on caching and pagesize.</font></pre>
<pre><font face="Verdana">The Stackflow article <a href="http://stackoverflow.com/questions/5329648/display-local-uiimage-on-uiwebview">Display Local UI Image On a UIWebView</a> shows how to this, replicated here for your convenience.</font></pre>
<pre><font face="Verdana">This code demonstrates reading a file from the local bundle, then embedding into the background image, in the html dom of a UIWebView:</font></pre>
<p><code><code></p>
<p>#import &quot;NSString+DataURI.h&quot;</p>
<p>#import &quot;NSData+Base64.h&quot;</p>
<p>...</p>
<p>-(void)webViewDidFinishLoad:(UIWebView *)webView</p>
<p>{</p>
<p>&#160;&#160;&#160; NSString *imgPath = [[NSBundle mainBundle] pathForResource:@&quot;image&quot; ofType:@&quot;png&quot;];</p>
<p>&#160;&#160;&#160; NSData *imgData = [NSData dataWithContentsOfFile:imgPath];</p>
<p>&#160;&#160;&#160; NSString *imgB64 = [[imgData base64Encoding] pngDataURIWithContent];</p>
<p>&#160;&#160;&#160; NSString *javascript = [NSString stringWithFormat:@&quot;document.body.style.backgroundImage='url(%@)';&quot;, imgB64];</p>
<p>&#160;&#160;&#160; [webView stringByEvaluatingJavaScriptFromString:javascript];</p>
<p>}</code></p>
<p><font face="Verdana">This code uses the following utility functions that provide the base 64 encoding support:</font></p>
<p>NSData+Base64.h</p>
<p><code>@interface NSData (Base64) </code></p>
<p>    <code></p>
<p>+ (NSData *)dataWithBase64EncodedString:(NSString *)string;</p>
<p>- (id)initWithBase64EncodedString:(NSString *)string;</p>
<p>- (NSString *)base64Encoding;</p>
<p>- (NSString *)base64EncodingWithLineLength:(unsigned int) lineLength;</p>
<p>@end</p>
<p>    </code></p>
<p>NSData.Base64.m</p>
<p><code>#import &quot;NSData+Base64.h&quot;</code></p>
<p>    <code></p>
<p>static char encodingTable[64] = {</p>
<p>'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',</p>
<p>'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',</p>
<p>'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',</p>
<p>'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };</p>
<p>@implementation NSData (VQBase64)</p>
<p>- (id)initWithString:(NSString *)string {</p>
<p>&#160;&#160;&#160; if ((self = [super init])) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [self initWithBase64EncodedString:string];</p>
<p>&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; return self;</p>
<p>}</p>
<p>+ (NSData *) dataWithBase64EncodedString:(NSString *) string {</p>
<p>&#160;&#160;&#160; return [[[NSData allocWithZone:nil] initWithBase64EncodedString:string] autorelease];</p>
<p>}</p>
<p>- (id) initWithBase64EncodedString:(NSString *) string {</p>
<p>&#160;&#160;&#160; NSMutableData *mutableData = nil;</p>
<p>&#160;&#160;&#160; if( string ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; unsigned long ixtext = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; unsigned long lentext = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; unsigned char ch = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; unsigned char inbuf[4], outbuf[3];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; short i = 0, ixinbuf = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; BOOL flignore = NO;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; BOOL flendtext = NO;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; NSData *base64Data = nil;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; const unsigned char *base64Bytes = nil;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Convert the string to ASCII data.</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; base64Data = [string dataUsingEncoding:NSASCIIStringEncoding];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; base64Bytes = [base64Data bytes];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; mutableData = [NSMutableData dataWithCapacity:[base64Data length]];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; lentext = [base64Data length];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; while( YES ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ixtext &gt;= lentext ) break;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ch = base64Bytes[ixtext++];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; flignore = NO;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ( ch &gt;= 'A' ) &amp;&amp; ( ch &lt;= 'Z' ) ) ch = ch - 'A';</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if( ( ch &gt;= 'a' ) &amp;&amp; ( ch &lt;= 'z' ) ) ch = ch - 'a' + 26;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if( ( ch &gt;= '0' ) &amp;&amp; ( ch &lt;= '9' ) ) ch = ch - '0' + 52;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if( ch == '+' ) ch = 62;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if( ch == '=' ) flendtext = YES;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else if( ch == '/' ) ch = 63;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else flignore = YES;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ! flignore ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; short ctcharsinbuf = 3;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BOOL flbreak = NO;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( flendtext ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ! ixinbuf ) break;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else ctcharsinbuf = 2;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ixinbuf = 3;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; flbreak = YES;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; inbuf [ixinbuf++] = ch;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ixinbuf == 4 ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ixinbuf = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [0] = ( inbuf[0] &lt;&lt; 2 ) | ( ( inbuf[1] &amp; 0x30) &gt;&gt; 4 );</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [1] = ( ( inbuf[1] &amp; 0x0F ) &lt;&lt; 4 ) | ( ( inbuf[2] &amp; 0x3C ) &gt;&gt; 2 );</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [2] = ( ( inbuf[2] &amp; 0x03 ) &lt;&lt; 6 ) | ( inbuf[3] &amp; 0x3F );</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; for( i = 0; i &lt; ctcharsinbuf; i++ )</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [mutableData appendBytes:&amp;outbuf[i] length:1];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( flbreak )&#160; break;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; self = [self initWithData:mutableData];</p>
<p>&#160;&#160;&#160; return self;</p>
<p>}</p>
<p>#pragma mark -</p>
<p>- (NSString *) base64Encoding {</p>
<p>&#160;&#160;&#160; return [self base64EncodingWithLineLength:0];</p>
<p>}</p>
<p>- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength {</p>
<p>&#160;&#160;&#160; const unsigned char&#160;&#160;&#160;&#160; *bytes = [self bytes];</p>
<p>&#160;&#160;&#160; NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];</p>
<p>&#160;&#160;&#160; unsigned long ixtext = 0;</p>
<p>&#160;&#160;&#160; unsigned long lentext = [self length];</p>
<p>&#160;&#160;&#160; long ctremaining = 0;</p>
<p>&#160;&#160;&#160; unsigned char inbuf[3], outbuf[4];</p>
<p>&#160;&#160;&#160; unsigned short i = 0;</p>
<p>&#160;&#160;&#160; unsigned short charsonline = 0, ctcopy = 0;</p>
<p>&#160;&#160;&#160; unsigned long ix = 0;</p>
<p>&#160;&#160;&#160; while( YES ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ctremaining = lentext - ixtext;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ctremaining &lt;= 0 ) break;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for( i = 0; i &lt; 3; i++ ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ix = ixtext + i;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( ix &lt; lentext ) inbuf[i] = bytes[ix];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else inbuf [i] = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [0] = (inbuf [0] &amp; 0xFC) &gt;&gt; 2;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [1] = ((inbuf [0] &amp; 0x03) &lt;&lt; 4) | ((inbuf [1] &amp; 0xF0) &gt;&gt; 4);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [2] = ((inbuf [1] &amp; 0x0F) &lt;&lt; 2) | ((inbuf [2] &amp; 0xC0) &gt;&gt; 6);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; outbuf [3] = inbuf [2] &amp; 0x3F;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ctcopy = 4;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch( ctremaining ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case 1:</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ctcopy = 2;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case 2:</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ctcopy = 3;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for( i = 0; i &lt; ctcopy; i++ )</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [result appendFormat:@&quot;%c&quot;, encodingTable[outbuf[i]]];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; for( i = ctcopy; i &lt; 4; i++ )</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [result appendString:@&quot;=&quot;];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ixtext += 3;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; charsonline += 4;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( lineLength &gt; 0 ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( charsonline &gt;= lineLength ) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; charsonline = 0;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [result appendString:@&quot;\n&quot;];</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; return [NSString stringWithString:result];</p>
<p>}</p>
<p>@end </p>
<p>&#160;&#160;
<p>NSString+DataURI.h</p>
<p>#import &lt;Foundation/Foundation.h&gt;</p>
<p>@interface NSString(DataURI)</p>
<p>- (NSString *) pngDataURIWithContent;</p>
<p>- (NSString *) jpgDataURIWithContent;</p>
<p>@end</p>
<p>    </code></p>
<p>NSString+DataURI.m</p>
<p><code>#import &quot;NSString+DataURI.h&quot;</code></p>
<p>    <code></p>
<p>@implementation NSString(DataURI)</p>
<p>- (NSString *) pngDataURIWithContent;</p>
<p>{</p>
<p>&#160;&#160;&#160; NSString * result = [NSString stringWithFormat: @&quot;data:image/png;base64,%@&quot;, self];</p>
<p>&#160;&#160;&#160; return result;</p>
<p>}</p>
<p>- (NSString *) jpgDataURIWithContent;</p>
<p>{</p>
<p>&#160;&#160;&#160; NSString * result = [NSString stringWithFormat: @&quot;data:image/jpg;base64,%@&quot;, self];</p>
<p>&#160;&#160;&#160; return result;</p>
<p>}</p>
<p>@end </p>
<p>      <font face="Verdana"></font>&#160;<font face="Verdana"></font>&#160;</code></code></p>
<pre><font face="Verdana"></font>&#160;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/361/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/361/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=361&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2011/05/24/data-urisa-way-of-embedding-images-in-your-html-page-or-uiwebview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>

		<media:content url="http://anoriginalidea.files.wordpress.com/2011/05/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting the default browser in Visual Studio 2010 in an MVC Application</title>
		<link>http://anoriginalidea.wordpress.com/2011/05/12/setting-the-default-browser-in-visual-studio-2010-in-an-mvc-application/</link>
		<comments>http://anoriginalidea.wordpress.com/2011/05/12/setting-the-default-browser-in-visual-studio-2010-in-an-mvc-application/#comments</comments>
		<pubDate>Thu, 12 May 2011 10:39:55 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://anoriginalidea.wordpress.com/2011/05/12/setting-the-default-browser-in-visual-studio-2010-in-an-mvc-application/</guid>
		<description><![CDATA[To set the default browser used for debugging in an ASP.Net web application you need to bring up the “Browse With…” option on an aspx web page.&#160; In a default MVC application you won’t have this option. To do this temporarily add a “default.aspx” form to the root of your project, then the “Browse With…” [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=358&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://anoriginalidea.files.wordpress.com/2011/05/image.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2011/05/image_thumb.png?w=244&#038;h=223" width="244" height="223" /></a></p>
<p>To set the default browser used for debugging in an ASP.Net web application you need to bring up the “Browse With…” option on an aspx web page.&#160; In a default MVC application you won’t have this option.</p>
<p>To do this temporarily add a “default.aspx” form to the root of your project, then the “Browse With…” context menu option will appear.&#160; Choose your favourite browser, then remove the “default.aspx”.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/358/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=358&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2011/05/12/setting-the-default-browser-in-visual-studio-2010-in-an-mvc-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>

		<media:content url="http://anoriginalidea.files.wordpress.com/2011/05/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Updating Twitter via SuperTweet using VBA</title>
		<link>http://anoriginalidea.wordpress.com/2011/04/28/updating-twitter-via-supertweet-using-vba/</link>
		<comments>http://anoriginalidea.wordpress.com/2011/04/28/updating-twitter-via-supertweet-using-vba/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 12:54:19 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[Outlook]]></category>
		<category><![CDATA[supertweet]]></category>
		<category><![CDATA[twitter api]]></category>
		<category><![CDATA[vb6]]></category>
		<category><![CDATA[vba]]></category>

		<guid isPermaLink="false">https://anoriginalidea.wordpress.com/2011/04/28/updating-twitter-via-supertweet-using-vba/</guid>
		<description><![CDATA[In my previous article I showed how to update a twitter status, prior to the twitter decision to remove the basic authentication api.&#160; This article shows a way of getting around this.&#160; The SuperTweet service allows you to continue to use basic authentication.&#160; This is particularly useful for non-visual processes that use VBA. I am [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=354&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><img style="margin:5px;" alt="image" src="http://anoriginalidea.files.wordpress.com/2007/10/image-thumb.png?w=231&amp;h=68" /></p>
<p>In my <a href="http://anoriginalidea.wordpress.com/2007/10/12/twittering-from-outlook-using-vba/">previous article</a> I showed how to update a twitter status, prior to the twitter decision to remove the basic authentication api.&#160; This article shows a way of getting around this.&#160; The <a href="http://supertweet.net">SuperTweet</a> service allows you to continue to use basic authentication.&#160; This is particularly useful for non-visual processes that use VBA.</p>
<p>I am currently using Twitter to update a private tweet-stream of my activities (such as sending email) from an Outlook 2010 macro.&#160; This stream is then fed into the iPhone application Momento, which provides me with an “autodiary” based on my various twitter feeds and online services.</p>
<p>To use the SuperTweet, there are just three steps:</p>
<ol>
<li>Sign In with OAuth to the SuperTweet.net&#160; (<a href="http://www.supertweet.net/login">Sign-Up/Sign-In Now</a>)</li>
<li>Create a password for your applications to use with the SuperTweet.net API when they want to Tweet: <a href="http://www.supertweet.net/about/documentation#step2">Learn more</a>. </li>
<li>Change your application to use <tt><a href="http://api.supertweet.net" rel="nofollow">http://api.supertweet.net</a></tt> instead of Twitter.com.&#160; See the sample below on how to do this using WinHttp in VBA. ( <a href="http://www.supertweet.net/about/api">Learn more</a>.)</li>
</ol>
<p>The VBA code below will allow you to do an update to Twitter.&#160; The UrlEncode implementation came from <a href="http://stackoverflow.com/questions/218181/how-can-i-url-encode-a-string-in-excel-vba">this StackOverflow post</a>.</p>
<p> <code>
<p>Function PostToTwitter(statusUpdate As String, username As String, password As String) As Boolean      <br />&#160;&#160;&#160; Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0&#160; <br />&#160;&#160;&#160; On Error GoTo error_handler       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Dim WinHttpReq As New WinHttpRequest       <br />&#160; <br />&#160;&#160;&#160;&#160; ' Assemble an HTTP Request.       <br />&#160;&#160;&#160; WinHttpReq.Open &quot;POST&quot;, _       <br />&#160;&#160;&#160;&#160;&#160; &quot;<a href="http://api.supertweet.net/1/statuses/update.xml&quot;">http://api.supertweet.net/1/statuses/update.xml&quot;</a>, False       <br />&#160;&#160;&#160; WinHttpReq.SetCredentials username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER       <br />&#160;&#160;&#160; ' Send the HTTP Request.       <br />&#160;&#160;&#160; WinHttpReq.SetRequestHeader &quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;       <br />&#160;&#160;&#160; WinHttpReq.Send &quot;status=&quot; &amp; URLEncode(statusUpdate)       <br />&#160;&#160;&#160; If WinHttpReq.Status &lt;&gt; 200 Then       <br />&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160; GoTo error_handler       <br />&#160;&#160;&#160; End If       <br />&#160;&#160;&#160; DoEvents       <br />&#160;&#160;&#160; Debug.Print &quot;Posted - &quot; &amp; statusUpdate       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; PostToTwitter = True       <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Exit Function</p>
<p>error_handler:</p>
<p>&#160;&#160;&#160; PostToTwitter = False      <br />&#160;&#160;&#160; <br />&#160;&#160;&#160; Exit Function       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />End Function</p>
<p>Public Function URLEncode( _     <br />&#160;&#160; StringToEncode As String, _      <br />&#160;&#160; Optional UsePlusRatherThanHexForSpace As Boolean = False _      <br />) As String</p>
<p>&#160; Dim TempAns As String     <br />&#160; Dim CurChr As Integer      <br />&#160; CurChr = 1</p>
<p>&#160; Do Until CurChr - 1 = Len(StringToEncode)     <br />&#160;&#160;&#160; Select Case Asc(Mid(StringToEncode, CurChr, 1))      <br />&#160;&#160;&#160;&#160;&#160; Case 48 To 57, 65 To 90, 97 To 122      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; TempAns = TempAns &amp; Mid(StringToEncode, CurChr, 1)      <br />&#160;&#160;&#160;&#160;&#160; Case 32      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; If UsePlusRatherThanHexForSpace = True Then      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TempAns = TempAns &amp; &quot;+&quot;      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Else      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TempAns = TempAns &amp; &quot;%&quot; &amp; Hex(32)      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; End If      <br />&#160;&#160;&#160;&#160;&#160; Case Else      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; TempAns = TempAns &amp; &quot;%&quot; &amp; _      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Right(&quot;0&quot; &amp; Hex(Asc(Mid(StringToEncode, _      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CurChr, 1))), 2)      <br />&#160;&#160;&#160; End Select</p>
<p>&#160;&#160;&#160; CurChr = CurChr + 1     <br />&#160; Loop</p>
<p>&#160; URLEncode = TempAns     <br />End Function</p>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/354/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=354&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2011/04/28/updating-twitter-via-supertweet-using-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>

		<media:content url="http://anoriginalidea.files.wordpress.com/2007/10/image-thumb.png?w=231&#38;h=68" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Bringing a Windows Application to the Foreground using .net</title>
		<link>http://anoriginalidea.wordpress.com/2011/04/01/bringing-a-windows-application-to-the-foreground-using-net/</link>
		<comments>http://anoriginalidea.wordpress.com/2011/04/01/bringing-a-windows-application-to-the-foreground-using-net/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 10:46:10 +0000</pubDate>
		<dc:creator>anoriginalidea</dc:creator>
				<category><![CDATA[.net Framework]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[SetForegroundWindow]]></category>

		<guid isPermaLink="false">https://anoriginalidea.wordpress.com/2011/04/01/bringing-a-windows-application-to-the-foreground-using-net/</guid>
		<description><![CDATA[It’s surprising that there’s very little information available about bringing another windows application to the foreground. The SetForegroundWindow api call can be useful in this regard, but it can’t be used unless you know the windows handle of the main window of the application you’re activating.&#160; If the application you’re activating has many child windows, [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=353&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://anoriginalidea.files.wordpress.com/2011/04/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://anoriginalidea.files.wordpress.com/2011/04/image_thumb.png?w=244&#038;h=95" width="244" height="95" /></a></p>
<p>It’s surprising that there’s very little information available about bringing another windows application to the foreground.</p>
<p>The SetForegroundWindow api call can be useful in this regard, but it can’t be used unless you know the windows handle of the main window of the application you’re activating.&#160; If the application you’re activating has many child windows, simply using the “MainWindowHandle” property on the Process object is not enough.</p>
<p>The code fragment and sample will show how to find a process, enumerate it’s child windows, then send these the foreground.</p>
<p>&#160;</p>
<pre><pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">BringAppToForeground(“notepad”)
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">………
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><span style="color:#0000ff;">using</span> System.Diagnostics; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><span style="color:#0000ff;">using</span> System.Runtime.InteropServices;
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">……….
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">[DllImport(&quot;<span style="color:#8b0000;">user32.dll</span>&quot;)] <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> <span style="color:#0000ff;">bool</span> SetForegroundWindow(IntPtr hWnd); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">[DllImport(&quot;<span style="color:#8b0000;">user32.dll</span>&quot;)] 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><p><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">extern</span> IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,</p><p> <span style="color:#0000ff;">string</span> windowClass, <span style="color:#0000ff;">string</span> windowTitle); 
</p></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">       
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> BringAppToForeground(<span style="color:#0000ff;">string</span> appName) 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">{
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#008000;">// Find Parent </span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           IntPtr parenthWnd = GetProcessWindowHandle(appName); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">if</span> (parenthWnd == IntPtr.Zero) <span style="color:#0000ff;">return</span>; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#008000;">// Get list of child windows </span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           List&lt;IntPtr&gt; loChildWindows = GetChildWindowHandles(parenthWnd);
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#008000;">// Bring Windows to Front </span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           BringWindowsToFront(loChildWindows.Reverse&lt;IntPtr&gt;());
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">}
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> IntPtr GetProcessWindowHandle(<span style="color:#0000ff;">string</span> processName) 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">{ 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           IntPtr parenthWnd = IntPtr.Zero; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">foreach</span> (Process loProcess <span style="color:#0000ff;">in</span> Process.GetProcessesByName(processName)) 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           { 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">               parenthWnd = loProcess.MainWindowHandle; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">               <span style="color:#0000ff;">if</span> (parenthWnd != IntPtr.Zero) <span style="color:#0000ff;">break</span>; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           } 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">return</span> parenthWnd; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">}
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> BringWindowsToFront(IEnumerable&lt;IntPtr&gt; windows) 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">{ 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#008000;">// Go through each and bring to front </span>
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">foreach</span> (IntPtr fronthWnd <span style="color:#0000ff;">in</span> windows) 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           { 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">               SetForegroundWindow(fronthWnd); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           } 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">}
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> List&lt;IntPtr&gt; GetChildWindowHandles(IntPtr parenthWnd) 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">{ 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           IntPtr hWnd = IntPtr.Zero; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           List&lt;IntPtr&gt; loChildWindows = <span style="color:#0000ff;">new</span> List&lt;IntPtr&gt;(); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">do</span> 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           { 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">               hWnd = FindWindowEx(parenthWnd, hWnd, <span style="color:#0000ff;">null</span>, <span style="color:#0000ff;">null</span>); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">               <span style="color:#0000ff;">if</span> (hWnd == IntPtr.Zero) <span style="color:#0000ff;">break</span>; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">               loChildWindows.Add(hWnd); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           } 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">while</span> (hWnd != IntPtr.Zero); 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">           <span style="color:#0000ff;">return</span> loChildWindows; 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;">} 
</pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<pre style="background-color:#ffffff;width:100%;font-family:consolas,&#039;font-size:12px;margin:0;"></pre>
<p>To understand how to use this in a winforms project, take a look at the sample project.</p>
<p><a href="http://cid-5f1708eb705d1c65.office.live.com/self.aspx/Public/BringWindowsAppToFront.zip">Download Sample Project</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/anoriginalidea.wordpress.com/353/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/anoriginalidea.wordpress.com/353/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=anoriginalidea.wordpress.com&#038;blog=1093530&#038;post=353&#038;subd=anoriginalidea&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://anoriginalidea.wordpress.com/2011/04/01/bringing-a-windows-application-to-the-foreground-using-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/a70f6e33c95b7744068ecffceac0aa31?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anoriginalidea</media:title>
		</media:content>

		<media:content url="http://anoriginalidea.files.wordpress.com/2011/04/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
