<?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>code.commongroove.com</title>
	<atom:link href="http://code.commongroove.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.commongroove.com</link>
	<description>C#, T-SQL, and general IT mojo</description>
	<lastBuildDate>Fri, 18 May 2012 14:34:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Toolbox: TechNet Magazine May 2012</title>
		<link>http://code.commongroove.com/2012/05/18/toolbox-technet-magazine-may-2012/</link>
		<comments>http://code.commongroove.com/2012/05/18/toolbox-technet-magazine-may-2012/#comments</comments>
		<pubDate>Fri, 18 May 2012 14:34:43 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=360</guid>
		<description><![CDATA[The May IT Toolbox column is up on the TechNet Magazine website. In May, I covered these products: SetACL Studio: Easily manage Windows ACLs LogFusion Pro: Real-time log scanning and highlighting NoVirusThanks File Governor: Unlock files easily Check it out &#8230; <a href="http://code.commongroove.com/2012/05/18/toolbox-technet-magazine-may-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine May IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/jj128106.aspx" target="_blank">May IT Toolbox</a> column is up on the <a title="TechNet Magazine" href="http://technet.microsoft.com/en-us/magazine/default.aspx" target="_blank">TechNet Magazine</a> website.</p>
<p>In May, I covered these products:</p>
<ul>
<li><strong>SetACL Studio</strong>: Easily manage Windows ACLs</li>
<li><strong>LogFusion Pro</strong>: Real-time log scanning and highlighting</li>
<li><strong>NoVirusThanks File Governor</strong>: Unlock files easily</li>
</ul>
<p><a title="TechNet Magazine May IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/jj128106.aspx" target="_blank">Check it out</a> and let me know what you think!</p>
<p>And, as always, if you have a utility or application you would like me to cover, <a href="mailto:greg.steen@live.com">please let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/05/18/toolbox-technet-magazine-may-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Parse the Query String into a Usable Object</title>
		<link>http://code.commongroove.com/2012/04/25/javascript-parse-the-query-string-into-a-usable-object/</link>
		<comments>http://code.commongroove.com/2012/04/25/javascript-parse-the-query-string-into-a-usable-object/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 18:12:46 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=358</guid>
		<description><![CDATA[One common task when working in JavaScript on the client side is having to parse the query string into a usable object form. Here&#8217;s a function that returns an array of arrays representing the key/value pairs in the query string: &#8230; <a href="http://code.commongroove.com/2012/04/25/javascript-parse-the-query-string-into-a-usable-object/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One common task when working in JavaScript on the client side is having to parse the query string into a usable object form.</p>
<p>Here&#8217;s a function that returns an array of arrays representing the key/value pairs in the query string:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #006600; font-style: italic;">// avoid naming collisions with a namespace</span><br />
myNamespace <span style="color: #339933;">=</span> myNamespace <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #006600; font-style: italic;">// returns an array of arrays representing</span><br />
<span style="color: #006600; font-style: italic;">// the key/value pairs in the querystring</span><br />
myNamespace.<span style="color: #660066;">getQueryStringLookup</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> queryString <span style="color: #339933;">=</span> location.<span style="color: #660066;">search</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>queryString <span style="color: #339933;">||</span> queryString.<span style="color: #660066;">length</span> <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> queryStringKvps <span style="color: #339933;">=</span> location.<span style="color: #660066;">search</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; lookup <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> imax <span style="color: #339933;">=</span> queryStringKvps.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> imax<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> kvp <span style="color: #339933;">=</span> queryStringKvps<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'='</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key <span style="color: #339933;">=</span> kvp<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value <span style="color: #339933;">=</span> decodeURIComponent<span style="color: #009900;">&#40;</span>kvp<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>lookup<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lookup<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; lookup<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> lookup<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>So, for example, if you had a query string like the following:</p>
<p>?product=Apple&#038;product=Orange&#038;category=Fruit</p>
<p>You would get back an array that you could use as so:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> qsLookup <span style="color: #339933;">=</span> myNamespace.<span style="color: #660066;">getQueryStringLookup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> category <span style="color: #339933;">=</span> qsLookup<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;category&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> products <span style="color: #339933;">=</span> qsLookup<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;product&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> apple <span style="color: #339933;">=</span> products<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> orange <span style="color: #339933;">=</span> products<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></div></div>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/04/25/javascript-parse-the-query-string-into-a-usable-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net MVC: Simple Custom Authorization by Inheriting from the AuthorizeAttribute</title>
		<link>http://code.commongroove.com/2012/04/20/asp-net-mvc-simple-custom-authorization-by-inheriting-from-the-authorizeattribute/</link>
		<comments>http://code.commongroove.com/2012/04/20/asp-net-mvc-simple-custom-authorization-by-inheriting-from-the-authorizeattribute/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 21:00:46 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Attributes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=352</guid>
		<description><![CDATA[Implementing custom authorization to a ASP.Net MVC site can be quite simple if you take advantage of the built-in ActionFilter authorization framework. Here&#8217;s how to do it. First, this enumeration describing four levels of access to the site. // They &#8230; <a href="http://code.commongroove.com/2012/04/20/asp-net-mvc-simple-custom-authorization-by-inheriting-from-the-authorizeattribute/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Implementing custom authorization to a ASP.Net MVC site can be quite simple if you take advantage of the built-in ActionFilter authorization framework.  Here&#8217;s how to do it.</p>
<p>First, this enumeration describing four levels of access to the site.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">// They types of user we have on the site</span><br />
<span style="color: #008000;">&#91;</span>Serializable<span style="color: #008000;">&#93;</span><br />
<span style="color: #008000;">&#91;</span>Flags<span style="color: #008000;">&#93;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> UserRole<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Guest <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,<br />
&nbsp; &nbsp; User <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,<br />
&nbsp; &nbsp; SuperUser <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,<br />
&nbsp; &nbsp; Admin <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Here&#8217;s a quick and dirty example of a session based reference to the current user that will be used to verify that he or she has access to the controller action requested.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">// The custom session object that keeps </span><br />
<span style="color: #008080; font-style: italic;">// track of the current user</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> MySessionObject<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> User Current <br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>User<span style="color: #008000;">&#41;</span>HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Session</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;CurrentUser&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span> &nbsp;<span style="color: #008000;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; set <span style="color: #008000;">&#123;</span> HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Session</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;CurrentUser&quot;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> &nbsp;<span style="color: #008000;">&#125;</span> <br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> MemberHasAtLeastRole<span style="color: #008000;">&#40;</span>UserRole matchTo<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> Current<span style="color: #008000;">.</span><span style="color: #0000FF;">Roles</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Any</span><span style="color: #008000;">&#40;</span>testRole <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>testRole <span style="color: #008000;">&gt;=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>matchTo<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>This is what does the real &#8220;work&#8221;.  By inheriting from the built-in AuthorizeAttribute, you take advantage of ASP.Net MVC&#8217;s built-in authorization framework.  Just override the Roles property with your own UserRole class and check that your current user has &#8220;at least&#8221; that role in the AuthorizeCore method override.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">// The custom authorization attribute</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> CustomAuthorizeAttribute <span style="color: #008000;">:</span> AuthorizeAttribute<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #008000;">new</span> UserRole Roles<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Notice the &quot;new&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> AuthorizeCore<span style="color: #008000;">&#40;</span>HttpContextBase httpContext<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Generally authenticated to the site</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>httpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">User</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Identity</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsAuthenticated</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Next, specific roles this user has</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>Roles <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> MySessionObject<span style="color: #008000;">.</span><span style="color: #0000FF;">MemberHasAtLeastRole</span><span style="color: #008000;">&#40;</span>Roles<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>And finally, in your controller, you apply the attribute to the applicable controller actions.  Or, if every controller action requires the same level of authorization, you could apply it to the class declaration of the controller.</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyController <span style="color: #008000;">:</span> Controller<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CustomAuthorize<span style="color: #008000;">&#40;</span>Roles <span style="color: #008000;">=</span> UserRole<span style="color: #008000;">.</span><span style="color: #0000FF;">SuperUser</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> ActionResult MyControllerAction<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> View<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/04/20/asp-net-mvc-simple-custom-authorization-by-inheriting-from-the-authorizeattribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine April 2012</title>
		<link>http://code.commongroove.com/2012/04/19/it-toolbox-technet-magazine-april-2012/</link>
		<comments>http://code.commongroove.com/2012/04/19/it-toolbox-technet-magazine-april-2012/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 11:51:38 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=348</guid>
		<description><![CDATA[The April IT Toolbox column is up on the TechNet Magazine website. In April, I covered these products: Fences: Organize your Windows Desktop LockHunter: Find and unlock locked files DiskInternals Linux Reader: Read EXT2/EXT3 file systems from Windows Check it &#8230; <a href="http://code.commongroove.com/2012/04/19/it-toolbox-technet-magazine-april-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine April IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh966764.aspx" target="_blank">April IT Toolbox</a> column is up on the <a title="TechNet Magazine" href="http://technet.microsoft.com/en-us/magazine/default.aspx" target="_blank">TechNet Magazine</a> website.</p>
<p>In April, I covered these products:</p>
<ul>
<li><strong>Fences</strong>: Organize your Windows Desktop</li>
<li><strong>LockHunter</strong>: Find and unlock locked files</li>
<li><strong>DiskInternals Linux Reader</strong>: Read EXT2/EXT3 file systems from Windows</li>
</ul>
<p><a title="TechNet Magazine April IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh966764.aspx" target="_blank">Check it out</a> and let me know what you think!</p>
<p>And, as always, if you have a utility or application you would like me to cover, <a href="mailto:greg.steen@live.com">please let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/04/19/it-toolbox-technet-magazine-april-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Dynamically Add Options to an HTML Select Using jQuery</title>
		<link>http://code.commongroove.com/2012/03/28/javascript-dynamically-add-options-to-an-html-select-using-jquery/</link>
		<comments>http://code.commongroove.com/2012/03/28/javascript-dynamically-add-options-to-an-html-select-using-jquery/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 20:25:38 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=346</guid>
		<description><![CDATA[Here&#8217;s how you can dynamically add options to an HTML select using jQuery var $selector = $&#40;'#mySelect'&#41;; $selector.append&#40;$&#40;'&#60;option&#62;', &#123; value: &#34;&#34; &#125;&#41;.text&#40;&#34;-- Choose --&#34;&#41;&#41;; $.each&#40;this.dataArray, function &#40;idx, dataItem&#41; &#123; &#160; &#160; $selector.append&#40;$&#40;'&#60;option&#62;', &#123; value: dataItem.Key &#125;&#41;.text&#40;dataItem.Value&#41;&#41;; &#125;&#41;; $selector.append&#40;$&#40;'&#60;option&#62;', &#123; value: &#8230; <a href="http://code.commongroove.com/2012/03/28/javascript-dynamically-add-options-to-an-html-select-using-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how you can dynamically add options to an HTML select using jQuery</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> $selector <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mySelect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
$selector.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;option&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> value<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;-- Choose --&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dataArray</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>idx<span style="color: #339933;">,</span> dataItem<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; $selector.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;option&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> value<span style="color: #339933;">:</span> dataItem.<span style="color: #660066;">Key</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>dataItem.<span style="color: #660066;">Value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
$selector.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;option&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> value<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;All&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Show All&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
$selector.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Selected '</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/03/28/javascript-dynamically-add-options-to-an-html-select-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine March 2012</title>
		<link>http://code.commongroove.com/2012/03/28/it-toolbox-technet-magazine-march-2012/</link>
		<comments>http://code.commongroove.com/2012/03/28/it-toolbox-technet-magazine-march-2012/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 20:22:31 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=344</guid>
		<description><![CDATA[The March IT Toolbox column is up on the TechNet Magazine website. In March, I covered these products: Easy Email Extractor: Mine files and folders for email addresses Bulk Rename Utility: Rename files and folders en masse ShieldsUP!: Test your &#8230; <a href="http://code.commongroove.com/2012/03/28/it-toolbox-technet-magazine-march-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine March IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh875161.aspx" target="_blank">March IT Toolbox</a> column is up on the <a title="TechNet Magazine" href="http://technet.microsoft.com/en-us/magazine/default.aspx" target="_blank">TechNet Magazine</a> website.</p>
<p>In March, I covered these products:</p>
<ul>
<li><strong>Easy Email Extractor</strong>: Mine files and folders for email addresses</li>
<li><strong>Bulk Rename Utility</strong>: Rename files and folders en masse</li>
<li><strong>ShieldsUP!</strong>: Test your attack surface and port exposure online</li>
</ul>
<p><a title="TechNet Magazine March IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh875161.aspx" target="_blank">Check it out</a> and let me know what you think!</p>
<p>And, as always, if you have a utility or application you would like me to cover, <a href="mailto:greg.steen@live.com">please let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/03/28/it-toolbox-technet-magazine-march-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine February 2012</title>
		<link>http://code.commongroove.com/2012/02/19/it-toolbox-technet-magazine-february-2012/</link>
		<comments>http://code.commongroove.com/2012/02/19/it-toolbox-technet-magazine-february-2012/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 17:57:18 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=341</guid>
		<description><![CDATA[The February IT Toolbox column is up on the TechNet Magazine website. In February, I covered these products: smtp4dev: A local smtp server to test out applications and email messages DisplayFusion Pro: A full-featured, multimonitor management application PureText: Copy/paste text &#8230; <a href="http://code.commongroove.com/2012/02/19/it-toolbox-technet-magazine-february-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine February IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh848749.aspx" target="_blank">February IT Toolbox</a> column is up on the <a title="TechNet Magazine" href="http://technet.microsoft.com/en-us/magazine/default.aspx" target="_blank">TechNet Magazine</a> website.</p>
<p>In February, I covered these products:</p>
<ul>
<li><strong>smtp4dev</strong>: A local smtp server to test out applications and email messages</li>
<li><strong>DisplayFusion Pro</strong>: A full-featured, multimonitor management application</li>
<li><strong>PureText</strong>: Copy/paste text without richtext formatting</li>
</ul>
<p><a title="TechNet Magazine February IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh848749.aspx" target="_blank">Check it out</a> and let me know what you think!</p>
<p>And, as always, if you have a utility or application you would like me to cover, <a href="mailto:greg.steen@live.com">please let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/02/19/it-toolbox-technet-magazine-february-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: Export a List of Objects to CSV with LINQ, Attributes, and Generics</title>
		<link>http://code.commongroove.com/2012/01/25/c-export-a-list-of-objects-to-csv-with-linq-attributes-and-generics/</link>
		<comments>http://code.commongroove.com/2012/01/25/c-export-a-list-of-objects-to-csv-with-linq-attributes-and-generics/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 03:00:48 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Attributes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=334</guid>
		<description><![CDATA[Have you ever needed to transform data from in-memory C# objects to a CSV flat-file of a specific format?  Here&#8217;s an easy way to get the job done with C#, LINQ, and Generics. First you need the Attribute you will &#8230; <a href="http://code.commongroove.com/2012/01/25/c-export-a-list-of-objects-to-csv-with-linq-attributes-and-generics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have you ever needed to transform data from in-memory C# objects to a CSV flat-file of a specific format?  Here&#8217;s an easy way to get the job done with C#, LINQ, and Generics.</p>
<p>First you need the Attribute you will use to mark up the properties on your exportable class:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// The name of the column for the CSV</span><br />
<span style="color: #008080; font-style: italic;">/// generated by a list of objects with</span><br />
<span style="color: #008080; font-style: italic;">/// properties marked with this attribute,</span><br />
<span style="color: #008080; font-style: italic;">/// if Export is true. &nbsp;Uses Order to order</span><br />
<span style="color: #008080; font-style: italic;">/// the properties on export</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> CsvColumnNameAttribute <span style="color: #008000;">:</span> Attribute<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Export <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Order <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Name <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> CsvColumnNameAttribute<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Export <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Order <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxValue</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// so unordered columns are at the end</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #008000;">&#125;</span></div></div>
<p>And here is how you use the attributes to mark up your class so you can export a list of instantiated objects:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyClassToExport<br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CsvColumn<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Activation Date&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> DateTime Date <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CsvColumn<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Full Name&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> User <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CsvColumn<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Account Type&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> Level <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CsvColumn<span style="color: #008000;">&#40;</span>Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Account Action&quot;</span>, Order <span style="color: #008000;">=</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Action <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">&#91;</span>CsvColumn<span style="color: #008000;">&#40;</span>Export <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> DateTime Added <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Then you need to code to actually create the CSV using LINQ and Generics:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// Generate a CSV as a string from a list</span><br />
<span style="color: #008080; font-style: italic;">/// of objects that have the CsvColumnNameAttribute</span><br />
<span style="color: #008080; font-style: italic;">/// applied</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetCsv<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> csvDataObjects<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; PropertyInfo<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> propertyInfos <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetProperties</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; var sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; sb<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendLine</span><span style="color: #008000;">&#40;</span>GetCsvHeaderSorted<span style="color: #008000;">&#40;</span>propertyInfos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; csvDataObjects<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">ForEach</span><span style="color: #008000;">&#40;</span>d <span style="color: #008000;">=&gt;</span> sb<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendLine</span><span style="color: #008000;">&#40;</span>GetCsvDataRowSorted<span style="color: #008000;">&#40;</span>d, propertyInfos<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> sb<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetCsvDataRowSorted<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span>T csvDataObject, PropertyInfo<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> propertyInfos<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; IEnumerable<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> valuesSorted <span style="color: #008000;">=</span> propertyInfos<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">new</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value <span style="color: #008000;">=</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span>csvDataObject, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Attribute <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>CsvColumnNameAttribute<span style="color: #008000;">&#41;</span>Attribute<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttribute</span><span style="color: #008000;">&#40;</span>x, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>CsvColumnNameAttribute<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Export</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Attribute</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Order</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> GetPropertyValueAsString<span style="color: #008000;">&#40;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Join</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;,&quot;</span>, valuesSorted<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetCsvHeaderSorted<span style="color: #008000;">&#40;</span>PropertyInfo<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> propertyInfos<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; IEnumerable<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> headersSorted <span style="color: #008000;">=</span> propertyInfos<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#40;</span>CsvColumnNameAttribute<span style="color: #008000;">&#41;</span>Attribute<span style="color: #008000;">.</span><span style="color: #0000FF;">GetCustomAttribute</span><span style="color: #008000;">&#40;</span>x, <span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>CsvColumnNameAttribute<span style="color: #008000;">&#41;</span>, <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Where</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Export</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Order</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Select</span><span style="color: #008000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Join</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;,&quot;</span>, headersSorted<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> GetPropertyValueAsString<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> propertyValue<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> propertyValueString<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>propertyValue <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyValueString <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>propertyValue <span style="color: #008000;">is</span> DateTime<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyValueString <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>DateTime<span style="color: #008000;">&#41;</span>propertyValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;dd MMM yyyy&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>propertyValue <span style="color: #008000;">is</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyValueString <span style="color: #008000;">=</span> propertyValue<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>propertyValue <span style="color: #008000;">is</span> <span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyValueString <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>propertyValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;#.####&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// format as you need it</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>propertyValue <span style="color: #008000;">is</span> <span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyValueString <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>propertyValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;#.####&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// format as you need it</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #008080; font-style: italic;">// treat as a string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; propertyValueString <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;&quot;</span><span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">+</span> propertyValue<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">@&quot;&quot;</span><span style="color: #666666;">&quot;&quot;</span>, <span style="color: #666666;">@&quot;&quot;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">@&quot;&quot;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// quotes with 2 quotes</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> propertyValueString<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Once you have that code up in going in your application, you can export your list of objects to a CSV with just a couple lines of code:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">// example usage</span><br />
var export <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>MyClassToExport<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008080; font-style: italic;">// TODO add items to list :)</span><br />
var csv <span style="color: #008000;">=</span> GetCsv<span style="color: #008000;">&#40;</span>export<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>Hope this helps!  And let me know if you have any suggestions or improvements.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/01/25/c-export-a-list-of-objects-to-csv-with-linq-attributes-and-generics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine January 2012</title>
		<link>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-january-2012/</link>
		<comments>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-january-2012/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 02:35:34 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=331</guid>
		<description><![CDATA[The January IT Toolbox column is up on the TechNet Magazine website. In January, I covered these products: SQL Source Control: Version your T-SQL within SSMS Bins: Taskbar Organizer for Windows MD5 Checksum Tool: Free MD5 checksum tool Check it &#8230; <a href="http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-january-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine January IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh771097.aspx" target="_blank">January IT Toolbox</a> column is up on the <a title="TechNet Magazine" href="http://technet.microsoft.com/en-us/magazine/default.aspx" target="_blank">TechNet Magazine</a> website.</p>
<p>In January, I covered these products:</p>
<ul>
<li><strong>SQL Source Control</strong>: Version your T-SQL within SSMS</li>
<li><strong>Bins</strong>: Taskbar Organizer for Windows</li>
<li><strong>MD5 Checksum Tool</strong>: Free MD5 checksum tool</li>
</ul>
<p><a title="TechNet Magazine January IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh771097.aspx" target="_blank">Check it out</a> and let me know what you think!</p>
<p>And, as always, if you have a utility or application you would like me to cover, <a href="mailto:greg.steen@live.com">please let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-january-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine December 2011</title>
		<link>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-december-2011/</link>
		<comments>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-december-2011/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 02:33:34 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=328</guid>
		<description><![CDATA[The December IT Toolbox column is up on the TechNet Magazine website. In December, I covered these products: SSMS Tools Pack: Extend SQL Server Management studio Network Inventory Advisor: Automated system and device inventory application Check it out and let &#8230; <a href="http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-december-2011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine December IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh708719.aspx" target="_blank">December IT Toolbox</a> column is up on the <a title="TechNet Magazine" href="http://technet.microsoft.com/en-us/magazine/default.aspx" target="_blank">TechNet Magazine</a> website.</p>
<p>In December, I covered these products:</p>
<ul>
<li><strong>SSMS Tools Pack</strong>: Extend SQL Server Management studio</li>
<li><strong>Network Inventory Advisor</strong>: Automated system and device inventory application</li>
</ul>
<p><a title="TechNet Magazine December IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh708719.aspx" target="_blank">Check it out</a> and let me know what you think!</p>
<p>And, as always, if you have a utility or application you would like me to cover, <a href="mailto:greg.steen@live.com">please let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-december-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

