<?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>Thu, 26 Jan 2012 03:00:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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>CsvColumnAttribute<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; <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>CsvColumnAttribute<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>CsvColumnAttribute<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>CsvColumnAttribute<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>CsvColumnAttribute<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>
		<item>
		<title>IT Toolbox: TechNet Magazine November 2011</title>
		<link>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-november-2011/</link>
		<comments>http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-november-2011/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 02:31:47 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=325</guid>
		<description><![CDATA[The November IT Toolbox column is up on the TechNet Magazine website. In November, I covered these products: MaxiVista: Extend Windows&#8217; desktop onto another physical machine EaseUS Todo Backup: An alternate backup solution for Windows desktops Check it out and &#8230; <a href="http://code.commongroove.com/2012/01/25/it-toolbox-technet-magazine-november-2011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine November IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh535740.aspx" target="_blank">November 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 November, I covered these products:</p>
<ul>
<li><strong>MaxiVista</strong>: Extend Windows&#8217; desktop onto another physical machine</li>
<li><strong>EaseUS Todo Backup</strong>: An alternate backup solution for Windows desktops</li>
</ul>
<p><a title="TechNet Magazine November IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh535740.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-november-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine October 2011</title>
		<link>http://code.commongroove.com/2011/10/21/it-toolbox-technet-magazine-october-2011/</link>
		<comments>http://code.commongroove.com/2011/10/21/it-toolbox-technet-magazine-october-2011/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 20:19:43 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=322</guid>
		<description><![CDATA[The October IT Toolbox column is up on the TechNet Magazine website. This month I covered three products: up.time: Up/down service, server and network device monitoring Synergy: Software-based KVM Iperf: Test your network&#8217;s performance Check it out and let me &#8230; <a href="http://code.commongroove.com/2011/10/21/it-toolbox-technet-magazine-october-2011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine October IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh528498.aspx" target="_blank">October 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>This month I covered three products:</p>
<ul>
<li><strong>up.time</strong>: Up/down service, server and network device monitoring</li>
<li><strong>Synergy</strong>: Software-based KVM</li>
<li><strong>Iperf</strong>: Test your network&#8217;s performance</li>
</ul>
<p><a title="TechNet Magazine October IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh528498.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/2011/10/21/it-toolbox-technet-magazine-october-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# : String Extension to Parse Enums</title>
		<link>http://code.commongroove.com/2011/09/23/c-string-extension-to-parse-enums/</link>
		<comments>http://code.commongroove.com/2011/09/23/c-string-extension-to-parse-enums/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 15:30:48 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=320</guid>
		<description><![CDATA[It seems to me that there is too much typing involved in parsing a string as an Enum type. Here&#8217;s a quick string extension method to turn it into a simpler one liner: public static T EnumParse&#60;T&#62;&#40;this string input, bool &#8230; <a href="http://code.commongroove.com/2011/09/23/c-string-extension-to-parse-enums/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It seems to me that there is too much typing involved in parsing a string as an Enum type.  Here&#8217;s a quick string extension method to turn it into a simpler one liner:</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: #0600FF; font-weight: bold;">static</span> T EnumParse<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span> <span style="color: #6666cc; font-weight: bold;">string</span> input, <span style="color: #6666cc; font-weight: bold;">bool</span> ignoreCase <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #6666cc; font-weight: bold;">Enum</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Parse</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span>, input, ignoreCase<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>With this extension, you can now do this:</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: #6666cc; font-weight: bold;">string</span> s <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;MyEnumValue&quot;</span><span style="color: #008000;">;</span><br />
MyEnum e <span style="color: #008000;">=</span> s<span style="color: #008000;">.</span><span style="color: #0000FF;">EnumParse</span><span style="color: #008000;">&lt;</span>MyEnum<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>Seems shorter to me. <img src='http://www.commongroove.com/code/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/09/23/c-string-extension-to-parse-enums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IT Toolbox: TechNet Magazine September 2011</title>
		<link>http://code.commongroove.com/2011/09/23/it-toolbox-technet-magazine-september-2011/</link>
		<comments>http://code.commongroove.com/2011/09/23/it-toolbox-technet-magazine-september-2011/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 15:25:56 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[Microsoft TechNet]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=317</guid>
		<description><![CDATA[The September IT Toolbox column is up on the TechNet Magazine website. This month I covered these two products: Lansweeper: Hardware, software, and device inventory management ipMonitor: Detailed monitoring of your servers, systems, and network devices. Check it out and &#8230; <a href="http://code.commongroove.com/2011/09/23/it-toolbox-technet-magazine-september-2011/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a title="TechNet Magazine September IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh441713.aspx" target="_blank">September 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>This month I covered these two products:</p>
<ul>
<li><strong>Lansweeper</strong>: Hardware, software, and device inventory management</li>
<li><strong>ipMonitor</strong>: Detailed monitoring of your servers, systems, and network devices.</li>
</ul>
<p><a title="TechNet Magazine September IT Toolbox" href="http://technet.microsoft.com/en-us/magazine/hh441713.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/2011/09/23/it-toolbox-technet-magazine-september-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net: App_Offline.htm as a Maintenance Page</title>
		<link>http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/</link>
		<comments>http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 15:40:35 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=311</guid>
		<description><![CDATA[While Googling about, I came upon an oldy-but-goody, that apparently has been available since the release of ASP.Net 2.0: App_Offline.htm. An undocumented feature, you can copy a file called app_offline.htm into the root of your .Net website and the application &#8230; <a href="http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While Googling about, I came upon an oldy-but-goody, that apparently has been available since the release of ASP.Net 2.0: App_Offline.htm.</p>
<p>An undocumented feature, you can copy a file called app_offline.htm into the root of your .Net website and the application will &#8220;bleed off&#8221; existing connections and redirect all new requests to the app_offline.htm page.</p>
<p>Once you remove the file, requests will again go back to your site.</p>
<p>Here&#8217;s ScottGu&#8217;s posts about it from back in 2005:</p>
<ul>
<li><a href="http://weblogs.asp.net/scottgu/archive/2005/10/06/426755.aspx" target="_blank">App_Offline.htm</a></li>
<li><a href="http://weblogs.asp.net/scottgu/archive/2006/04/09/442332.aspx" target="_blank">App_Offline.htm and working around the &#8220;IE Friendly Errors&#8221; feature</a></li>
</ul>
<p>One thing to note if you are using ASP.Net MVC.  Be sure your system.webserver configuration is set up to handle all requests so you don&#8217;t get 404s instead of the app_offline.htm page:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:550px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules</span> <span style="color: #000066;">runAllManagedModulesForAllRequests</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.webServer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/09/16/asp-net-app_offline-htm-as-a-maintenance-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSIS: Use Two OLE DB Destination Adapters to Catch Insertion/Constraint Errors</title>
		<link>http://code.commongroove.com/2011/09/16/ssis-use-two-ole-db-destination-adapters-to-catch-insertionconstraint-errors/</link>
		<comments>http://code.commongroove.com/2011/09/16/ssis-use-two-ole-db-destination-adapters-to-catch-insertionconstraint-errors/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 15:27:27 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=307</guid>
		<description><![CDATA[If you are using SQL Server Integration Server (SSIS) packages to insert large volumes of data, you have undoubtedly encountered incorrectly formatted or typed data in your data source including precision errors, conversion errors, and primary key/foreign key constraint errors etc. To &#8230; <a href="http://code.commongroove.com/2011/09/16/ssis-use-two-ole-db-destination-adapters-to-catch-insertionconstraint-errors/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you are using SQL Server Integration Server (SSIS) packages to insert large volumes of data, you have undoubtedly encountered incorrectly formatted or typed data in your data source including precision errors, conversion errors, and primary key/foreign key constraint errors etc.</p>
<p>To avoid package failure, you can choose to redirect error output to an alternate destination rather.  However, if you are using &#8220;Table or view &#8211; fast load&#8221; as your insertion method, it can be difficult to see which rows are actually the offenders in your redirected output.</p>
<p>One way to get around this is to <strong>use two OLE DB Destination adapters with different table access modes and then redirect the output</strong>.</p>
<p>On the first OLD DB Destination adapter, choose &#8220;Table or view &#8211; fast load&#8221; as the access mode, but set the maximum commit size to a specific number appropriate for your data set size.  Remember the smaller the commit size the slower the package will run.  In my particular case, I found a commit size of 5000 was appropriate for the data source.</p>
<p>Next, connect the error output from your first OLE DB Destination adapter to a second OLE DB Destination adapter rather than directly to a &#8220;bad input&#8221; file or database destination.  On this adapter, choose &#8220;Table or view&#8221; as the access mode which will insert records into the database one-by-one (another reason why you will have to tune your first adapter&#8217;s commit size to get optimal balance between performance and error handling).</p>
<p>Finally, take the error output from this second OLE DB Destination adapter and connect it to your &#8220;bad input&#8221; destination.</p>
<p>When it runs, the data batch that has the bad data on the first adapter will get redirected to the second adapter rather than having the whole commit size set being dumped to your error output file.  And because it is inserting one-by-one with &#8220;Table or view&#8221; access, you will only get the &#8220;real&#8221; errors dumped out to your error destination.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/09/16/ssis-use-two-ole-db-destination-adapters-to-catch-insertionconstraint-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript: Extending String to Have startsWith and endWith Functions</title>
		<link>http://code.commongroove.com/2011/09/09/javascript-extending-string-to-have-startswith-and-endwith-functions/</link>
		<comments>http://code.commongroove.com/2011/09/09/javascript-extending-string-to-have-startswith-and-endwith-functions/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 13:13:55 +0000</pubDate>
		<dc:creator>Greg</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://code.commongroove.com/?p=305</guid>
		<description><![CDATA[Here&#8217;s two prototype functions you can add to your JavaScript to give you &#8220;startsWith&#8221; and &#8220;endsWith&#8221; functions: if &#40;!String.prototype.startsWith&#41; &#123; &#160; &#160; String.prototype.startsWith = function &#40;str&#41; &#123; &#160; &#160; &#160; &#160; return this.slice&#40;0, str.length&#41; == str; &#160; &#160; &#125;; &#125; &#8230; <a href="http://code.commongroove.com/2011/09/09/javascript-extending-string-to-have-startswith-and-endwith-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s two prototype functions you can add to your JavaScript to give you &#8220;startsWith&#8221; and &#8220;endsWith&#8221; functions:</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">startsWith</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">startsWith</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>str<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> str.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> str<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">endsWith</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">endsWith</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>str<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>str.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> str<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://code.commongroove.com/2011/09/09/javascript-extending-string-to-have-startswith-and-endwith-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

