Read data from a CSV files or Tab delimited file is very common especially in the era of big data where you get a large flat file exported, transformed and then reloaded. I am often shocked to see that people write their own algorithm for this when a ...

Click here to read this mailing online.

Your email updates, powered by FeedBlitz

 
Here is a sample subscription for chrisw_88@hotmail.com


"C# Guild (csharp)" - 5 new articles

  1. Reading CSV or Tab delimited files from C#
  2. Running Powershell Scripts from your Application
  3. Ever wonder what you would do without technology...
  4. Dynamics CRM Unleashed Blog
  5. Essential Chrome Plug-ins for Web Developers
  6. More Recent Articles

Reading CSV or Tab delimited files from C#

Read data from a CSV files or Tab delimited file is very common especially in the era of big data where you get a large flat file exported, transformed and then reloaded. I am often shocked to see that people write their own algorithm for this when a very powerful module already exists and is free.

CSVhelper is available on GitHub and in its post basic usage you create a class file in your solution with the field name matching the fields in your Comma Separated file.  Then you simply do this:
  • Create a class to store your data

       class myRecord { public string Id { get; set;} public string Name {get; set;} }
  • Write code to open your file stream
  • Reference the CsvHelper dll
  • place a using statement for the CsvHelper at the top of your module

    using CsvHelper;
  • Use code similar to this where myFileStream is the stream you opened and myRecord is your class to fill with the data:

      using (var csv = new CsvReader(myFileStream))  {
         var recordList = csv.GetRecords().ToList();
     }
  • Voila, the variable recordList is a list that contains an instance of myRecord per row in your file.
Now this will read a comma-separated file but what if your file is tab delimited.  Well that is just as simply create a configuration object and assign delimiter:
      CsvConfiguration config = new CsvConfiguration();
      config.Delimiter = "\t";


Now pass this configuration object into your call:

           using (var csv = new CsvReader(myFileStream, config))
          {
              var recordList = csv.GetRecords().ToList();
          }

This same library can be used to write to a CSV to Tab Delimited file. You would make a call something like this:

            // Write the file
            using (var swFlat = new StreamWriter(connectionString))
            {
                using (var csvwriteFlat = new CsvWriter(swFlat))
                {
                    if (recordList != null) csvwriteFlat.WriteRecords(recordList);
                }
            }


    

Running Powershell Scripts from your Application

I have been working on a Feed Processing Library for many years now.  It featured its own simple Automation Script however in recent years I have seen the power of PowerShell scripts and am integrating it into my Feed Processor.  While doing this, I made notes below so it would help you through the same process of using it in your applications.

The first step is adding the reference to System.Management.Automation.dll to your solution. Although there are many ways to do this Rasik Bihari answered the best way to do it: Thanks Rasik Bihari for the answer.
System.Management.Automation dll is now published as "System.Management.Automation" nuget package here. Just add a reference to this nuget package from visual studio nuget package manager in your project and get going.
It shows like this in your packages.config file once you have installed the above mentioned nuget package in your project: 
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="System.Management.Automation.dll" version="10.0.10586.0" targetFramework="net452" />
</packages>
Once added, you can follow the recipe on how to run PowerShell Script from C#.








    

Ever wonder what you would do without technology...

JJ Abrams does a decent job showing the results of technology disappearing. Yes its not 100% realistic but if it was NBC would not be able to show it.

However from watching this episode, it gives you an idea of what would happen to that rich guy at Google.

Check out the pilot episode available on NBC.

    

Dynamics CRM Unleashed Blog

For those Guild Members who are looking at Dynamics CRM or are looking at revolutionary and out of the box ways of getting the most out of it, there is a new blog starting up that will be providing a wealth of information on just those topics.

The Dynamics CRM Unleashed Blog is written by someone with hands on experience working with large scale and cloud based CRM.

I know I will be reading it on a regular basis, so I thought I would pass it on to you as well.

If you have any tips, tricks or resources you would like to share with the Guild please email them to Susan Fischer at susan@clinchportal.com or Chris Williams at chrisw_88@hotmail.com
    

Essential Chrome Plug-ins for Web Developers

A co-worker of mine passed this link onto me.  It has some really good plug-ins to help improve website quality and help diagnose issues.

The ones that stand out are:
  • Check my links - This is a good plug-in to check for the page you are on. Still I recommend downloading xenu to check the whole site.
  • Firebug Lite - Nice plug-in light weight from toolbar.
  • yslow - This is pretty much a standard tool to have in your arsonal as it provides reasons why your site is so slow
Check out the full article at: 18 Essential Chrome Extensions for Web Development

If you know of any others that are useful please email them to Susan Fischer at susan@clinchportal.com and we will post them here.
    

More Recent Articles


You Might Like

Click here to safely unsubscribe from "C# Guild (csharp)."
Click here to view mailing archives, here to change your preferences, or here to subscribePrivacy