<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>#region Coad's Code : C#</title><link>http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx</link><description>Tags: C#</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Visual Studio 2005 (Whidbey) Beta2 is Here!</title><link>http://msmvps.com/blogs/coad/archive/2005/04/18/43500.aspx</link><pubDate>Tue, 19 Apr 2005 01:16:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:43500</guid><dc:creator>coad</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=43500</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2005/04/18/43500.aspx#comments</comments><description>&lt;p&gt;&lt;b&gt;Whidbey Beta2 is Released!&lt;/b&gt;  We all (you &amp;amp; MS) have been waiting long for this build!  Wow, it is a substantial improvement over Beta1 and the client bits even have a Go Live License.  I'm excited!  How about you? &lt;img style="position: relative; top: 2px;" src="http://coad.net/blog/images/SmileDot.gif" /&gt;&lt;/p&gt;&lt;p&gt;If you have a &lt;a href="http://msdn.microsoft.com/howtobuy/vs2005/"&gt;MSDN Subscription&lt;/a&gt;, you can &lt;a href="http://msdn.microsoft.com/getthebetas/"&gt;Get the Beta&lt;/a&gt; for the cost of S/H or download &lt;a href="http://msdn.microsoft.com/vs2005"&gt;Visual Studio 2005&lt;/a&gt; - &lt;a href="http://msdn.microsoft.com/teamsystem"&gt;Team System&lt;/a&gt; (aka VSTS).  There is a &lt;a href="http://lab.msdn.microsoft.com/vs2005/golive/"&gt;Go-Live License&lt;/a&gt; which permits "production deployments of customer applications".&lt;/p&gt;&lt;p&gt;For the free (&lt;a href="http://www.microsoft.com/presspass/press/2005/mar05/03-21VS2005PR.asp"&gt;for now&lt;/a&gt;)
&lt;a href="http://lab.msdn.microsoft.com/express/"&gt;Express SKUs&lt;/a&gt;:
&lt;a href="http://download.microsoft.com/download/c/0/7/c07e9e42-0d34-45d7-890f-810964216a62/vcssetup.exe"&gt;C#&lt;/a&gt;,
&lt;a href="http://download.microsoft.com/download/e/1/c/e1c75061-a229-49ea-bd0c-d0a7a22e8ba4/vbsetup.exe"&gt;VB&lt;/a&gt;,
&lt;a href="http://download.microsoft.com/download/1/c/3/1c3ccc8e-0fcf-400f-bd5c-56c4d65961e9/vcsetup.exe"&gt;VC++&lt;/a&gt;,
&lt;a href="http://download.microsoft.com/download/6/3/8/638c4a4a-8343-4360-9fe8-78ae03037057/vjssetup.exe"&gt;J#&lt;/a&gt;,
&lt;a href="http://download.microsoft.com/download/3/a/0/3a017815-b515-4807-87e5-f2dc57191c97/vwdsetup.exe"&gt;Web Dev&lt;/a&gt;,
&lt;a href="http://download.microsoft.com/download/3/b/2/3b23d152-96cd-4d4b-a136-f8dc8b63cbb0/SQLEXPR.EXE"&gt;SQL Srv&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=43500" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/coad/archive/tags/VSTS/default.aspx">VSTS</category></item><item><title>SerialPort (RS-232 Serial COM Port) in C# .NET</title><link>http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx</link><pubDate>Thu, 24 Mar 2005 02:28:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:39466</guid><dc:creator>coad</dc:creator><slash:comments>285</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=39466</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx#comments</comments><description>&lt;p&gt;This article is about communicating through the PC&amp;#39;s Serial COM RS-232 port using Microsoft .NET 2.0 or later by using the System.IO.Ports.SerialPort class.&amp;#160; If you&amp;#39;re looking for USB info, &lt;a href="http://msmvps.com/blogs/coad/archive/2005/03/23/39466.aspx#usb"&gt;see here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;Way in the Past...&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Back in my early (pre C# MVP) days, I had written an article on &lt;a href="http://devhood.com/"&gt;DevHood&lt;/a&gt; titled &lt;a href="http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320"&gt;Serial COM Simply in C#&lt;/a&gt;. It became quite popular and is (at the time of writing this follow up post) the top Google search for &amp;quot;&lt;a href="http://www.google.com/search?hl=en&amp;amp;q=serial+c%23"&gt;serial c#&lt;/a&gt;&amp;quot;. Now every week I get several e-mails with people asking questions and it is high time for some serious updating.&lt;/p&gt;  &lt;p&gt;The article was (originally) written soon after .NET was introduced to the world, and other .NET serial port controls had not yet been written. So at the time, this was an easy solution. Just use the MSComm.ocx control from VS6 which most Devs had at the time. Now however, there are many easier and preferred methods than dealing with the complexities of interoping with an old legacy (non-.NET) ActiveX OCX control.&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;A Bright Future is Here!&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Today, the primary solution is to use the new &lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=SerialPort+site%3Amsdn.microsoft.com"&gt;SerialPort&lt;/a&gt; control that is part of .NET 2.0 and is &lt;em&gt;freely&lt;/em&gt; available in &lt;a href="http://msdn.microsoft.com/express"&gt;C# Express on MSDN&lt;/a&gt;. It is &lt;em&gt;considerably&lt;/em&gt; easier to use and is a true .NET component.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;Example Application &amp;amp; Sample Code: SerialPort Terminal&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;&lt;img style="border-right-width:0px;margin:5px 5px 5px 0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" border="0" alt="Download Button - Small" align="left" src="http://coad.net/Blog/Images/SerialPortRS232SerialCOMPortinC.NET_A04E/DownloadButtonSmall.png" width="146" height="50" /&gt;&lt;/a&gt; For loyal fans of the tutorial, I&amp;#39;ve written a sample code application, &lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;&lt;strong&gt;&lt;font color="#ff0000"&gt;SerialPortTerminal.zip&lt;/font&gt;&lt;/strong&gt;&lt;/a&gt;, which you can try out to see how the new SerialPort control is used. Requires Visual Studio 2005 &amp;amp; .NET 2.0 or later to compile &amp;amp; run.&amp;#160; If you just want to run the executable, try the latest &lt;a href="http://coad.net/projects/dad/SerialPortTerminal/"&gt;clickonce deployed version&lt;/a&gt; I’ve posted.&amp;#160; It is just a simple little application with very basic support for text or binary (hex) modes to send and receive data.&amp;#160; A nice feature or two is auto-detection of installed COM ports that update at runtime if you plugin or remove those USB-to-Serial adapters, also you can change the DTR and RTS levels and monitor the CTS, DSR, and CD lines.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;&lt;img style="border-right-width:0px;margin:10px 0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="SerialPort Terminal 01" border="0" alt="SerialPort Terminal 01" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/coad.metablogapi/2210.SerialPort-Terminal-01_5F00_3.png" width="505" height="349" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;Continued Support&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Due to the high volume of e-mail I&amp;#39;ve been receiving on serial port communication in general, I&amp;#39;ve wrote this post and added an &lt;a href="http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx#faq"&gt;FAQ section&lt;/a&gt; to the bottom of the post.&amp;#160; Check this first if you have questions.&amp;#160; If you post a question as a comment that hasn&amp;#39;t been answered in the post, I&amp;#39;ll add it to the FAQ section. &lt;img style="position:relative;top:2px;" src="http://coad.net/blog/images/SmileDot.gif" width="14" height="14" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;For those of you who I&amp;#39;ve directed to this blog post, please understand that I&amp;#39;m just another guy working away at a full time job (helping manage the release of &lt;a href="http://msdn.microsoft.com/teamsystem"&gt;Team System&lt;/a&gt;) who has worked with serial RS-232 ports in the past (moving on to USB now). I like to help people, hence I wrote the original article, this sample code, and the FAQ, but do not have the resources to answer additional serial port communication questions. Please check out the &lt;a href="http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx#faq"&gt;SerialCom FAQ&lt;/a&gt; for other .NET COM Port solutions and technical support options.&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;&lt;strong class="head"&gt;&lt;/strong&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;&lt;strong class="head"&gt;Get Connected Up&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You can obtain &lt;a href="http://www.adapterz.com/item.htm?id=60414"&gt;USB to Serial&lt;/a&gt; adapters and have just about as many ports on your PC as you like. I carry around two adapters with a &lt;a href="http://www.buyextras.com/numoaddb9fef.html"&gt;null modem&lt;/a&gt; (&lt;a href="http://www.google.com/search?hl=en&amp;amp;q=null+modem"&gt;what is it?&lt;/a&gt;, search &lt;a href="http://froogle.google.com/froogle?hl=en&amp;amp;lr=&amp;amp;tab=wf&amp;amp;scoring=p&amp;amp;q=null+modem+db9"&gt;Froogle&lt;/a&gt;) between them so I can create a loopback to send &amp;amp; receive through to separate ports on most any computer. I&amp;#39;d recommend doing the same for when writing code for the serial port.&lt;/p&gt;  &lt;p&gt;If you&amp;#39;d like to quickly and easily create your own external devices to communicate with the PC, I recommend starting with the &lt;a href="http://www.basicstamp.com"&gt;Parallax BASIC Stamp&lt;/a&gt; modules. Parallax has lots of easy &lt;a href="http://www.parallax.com/Store/Accessories/tabid/84/Default.aspx"&gt;accessories&lt;/a&gt; (such as LCDs, RF, Sounds, AD &amp;amp; DA, etc) for their modules. After that you could migrate to an &lt;a href="http://www.atmel.com"&gt;Atmel Microcontroller&lt;/a&gt; (recommended) or &lt;a href="http://www.microchip.com"&gt;Microchip PIC&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong class="head"&gt;Let&amp;#39;s Have the Code&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Here is an example of how easy it is to use the new SerialPort control.&lt;/p&gt;  &lt;p&gt;Very simply, here is how you can send a bit of data out the port.&lt;/p&gt;  &lt;p&gt;&lt;code&gt;     &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;background:white;border-top:black 1px solid;border-right:black 1px solid;" cellpadding="6"&gt;&lt;tbody&gt;         &lt;tr&gt;           &lt;td&gt;             &lt;pre style="display:inline;"&gt;&lt;div&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; This is a new namespace in .NET 2.0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#008000;"&gt;// that contains the SerialPort class&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.IO.Ports;

&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; SendSampleData()
{
  &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Instantiate the communications&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#008000;"&gt;  // port with some basic settings&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  SerialPort port &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPort(&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;COM1&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#000000;"&gt;9600&lt;/span&gt;&lt;span style="color:#000000;"&gt;, Parity.None, &lt;/span&gt;&lt;span style="color:#000000;"&gt;8&lt;/span&gt;&lt;span style="color:#000000;"&gt;, StopBits.One);
  
  &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Open the port for communications&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  port.Open();
  
  &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Write a string&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  port.Write(&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Hello World&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;);
  
  &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Write a set of bytes&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  port.Write(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;byte&lt;/span&gt;&lt;span style="color:#000000;"&gt;[] {&lt;/span&gt;&lt;span style="color:#000000;"&gt;0x0A&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#000000;"&gt;0xE2&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#000000;"&gt;0xFF&lt;/span&gt;&lt;span style="color:#000000;"&gt;}, &lt;/span&gt;&lt;span style="color:#000000;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;, &lt;/span&gt;&lt;span style="color:#000000;"&gt;3&lt;/span&gt;&lt;span style="color:#000000;"&gt;);
  
  &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Close the port&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;  port.Close();
}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;&lt;/table&gt;
  &lt;/code&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;Now let&amp;#39;s take a look at what it takes to read data in from the communications port. This demonstrates reading text; for an example of reading binary data, see my &lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;SerialPortTerminal.zip&lt;/a&gt; sample app. &lt;/p&gt;

&lt;ol style="margin-top:0px;"&gt;
  &lt;li&gt;Create a new &amp;quot;Console Application&amp;quot; and replace all the default class code with this code &lt;/li&gt;

  &lt;li&gt;Add a reference to &amp;quot;System.Windows.Forms&amp;quot; to the project &lt;/li&gt;

  &lt;li&gt;Run w/ F5, to exit the app, press Ctrl-Break. &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msmvps.com/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=161&amp;amp;postid=39466#GetConnectedUp"&gt;Get Connected Up&lt;/a&gt; with two USB to Serial adapters and a null modem &lt;/li&gt;

  &lt;li&gt;Use another app, the code above, or the &lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;SerialPortTerminal.zip&lt;/a&gt; example to send data and watch it come in with this code &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
    &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;background:white;border-top:black 1px solid;border-right:black 1px solid;" cellpadding="6"&gt;&lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;pre style="display:inline;"&gt;&lt;div&gt;&lt;span style="color:#0000ff;"&gt;#region&lt;/span&gt;&lt;span style="color:#000000;"&gt; Namespace Inclusions&lt;/span&gt;&lt;span style="color:#000000;"&gt;
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="color:#000000;"&gt; System;
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.IO.Ports;
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.Windows.Forms;
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;#endregion&lt;/span&gt;&lt;span style="color:#000000;"&gt;

&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;namespace&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPortExample
{
  &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPortProgram
  {
    &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Create the serial port with basic settings&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPort port &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPort(&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;COM1&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;,&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;      9600&lt;/span&gt;&lt;span style="color:#000000;"&gt;, Parity.None, &lt;/span&gt;&lt;span style="color:#000000;"&gt;8&lt;/span&gt;&lt;span style="color:#000000;"&gt;, StopBits.One);

    [STAThread]
    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; Main(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt;[] args)
    { 
      &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Instatiate this class&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;      &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPortProgram();
    }

    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPortProgram()
    {
      Console.WriteLine(&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;Incoming Data:&lt;/span&gt;&lt;span style="color:#000000;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;);

      &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Attach a method to be called when there&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#008000;"&gt;      // is data waiting in the port&amp;#39;s buffer&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;      port.DataReceived &lt;/span&gt;&lt;span style="color:#000000;"&gt;+=&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;        SerialDataReceivedEventHandler(port_DataReceived);

      &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Begin communications&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;      port.Open();
      
      &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Enter an application loop to keep this thread alive&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;      Application.Run();
    }

    &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; port_DataReceived(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="color:#000000;"&gt; sender,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;      SerialDataReceivedEventArgs e)
    {
      &lt;/span&gt;&lt;span style="color:#008000;"&gt;//&lt;/span&gt;&lt;span style="color:#008000;"&gt; Show all the incoming data in the port&amp;#39;s buffer&lt;/span&gt;&lt;span style="color:#008000;"&gt;
&lt;/span&gt;&lt;span style="color:#000000;"&gt;      Console.WriteLine(port.ReadExisting());
    }
  }
}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;&lt;/table&gt;
  &lt;/code&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;One of the (several) new methods that is supported, and one I&amp;#39;m very glad is finally here, is the ability to obtain a list of the COM ports installed on the computer (ex: COM1, COM2, COM4). This is definately helpful when you want to present the list of ports avalible for the user to select from (as in the &lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;SerialPortTerminal.zip&lt;/a&gt; Win App example).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
    &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;background:white;border-top:black 1px solid;border-right:black 1px solid;" cellpadding="6"&gt;&lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;pre style="display:inline;"&gt;&lt;div&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt;&lt;span style="color:#000000;"&gt; (&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; s &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;in&lt;/span&gt;&lt;span style="color:#000000;"&gt; SerialPort.GetPortNames())
  System.Diagnostics.Trace.WriteLine(s);&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;&lt;/table&gt;
  &lt;/code&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;Here are two helpful little methods for sending files through the serial port. Of course, these are the bare essentials and as always, you should check to make sure the port is open first (port.IsOpen) and use try/catch around trying to open a file, but you get the gist with this code. The binary sending routine is limited to about 2GB (the size of an int), but this should be okay for most uses. &lt;img style="position:relative;top:2px;" src="http://coad.net/blog/images/SmileDot.gif" width="14" height="14" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
    &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;background:white;border-top:black 1px solid;border-right:black 1px solid;" cellpadding="6"&gt;&lt;tbody&gt;
        &lt;tr&gt;
          &lt;td&gt;
            &lt;pre style="display:inline;"&gt;&lt;div&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="color:#000000;"&gt; System.IO;

&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; SendTextFile(&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;  SerialPort port, &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; FileName)
{ port.Write(File.OpenText(FileName).ReadToEnd()); }

&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="color:#000000;"&gt; &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="color:#000000;"&gt; SendBinaryFile(&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;  SerialPort port, &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="color:#000000;"&gt; FileName)
{
  &lt;/span&gt;&lt;span style="color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="color:#000000;"&gt; (FileStream fs &lt;/span&gt;&lt;span style="color:#000000;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt; File.OpenRead(FileName))
    port.Write((&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="color:#000000;"&gt; BinaryReader(fs)).ReadBytes(&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#000000;"&gt;      (&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt;)fs.Length), &lt;/span&gt;&lt;span style="color:#000000;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;, (&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="color:#000000;"&gt;)fs.Length);
}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;&lt;/table&gt;
  &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;a id="ProjectPhotos"&gt;&lt;/a&gt;&lt;strong class="head"&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong class="head"&gt;RS-232 Project Photos&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Each of these involve RS-232 serial port communications. 
  &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;padding-bottom:4px;padding-left:4px;padding-right:4px;font:10pt verdana;border-top:black 1px solid;border-right:black 1px solid;padding-top:4px;" class="Photo"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td align="center"&gt;&lt;img src="http://coad.net/blog/images/SerialPortRS232SerialCOMPortinC.NET_EE09/SerialComBASICStamp4.jpg" width="436" height="351" alt="" /&gt; &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="center"&gt;Just what&amp;#39;s needed to get started with microcontrollers, 
          &lt;br /&gt;a Basic Stamp, mini LCD display, power, and RS-232 port.&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;

  &lt;br /&gt;

  &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;padding-bottom:4px;padding-left:4px;padding-right:4px;font:10pt verdana;border-top:black 1px solid;border-right:black 1px solid;padding-top:4px;" class="Photo"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td align="center"&gt;&lt;img src="http://coad.net/blog/images/SerialPortRS232SerialCOMPortinC.NET_EE09/SerialComNullModem4.jpg" width="415" height="263" alt="" /&gt; &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="center"&gt;Two USB to Serial adapters with a null modem 
          &lt;br /&gt;to loopback and test your serial software.&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;

  &lt;br /&gt;

  &lt;table style="border-bottom:black 1px solid;border-left:black 1px solid;padding-bottom:4px;padding-left:4px;padding-right:4px;font:10pt verdana;border-top:black 1px solid;border-right:black 1px solid;padding-top:4px;" class="Photo"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td align="center"&gt;&lt;img src="http://coad.net/blog/images/SerialPortRS232SerialCOMPortinC.NET_EE09/SerialComSerialProject4.jpg" width="470" height="274" alt="" /&gt; &lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td align="center"&gt;The brains to a mini automated radio station that let me 
          &lt;br /&gt;control my PC &amp;amp; home using my HAM radio from around town.&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;strong class="head"&gt;Port Wiring Notes&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;DB9 Male (Pin Side)                   DB9 Female (Pin Side)
DB9 Female (Solder Side)              DB9 Male (Solder Side)
    -------------                          -------------
    \ 1 2 3 4 5 /                          \ 5 4 3 2 1 /
     \ 6 7 8 9 /                            \ 9 8 7 6 /
      ---------                              ---------

DB9 Female to DB9 Female Null-Modem Wiring
 2 |  3 |  7 |  8 | 6&amp;amp;1|  5 |  4
---- ---- ---- ---- ---- ---- ---- 
 3 |  2 |  8 |  7 |  4 |  5 | 6&amp;amp;1

9-pin   25-pin  Assignment                 From PC
------  ------  -------------------------  ------------
Shield  1       Case Ground                Gnd
1       8       DCD (Data Carrier Detect)  Input
2       3       RX  (Receive Data)         Input
3       2       TX  (Transmit Data)        Output
4       20      DTR (Data Terminal Ready)  Output
5       7       GND (Signal Ground)        Gnd
6       6       DSR (Data Set Ready)       Input
7       4       RTS (Request To Send)      Output
8       5       CTS (Clear To Send)        Input
9       22      RI  (Ring Indicator)       Input

- RTS &amp;amp; DTR are binary outputs that can be manually set and held
- DCD, DSR, CTS, and RI are binary inputs that can be read
- RX &amp;amp; TX can not be set manually and are controlled by the UART
- maximum voltages are between -15 volts and +15 volts
- binary outputs are between +5 to +15 volts and -5 to -15 volts
- binary inputs are between +3 to +15 volts and -3 to -15 volts
- input voltages between -3 to +3 are undefined while output voltages
  between -5 and +5 are undefined
- positive voltages indicate ON or SPACE, negative voltages indicate
  OFF or MARK&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;
&lt;strong class="head"&gt;Other Resources&lt;/strong&gt; 

&lt;p&gt;Here are some additional sites, libraries, tutorials, etc. These are links that I just found around the net and am providing for convenience (they are not endorsed).&lt;/p&gt;

&lt;ul style="margin-top:0px;"&gt;
  &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/RS-232"&gt;RS-232 on Wikipedia&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/library/30swa673(en-us,vs.80).aspx"&gt;SerialPort on MSDN&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Search on Google &lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=SerialPort+C%23"&gt;#1&lt;/a&gt;, &lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=serialport+.net"&gt;#2&lt;/a&gt;, &lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=.net+serial+port"&gt;#3&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://ourworld.compuserve.com/homepages/richard_grier/CFSerial.htm"&gt;CFSerialIO&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://www.opennetcf.org/SourceBrowse/browse.aspx?f=d:/sites/OpenNETCF/InetPub/wwwroot/Source/OpenNETCF/IO/Serial"&gt;OpenNETCF Port&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Where CF = Compact Framework&lt;/p&gt;

&lt;p&gt;&lt;strong class="head"&gt;&lt;/strong&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;strong class="head"&gt;The Final Say (aka Conclusion)&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The new SerialPort class in .NET 2.0 rocks! It is much easier to use than getting the old MSComm.ocx control going in a .NET app, contains new functionality, is a &amp;#39;native&amp;#39; .NET control, has docs built into the MSDN Library, and is easy to use.&lt;/p&gt;

&lt;br /&gt;

&lt;h3&gt;&lt;a name="faq"&gt;&lt;/a&gt;&lt;strong class="head"&gt;&lt;font color="#800000"&gt;Frequently Asked Questions (FAQ)&lt;/font&gt;&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;I&amp;#39;m adding this section (as of 8/10/06) to address the common questions I get on this post and through e-mail.&amp;#160; Chances are, if you ask a good question in the comments here, I&amp;#39;ll post it here for others to see easily. Some of the most popular topics are &lt;a href="#usb"&gt;usb&lt;/a&gt;, &lt;a href="#device"&gt;device&lt;/a&gt;, &lt;a href="#cable"&gt;cable&lt;/a&gt;, &lt;a href="#lines"&gt;lines&lt;/a&gt;, &lt;a href="#power"&gt;power&lt;/a&gt;, &lt;a href="#packets"&gt;packets&lt;/a&gt;, &lt;a href="#bridge"&gt;bridge&lt;/a&gt;, &lt;a href="#help"&gt;help&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Q: When updating a control (like a text box) while in the DataRecieved event, I get an error. 
      &lt;br /&gt;&lt;/strong&gt;A: The SerialPort class raises events on a separate thread than the main form was create on.&amp;#160; Windows Forms controls must be modified only on their original thread.&amp;#160; Thankfully there is an easy way to do this.&amp;#160; Each Windows control has a &amp;quot;Invoke&amp;quot; method which will run code on the control&amp;#39;s original thread.&amp;#160; So to put the recently received data into a text box (txtLog), this would do it:&amp;#160;&amp;#160; txtLog.Invoke(new EventHandler(delegate { txtLog.Text += comport.ReadExisting(); });&amp;#160;&amp;#160; You can see this more in action in the &amp;quot;Log&amp;quot; event of &amp;quot;Terminal.cs&amp;quot; my sample code project, &lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;SerialPortTerminal.zip&lt;/a&gt;. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: I can&amp;#39;t find the System.IO.Ports namespace. 
      &lt;br /&gt;&lt;/strong&gt;A: Using Visual Studio 2003?&amp;#160; The new namespace, and SerialPort class, is part of .NET 2.0 and Visual Studio 2005.&amp;#160; It is not included in .NET 1.x (and Visual Studio 2003).&amp;#160; Even if you have .NET 2.0 or Visual Studio 2005 installed, you can not access the class from within Visual Studio 2003. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: I only have .NET 1.1, what can I do? 
      &lt;br /&gt;&lt;/strong&gt;A: Upgrade to .NET 2.0.&amp;#160; Seriously, it&amp;#39;s free.&amp;#160; In fact, you can get the great C# and VB Visual Studio Interactive Development Environment (IDE) editors for FREE now with &lt;a href="http://msdn.microsoft.com/vstudio/express/visualcsharp/"&gt;C# Express&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/vstudio/express/vb/"&gt;VB Express&lt;/a&gt;.&amp;#160; The &lt;a href="http://msdn.microsoft.com/netframework/downloads/updates/"&gt;.NET 2.0 Software Development Kit (SDK)&lt;/a&gt; for command-line development is also free.&amp;#160; If you really must stay in .NET 1.1, you can use the technique I talk about in &lt;a href="http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320"&gt;Serial COM Simply in C#&lt;/a&gt; or a 3rd party library. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: I&amp;#39;m sending data to my device, but it is not responding.&lt;/strong&gt; 

    &lt;br /&gt;A: First make sure the device will respond using a standard app like Hyperterminal.&amp;#160; Check the settings (baud rate, data bits, stop bits, etc) and make sure they match with your code.&amp;#160; Try sending binary data via binary arrays.&amp;#160; Many devices expect a carriage return at the end of a command, so be sure to send 0x0D or \n.&amp;#160; String data can be easily converted to a binary array using: 

    &lt;br /&gt;byte[] data = System.Text.ASCIIEncoding.Default.GetBytes(&amp;quot;Hello World\n&amp;quot;); 

    &lt;br /&gt;com.Write(data, 0, data.Length); 

    &lt;br /&gt;Many devices require several carriage returns first to sync baud rates, so send several, like: com.Output(&amp;quot;&amp;quot;.PadLeft(9, &amp;#39;\n&amp;#39;));&amp;#160; It you&amp;#39;re communicating with a modem, make sure Echo Back is turned on.&amp;#160; Send &amp;quot;ATE1\n&amp;quot;.&amp;#160; Other than this, just keep trying and playing around with it.&amp;#160; It can be hard because you don&amp;#39;t see the response from the device as easily as you would with a terminal app. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: When I put received data to a text box or rich text box, I get a strange symbols. 
      &lt;br /&gt;&lt;/strong&gt;A: The default font of text boxes is designed only to show standard characters.&amp;#160; Try using &amp;quot;CharMap&amp;quot; (a free tool in WinXP, click &amp;quot;Start&amp;quot;, &amp;quot;Run&amp;quot;, type &amp;quot;CharMap&amp;quot;, enter).&amp;#160; &amp;quot;Terminal&amp;quot; is a font designed to show classic ASCII characters and is what most terminal apps (like my sample code and Hyperterminal) use.&amp;#160; There are also many ASCII codes that won&amp;#39;t display correctly.&amp;#160; This is why I choose to show the hex data instead of an ASCII string a lot of the time.&amp;#160; System.Convert.ToString(mybyte, 16) will convert a byte to a string hex code, for example: byte b = 13; string s = Convert.ToStrong(b, 16).PadLeft(2, &amp;#39;0&amp;#39;), then s will contain &amp;quot;0D&amp;quot;.&amp;#160; See the &amp;quot;ByteArrayToHexString&amp;quot; and &amp;quot;HexStringToByteArray&amp;quot; methods in my sample app, &lt;a href="http://coad.net/Blog/Resources/SerialPortTerminal.zip"&gt;SerialPortTerminal.zip&lt;/a&gt;. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;a name="usb"&gt;&lt;/a&gt;&lt;strong&gt;Q: What about USB communications?&amp;#160; How can I do USB?&lt;/strong&gt; 

    &lt;br /&gt;This blog post isn&amp;#39;t about USB.&amp;#160; Believe me, I wish the .NET framework supported USB natively, and I&amp;#39;m doing what I can here at Microsoft to see USB get into the framework in the future.&amp;#160; For now, you can use a &lt;/a&gt;&lt;a href="http://www.adapterz.com/item.htm?id=60414"&gt;USB to Serial adapter&lt;/a&gt;.&amp;#160; I use a lot of these.&amp;#160; They plug into the USB port, then appear just as a SerialPort to the PC.&amp;#160; &lt;br /&gt;

    &lt;br /&gt;For native USB devices, microcontroller vendors such as &lt;a href="http://www.microchip.com/"&gt;Microchip&lt;/a&gt;, &lt;a href="http://www.atmel.com/"&gt;Atmel&lt;/a&gt;, and &lt;a href="http://www.ti.com/"&gt;TI&lt;/a&gt; make chips that do this for projects as well as have chips that support USB natively (I&amp;#39;m using the &lt;a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010273"&gt;PIC18F2455&lt;/a&gt;).&amp;#160; There is a &lt;em&gt;lot of info &lt;/em&gt;and USB C# libraries readily available online with a quick search, try &lt;b&gt;&lt;a href="http://www.google.com/search?hl=en&amp;amp;q=usb+C%23"&gt;USB C#&lt;/a&gt;&lt;/b&gt;, which turns up resources like this &lt;a href="http://www.vsj.co.uk/articles/display.asp?id=600"&gt;great article&lt;/a&gt; or this &lt;a href="http://www.codeproject.com/KB/cs/USB_HID.aspx"&gt;USB HID C# open source project&lt;/a&gt;.&amp;#160; &lt;br /&gt;

    &lt;br /&gt;For simple USB-to-Serial bridges that allow your device to communicate via RS-232 but connect via USB to the PC, check out the section below on &lt;a href="#bridge"&gt;USB-to-Serial Bridge Chipsets&lt;/a&gt; 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: Can I use the sample code here in my own projects (commercial or not)?&lt;/strong&gt; 

    &lt;br /&gt;Yes!&amp;#160; All sample code on my blog is free public domain material.&amp;#160; I&amp;#39;m not a legal guy so I don&amp;#39;t know the exact words to use, but I&amp;#39;ll try...&amp;#160; I&amp;#39;m not responsible for any problems!&amp;#160; Use at your own rick etc.&amp;#160; However, have at it, if it helps you out, fantastic, that&amp;#39;s what it&amp;#39;s here for. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: When using SerialPort.Open() (or SerialPort.PortOpen = true) I get the exception &amp;quot;UnauthorizedAccessException&amp;quot; or &lt;strong&gt;the error &amp;quot;An unhandled exception of type &amp;#39;System.Runtime.InteropServices.COMException&amp;#39; occurred in axinterop.mscommlib.dll&amp;quot;&lt;/strong&gt;&lt;/strong&gt; 

    &lt;br /&gt;It may be one of a few factors: 

    &lt;br /&gt;

    &lt;ul style="margin-top:0px;"&gt;
      &lt;li&gt;It may require Administrative privileges to use the port. &lt;/li&gt;

      &lt;li&gt;The port may already be open by another program, only one app can use a port at a time. &lt;/li&gt;

      &lt;li&gt;The port may not exist on the computer (this happens a lot).&amp;#160; Verify the port you&amp;#39;re trying to open is listed in the Device Manager (FAQ #9). &lt;/li&gt;

      &lt;li&gt;The name being provided is not exactly correct. 
        &lt;br /&gt;Use the full name of the port when opening, like &amp;quot;COM1&amp;quot; (not &amp;quot;1&amp;quot;) &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: How do I know what COM ports are on my PC?&lt;/strong&gt; 

    &lt;br /&gt;Use the Device Manager (&amp;quot;Start&amp;quot;, &amp;quot;Run&amp;quot;, &amp;quot;devmgmt.msc&amp;quot;) and look for the &amp;quot;Ports&amp;quot; node (see below).&amp;#160; If you &lt;u&gt;don&amp;#39;t see a Ports node&lt;/u&gt;, it&amp;#39;s because there are no Serial or Parallel ports installed in the PC.&amp;#160; You can also use System.IO.Ports.SerialPort.GetPortNames() to return the list of available ports.&amp;#160; Many laptops these day&amp;#39;s don&amp;#39;t have a serial port.&amp;#160; You can get more serial ports very easily today with &lt;a href="http://www.google.com/search?hl=en&amp;amp;q=USB+Serial+Adapter"&gt;USB to Serial adapters&lt;/a&gt;. 

    &lt;br /&gt;

    &lt;br /&gt;&lt;img src="http://msmvps.com/blogs/coad/WindowsLiveWriter/SerialPortRS232SerialCOMPortinC.NET_9269/DeviceManagerforPorts5.png" width="274" height="519" alt="" /&gt; 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;a name="device"&gt;&lt;/a&gt;&lt;strong&gt;Q: How do I communicate with my specific device?&amp;#160; Modem, Mobile Phone, LED/LCD Display, Scanner, GPS, GSM/GPRS, CDMA, test equipment, etc 
      &lt;br /&gt;&lt;/strong&gt;This post is specific to device independent serial port communications.&amp;#160; RS-232 is a hardware standard and there are hundreds (if not thousands) of software protocols that are created for communicating over RS-232.&amp;#160; An analogy would be that physical telephone hardware is used around the globe (like the RS-232 hardware standard), but there are hundreds of languages people can speak through the phone to each other to communicate (the software protocol).&amp;#160; You will need to find information about the protocol used for your specific device elsewhere.&amp;#160; I&amp;#39;d recommend looking on the manufacture&amp;#39;s website, writing/calling the manufacture, or searching online for your specific device.&amp;#160; Sometimes you can find fans or hackers of a device that congregate on a forum.&amp;#160; Some protocols can be found through wikipedia, like the GPS &lt;a href="http://en.wikipedia.org/wiki/NMEA_0183"&gt;NMEA 0183&lt;/a&gt; serial protocol that GPS units use to send their data via a serial connection.&amp;#160; Honestly the RS-232 communications is the easy part, I personally find the more interesting challenge is writing software for the particular protocol in use.&amp;#160; Best of luck in finding specifications on the protocol you’re device uses! 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;a name="lines"&gt;&lt;/a&gt;&lt;strong&gt;Q: What control lines can I manually manipulate? 
      &lt;br /&gt;&lt;/strong&gt;Control lines on an RS-232 serial port were introduced to provide flow control of serial data.&amp;#160; Even though a modem or PC may be rated for a particular baud rate, it doesn’t always mean that the device can process the data that fast.&amp;#160; For example, bits may flow in through a modem at 2400 bps (bits per second) but in the early days a PC couldn’t process the data fast enough, so it would toggle control lines to tell the modem that it was read for more data or to ‘pause’ send it data.&amp;#160; Now since PCs are quite fast these lines are mostly ignored.&amp;#160; They can be used as a simple way to toggle an LED or send or receive high or low states. RTS/CTS control flow is one such technique which is supported natively by the control via the Handshake property. 

    &lt;br /&gt;

    &lt;br /&gt;Lines marked ‘Output’ in the table can be set by the serial port to a high or low state (True or False) and the ‘Input’ lines can be read as high or low.&amp;#160; You can use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.pinchanged.aspx"&gt;PinChanged&lt;/a&gt; event to be notified when one of the input pins changes.&amp;#160; The &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.handshake.aspx"&gt;Handshake&lt;/a&gt; property can be set to use RTS/CTS (uses hardware control lines) or XON/XOFF (uses software) or both. 

    &lt;br /&gt;

    &lt;br /&gt;

    &lt;table border="0" cellspacing="0" cellpadding="2" width="497"&gt;&lt;tbody&gt;
        &lt;tr&gt;
          &lt;td valign="top" width="98"&gt;&lt;strong&gt;Control Line&lt;/strong&gt;&lt;/td&gt;

          &lt;td valign="top" width="151"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;

          &lt;td valign="top" width="83"&gt;&lt;strong&gt;DB9 Pin&lt;/strong&gt;&lt;/td&gt;

          &lt;td valign="top" width="85"&gt;&lt;strong&gt;SerialPort Property&lt;/strong&gt;&lt;/td&gt;

          &lt;td valign="top" width="78"&gt;&lt;strong&gt;I/O&lt;/strong&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;td valign="top" width="98"&gt;DTR&lt;/td&gt;

          &lt;td valign="top" width="151"&gt;Data Terminal Ready&lt;/td&gt;

          &lt;td valign="top" width="83"&gt;4&lt;/td&gt;

          &lt;td valign="top" width="85"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.dtrenable.aspx"&gt;DtrEnable&lt;/a&gt;&lt;/td&gt;

          &lt;td valign="top" width="78"&gt;Output&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;td valign="top" width="98"&gt;RTS&lt;/td&gt;

          &lt;td valign="top" width="151"&gt;Request to Send&lt;/td&gt;

          &lt;td valign="top" width="83"&gt;7&lt;/td&gt;

          &lt;td valign="top" width="85"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.rtsenable.aspx"&gt;RtsEnable&lt;/a&gt;&lt;/td&gt;

          &lt;td valign="top" width="78"&gt;Output&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;td valign="top" width="98"&gt;CTS&lt;/td&gt;

          &lt;td valign="top" width="151"&gt;Clear to Send&lt;/td&gt;

          &lt;td valign="top" width="83"&gt;8&lt;/td&gt;

          &lt;td valign="top" width="85"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.ctsholding.aspx"&gt;CtsHolding&lt;/a&gt;&lt;/td&gt;

          &lt;td valign="top" width="78"&gt;Input&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;td valign="top" width="98"&gt;DSR&lt;/td&gt;

          &lt;td valign="top" width="151"&gt;Data Set Ready&lt;/td&gt;

          &lt;td valign="top" width="83"&gt;6&lt;/td&gt;

          &lt;td valign="top" width="85"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.dsrholding.aspx"&gt;DsrHolding&lt;/a&gt;&lt;/td&gt;

          &lt;td valign="top" width="78"&gt;Input&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;td valign="top" width="98"&gt;CD (or DCD)&lt;/td&gt;

          &lt;td valign="top" width="151"&gt;Data Carrier Detect&lt;/td&gt;

          &lt;td valign="top" width="83"&gt;1&lt;/td&gt;

          &lt;td valign="top" width="85"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.dsrholding.aspx"&gt;CDHolding&lt;/a&gt;&lt;/td&gt;

          &lt;td valign="top" width="78"&gt;Input&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/tbody&gt;&lt;/table&gt;

    &lt;br /&gt;&lt;/a&gt;For detecting a Ring Indication, see the next question. 

    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: How do you detect the Ring Indicator line?&lt;/strong&gt; 

    &lt;br /&gt;There isn’t a property off of the SerialPort class to test the current state of the Ring Indicator (DB9 pin 9), but there is an event that gets triggered, PinChanged.&amp;#160;&amp;#160; You can attach an event listener to PinChanged and when the event is called, SerialPinChangedEventArgs is passed with a EventType property of type SerialPinChange which will indicate if a ring indication was detected.&amp;#160; Here is an example:

    &lt;br /&gt; 

    &lt;br /&gt;

    &lt;div style="border-bottom:black 1px solid;border-left:black 1px solid;padding-bottom:0.2em;padding-left:0.2em;padding-right:0.2em;font-family:courier new;background:white;color:black;font-size:10pt;border-top:black 1px solid;border-right:black 1px solid;padding-top:0.2em;"&gt;
      &lt;p style="margin:0px;"&gt;comport.PinChanged += &lt;span style="color:blue;"&gt;new&lt;/span&gt; SerialPinChangedEventHandler(comport_PinChanged);&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;void&lt;/span&gt; comport_PinChanged(&lt;span style="color:blue;"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af;"&gt;SerialPinChangedEventArgs&lt;/span&gt; e)&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;{&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160; &lt;span style="color:blue;"&gt;if&lt;/span&gt; (e.EventType == &lt;span style="color:#2b91af;"&gt;SerialPinChange&lt;/span&gt;.Ring) RingDetected();&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;}&lt;/p&gt;
    &lt;/div&gt;

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;a name="power"&gt;&lt;/a&gt;&lt;strong&gt;Q: What pins can I use for powering devices, a high signal, or for boolean input &amp;amp; output? 
      &lt;br /&gt;&lt;/strong&gt;The TX &amp;amp; RX pins carry the standard serial signal, but the other pins can be used as high/low input/output pins.&amp;#160; The output pins (4 DTR or 8 CTS), supply 5 to 15 volts (15v is proper RS-232 standard) when high and 0 to -15 volts when low.&amp;#160; They only supply flea current so they&amp;#39;re not meant to be used for powering any devices (like USB is designed for).&amp;#160; However, they can be used as a reference voltage or for switching to one of the input pins for a high or low signal.&amp;#160; The input pins (1 DCD, 6 DSR, 8 CTS, and 9 RI) can be used to detect a high or low signal.&amp;#160; Proper RS-232 signal levels are -15v for a low and +15v for a high (compared to ground, pin 5).&amp;#160; A &lt;/a&gt;&lt;a href="http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&amp;amp;storeId=10001&amp;amp;catalogId=10001&amp;amp;productId=698576"&gt;MAX232&lt;/a&gt; or similar chip takes a TTL 0-5v input and produces the -15v to +15v levels.&amp;#160; However, most PC RS-232 COM ports will accept a 0v for low and 5v for high, but it is not guaranteed and alters from PC to PC.&amp;#160; If you want a simple &amp;quot;toggle high&amp;quot;, just hold pin 4 DTR high, and switch it to pin 1 DCD.&amp;#160; The .NET SerialPort class has easy to use properties for switching the output pins high or low and for detecting the current level of the input pins.&amp;#160; I have been able to use pin 4 DTR for a very low current (20ma max) PIC processors, but not reliably.&amp;#160; I prefer to always supply external power and use pin 4 as a signal to turn on or off my device.&amp;#160; I&amp;#39;ll attach pin 4 to a transistor that switches my power source to my PIC to turn it on or off. 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;a name="packets"&gt;&lt;/a&gt;&lt;strong&gt;Q: What about ‘packets’?&amp;#160; Does RS-232 support any commands or data segregation?&amp;#160; OR&amp;#160; Data comes in at seemingly random times? 
      &lt;br /&gt;&lt;/strong&gt;Serial data flow through RS-232 has nothing to do with ‘packets’.&amp;#160; It’s just a stream of bytes in and out.&amp;#160; There is no guarantee that data arrives together. 

    &lt;br /&gt;

    &lt;br /&gt;&lt;strong&gt;Packet Protocols 
      &lt;br /&gt;&lt;/strong&gt;Any notion of data compartmentalization (packets) would have to be coded by you for your unique use.&amp;#160; Much of my time working with serial has been spent on defining useful packet like protocols, that usually include some type of header, command structure, and CRC check.&amp;#160; For example, the first two bytes are the packet length, the next two bytes is the command, next two bytes are parameters, and the last byte is a CRC.&amp;#160; Then my apps would buffer incoming data and look in the buffer for valid packets.&amp;#160; Of course it differs depending on the device you’re working with and your specific needs.&amp;#160; USB does have specific communications protocol defined, one of them being command based, like the little packet just mentioned.&amp;#160; But with USB, you’re able to get the whole command and parameter together at once, with serial you have to create the protocol yourself, buffer, and parse the data.&amp;#160; My &lt;/a&gt;&lt;a href="http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=320"&gt;previous serial post&lt;/a&gt; has more info under the header “Protocol Development”. 

    &lt;br /&gt;

    &lt;br /&gt;&lt;strong&gt;Buffering Incoming Data&lt;/strong&gt; 

    &lt;br /&gt;Since bytes may come in at any time, buffering incoming data is critical.&amp;#160; For example, you may send a command out to your device, and the response back to the PC could trigger a single DataReceived event with all the 30 bytes of response data in the receive buffer.&amp;#160; Or more likely, it could be any number of separate triggers of the DataReceived (up to the number of bytes received), like 4 triggers, first with 2 bytes, then 15 bytes, then 1 byte, then 12 bytes.&amp;#160; Don’t look for a complete response in a single DataReceived call, instead: 

    &lt;br /&gt;1. buffer the incoming data 

    &lt;br /&gt;2. then scan your buffer to find complete data 

    &lt;br /&gt;3. remove the used data from the buffer 

    &lt;br /&gt;

    &lt;br /&gt;To buffer incoming data, use a coding pattern like this: 

    &lt;br /&gt;(download the code &lt;a href="http://coad.net/blog/resources/SerialComBuffering.zip"&gt;SerialComBuffering.zip&lt;/a&gt;) 

    &lt;br /&gt;

    &lt;div style="border-bottom:black 1px solid;border-left:black 1px solid;padding-bottom:0.75em;padding-left:0.75em;padding-right:0.75em;font-family:consolas;background:white;color:black;font-size:10pt;border-top:black 1px solid;border-right:black 1px solid;padding-top:0.75em;"&gt;
      &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; &lt;span style="color:purple;"&gt;System&lt;/span&gt;;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; &lt;span style="color:purple;"&gt;System&lt;/span&gt;.&lt;span style="color:purple;"&gt;IO&lt;/span&gt;.&lt;span style="color:purple;"&gt;Ports&lt;/span&gt;;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;using&lt;/span&gt; &lt;span style="color:purple;"&gt;System&lt;/span&gt;.&lt;span style="color:purple;"&gt;Collections&lt;/span&gt;.&lt;span style="color:purple;"&gt;Generic&lt;/span&gt;;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&lt;span style="color:blue;"&gt;namespace&lt;/span&gt; &lt;span style="color:purple;"&gt;SerialComBuffering&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;{&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160; &lt;span style="color:blue;"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Program&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160; {&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;SerialPort&lt;/span&gt; &lt;span style="color:purple;"&gt;com&lt;/span&gt; = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SerialPort&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;SerialPort&lt;/span&gt;.&lt;span style="color:purple;"&gt;GetPortNames&lt;/span&gt;()[0], &lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 9600, &lt;span style="color:#2b91af;"&gt;Parity&lt;/span&gt;.&lt;span style="color:purple;"&gt;None&lt;/span&gt;, 8, &lt;span style="color:#2b91af;"&gt;StopBits&lt;/span&gt;.&lt;span style="color:purple;"&gt;One&lt;/span&gt;);&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;byte&lt;/span&gt;&amp;gt; &lt;span style="color:purple;"&gt;bBuffer&lt;/span&gt; = &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;byte&lt;/span&gt;&amp;gt;();&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;string&lt;/span&gt; &lt;span style="color:purple;"&gt;sBuffer&lt;/span&gt; = &lt;span style="color:#2b91af;"&gt;String&lt;/span&gt;.&lt;span style="color:purple;"&gt;Empty&lt;/span&gt;;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;static&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; &lt;span style="color:purple;"&gt;Main&lt;/span&gt;(&lt;span style="color:blue;"&gt;string&lt;/span&gt;[] &lt;span style="color:purple;"&gt;args&lt;/span&gt;)&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; { &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Program&lt;/span&gt;(); }&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;Program&lt;/span&gt;()&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;com&lt;/span&gt;.&lt;span style="color:purple;"&gt;DataReceived&lt;/span&gt; += &lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;SerialDataReceivedEventHandler&lt;/span&gt;(&lt;span style="color:purple;"&gt;com_DataReceived&lt;/span&gt;);&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;com&lt;/span&gt;.&lt;span style="color:purple;"&gt;Open&lt;/span&gt;();&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.&lt;span style="color:purple;"&gt;WriteLine&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;Waiting for incoming data...&amp;quot;&lt;/span&gt;);&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.&lt;span style="color:purple;"&gt;ReadKey&lt;/span&gt;();&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;void&lt;/span&gt; &lt;span style="color:purple;"&gt;com_DataReceived&lt;/span&gt;(&lt;span style="color:blue;"&gt;object&lt;/span&gt; &lt;span style="color:purple;"&gt;sender&lt;/span&gt;, &lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#2b91af;"&gt;SerialDataReceivedEventArgs&lt;/span&gt; &lt;span style="color:purple;"&gt;e&lt;/span&gt;)&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// Use either the binary OR the string technique (but not both)&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// Buffer and process binary data&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;while&lt;/span&gt; (&lt;span style="color:purple;"&gt;com&lt;/span&gt;.&lt;span style="color:purple;"&gt;BytesToRead&lt;/span&gt; &amp;gt; 0) &lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;bBuffer&lt;/span&gt;.&lt;span style="color:purple;"&gt;Add&lt;/span&gt;((&lt;span style="color:blue;"&gt;byte&lt;/span&gt;)&lt;span style="color:purple;"&gt;com&lt;/span&gt;.&lt;span style="color:purple;"&gt;ReadByte&lt;/span&gt;());&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;ProcessBuffer&lt;/span&gt;(&lt;span style="color:purple;"&gt;bBuffer&lt;/span&gt;);&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// Buffer string data&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;sBuffer&lt;/span&gt; += &lt;span style="color:purple;"&gt;com&lt;/span&gt;.&lt;span style="color:purple;"&gt;ReadExisting&lt;/span&gt;();&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:purple;"&gt;ProcessBuffer&lt;/span&gt;(&lt;span style="color:purple;"&gt;sBuffer&lt;/span&gt;);&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; &lt;span style="color:purple;"&gt;ProcessBuffer&lt;/span&gt;(&lt;span style="color:blue;"&gt;string&lt;/span&gt; &lt;span style="color:purple;"&gt;sBuffer&lt;/span&gt;)&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// Look in the string for useful information&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// then remove the useful data from the buffer&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;private&lt;/span&gt; &lt;span style="color:blue;"&gt;void&lt;/span&gt; &lt;span style="color:purple;"&gt;ProcessBuffer&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;byte&lt;/span&gt;&amp;gt; &lt;span style="color:purple;"&gt;bBuffer&lt;/span&gt;)&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// Look in the byte array for useful information&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:green;"&gt;// then remove the useful data from the buffer&lt;/span&gt;&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;&amp;#160; }&lt;/p&gt;

      &lt;p style="margin:0px;"&gt;}&lt;/p&gt;
    &lt;/div&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: How do you detect when a device is connected or disconnected? 
      &lt;br /&gt;&lt;/strong&gt;Simply put, the device usually starts or stops sending data.&amp;#160; There are no built in events when a device connects or disconnects.&amp;#160; But there are a few tricks you can do, if you’re creating the serial device yourself, then you have more options.&amp;#160; I’ve had my devices (and PC apps) send a constant “are you there” set of bytes, like 00 00 11 11 00 00 hex (I’d use a ‘are you there’ custom ‘packet’ as in Q13 above) till a device on the other end responds.&amp;#160; You could also use hardware, that’s what some of the other signals lines are for (CDC, DSR, RTS, CTS, RI), you can tie one of these high and then catch an event when the line goes high so you know there’s a device there, when it goes low the device is gone. 

    &lt;br /&gt;&amp;#160;&lt;a name="files"&gt;&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: How do I transfer files? 
      &lt;br /&gt;&lt;/strong&gt;If you’re interested in sending entire files between computers or to a device, you have two primary choices.&amp;#160; First choice is to write your own protocol for breaking a file into manageable packets, detecting errors, sending/receiving, etc.&amp;#160; Second choice is to use a protocol already created, like &lt;a href="http://en.wikipedia.org/wiki/XMODEM"&gt;XModem&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/YMODEM"&gt;YModem&lt;/a&gt;, &lt;a href="http://en.wikipedia.org/wiki/ZMODEM"&gt;ZModem&lt;/a&gt;, etc.&amp;#160; These protocols were created long ago specifically to send files over a serial connection with features like error correction, being able to resume transfers, compression, etc.&amp;#160; I’m only aware of commercial implementations for .NET right now, like Sax Software’s &lt;a href="http://www.sax.net/commstudio/protocols"&gt;CommStudio&lt;/a&gt; or Scientific Component’s &lt;a href="http://scientificcomponent.com/portcontroller_net_v20_press.htm"&gt;PortController.NET&lt;/a&gt;.&amp;#160; If anyone find an open source implementation, please let me know! 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;a name="cable"&gt;&lt;/a&gt;&lt;strong&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/coad.metablogapi/0083.USB_5F00_Serial_5F00_Prolific_5F00_single_5F00_small_5B00_1_5D005F00_2.jpg"&gt;&lt;strong&gt;&lt;img style="border-right-width:0px;margin:0px 0px 0px 10px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="USB_Serial_Prolific_single_small[1]" border="0" alt="USB_Serial_Prolific_single_small[1]" align="right" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/coad.metablogapi/3644.USB_5F00_Serial_5F00_Prolific_5F00_single_5F00_small_5B00_1_5D005F00_thumb.jpg" width="200" height="166" /&gt;&lt;/strong&gt;&lt;/a&gt;Q: Where can I get USB-to-Serial cables?&lt;/strong&gt; 

    &lt;br /&gt;USB-to-Serial adapter cables allow you to get a standard RS-232 DB9 cable by plugging in the adapter to your USB port.&amp;#160; You can use several of these to get multiple DB9 ports.&amp;#160; Many laptops, even desktops, don’t have serial ports these days which makes these particularly handy. 

    &lt;br /&gt;&amp;#160; &lt;br /&gt;Every so often I source a good cable for a decent price, typically around $10.&amp;#160; Here is the deal I’m currently using.&amp;#160; &lt;a title="http://www.iofast.com/product_info.php/products_id/4681" href="http://www.iofast.com/product_info.php/products_id/4681"&gt;http://www.iofast.com/product_info.php/products_id/4681&lt;/a&gt; 

    &lt;br /&gt;&amp;#160; &lt;br /&gt;Be forewarned, not all cables are created equally!&amp;#160; There are two issues to contend with… 

    &lt;ol&gt;
      &lt;li&gt;There are a number of companies that create USB chipsets that emulates an RS-232 port.&amp;#160; Some are much more compatible with PCs and Macs than others.&amp;#160; For example, the Prolific and FTDI chipset are used in the most compatible adapters (unlike Ark Micro, or others).&amp;#160; Those companies produce WHQL (Windows Hardware Quality Labs) certified drivers and the drivers are built into most Windows and Mac systems already.&amp;#160; So when shopping for a cable, be sure to check the chipset manufacture.&amp;#160; Here are some handy links to drivers in case you need them. 
        &lt;ol&gt;
          &lt;li&gt;&lt;a href="http://www.prolific.com.tw/eng/downloads.asp?ID=31"&gt;Prolific Chipset Drivers&lt;/a&gt; &lt;/li&gt;

          &lt;li&gt;&lt;a href="http://www.ftdichip.com/FTDrivers.htm"&gt;FTDI Chipset Drivers&lt;/a&gt; &lt;/li&gt;
        &lt;/ol&gt;
      &lt;/li&gt;

      &lt;li&gt;Standard RS-232 signals range from 3 to 15 volts (plus or minus), 0 is not a valid signal.&amp;#160; The USB-to-Serial interface chips used in these cables produce 0 to 5 volts, standard TTL level logic.&amp;#160; While this works for some PCs, and certainly most microcontrollers, it is not 100% compatible.&amp;#160; The ‘correct’ USB-to-Serial cables incorporate an additional line level driver, like the MAX232, that take the 0 to 5 volts and convert it to an appropriate +/- 12 volts for RS-232.&amp;#160; The problem is that many low-quality cables exist out there without this line level driver chip. 
        &lt;br /&gt;&amp;#160; &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;a name="bridge"&gt;&lt;/a&gt;&lt;strong&gt;Q: How can I best interface with my microcontroller?&amp;#160; USB-to-Serial Bridge Chipsets 
      &lt;br /&gt;&lt;/strong&gt;&lt;a href="http://www.ftdichip.com/Products/FT232R.htm"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;margin-left:0px;border-left-width:0px;margin-right:0px;" title="FTDI FT232R 01" border="0" alt="FTDI FT232R 01" align="right" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/coad.metablogapi/0647.FTDI-FT232R-01_5F00_3.jpg" width="201" height="154" /&gt;&lt;/a&gt; If you are building your own devices, usually with some type of microcontroller, and want to interface with the PC, you can certainly use RS-232 either plugged straight into your PC or via a USB-to-Serial adapter cable, but another option is to use an USB-to-Serial bridge chipset directly in your project (what is inside of the USB-to-Serial adapter cables).&amp;#160; This allows your device to use RS-232 internally, but connect to a computer via USB and you as a project designer never need worry about the USB interface or drivers (your device and PC software just see serial RS-232).&amp;#160; You could use a native USB microcontroller (without an RS-232 bridge), such as the &lt;a href="http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en023497"&gt;PIC18F2450&lt;/a&gt;, but that requires writing your own USB drivers and a much deeper understanding of the USB infrastructure (both in hardware and software).&amp;#160; This article is focused on serial RS-232, so I’m covering the USB-to-Serial bridges here. 

    &lt;br /&gt;&amp;#160; &lt;br /&gt;These modern ICs don’t require external crystals, can power your device from USB Power, provide clock sources for your micro if you like, and come with Windows Certified (WHQL) drivers that are actually included in Windows Vista and beyond (also built in Mac drivers).&amp;#160; Here are a few… 

    &lt;ol&gt;
      &lt;li&gt;&lt;strong&gt;FTDI FT232RL&lt;/strong&gt; 

        &lt;br /&gt;The FTDI chips are most popular in electronics projects and used by companies like Parallax and the &lt;a href="http://store.gravitech.us/ardu.html"&gt;Arduino Duemilanove&lt;/a&gt;.&amp;#160; They also have the best support in terms of evaluation modules, well written datasheet, and product availability. 

        &lt;br /&gt;Links: &lt;a href="http://www.ftdichip.com/Products/FT232R.htm"&gt;product info&lt;/a&gt;, &lt;a href="http://www.ftdichip.com/Documents/DataSheets/DS_FT232R.pdf"&gt;datasheet&lt;/a&gt;, &lt;a href="http://www.ftdichip.com/Products/EvaluationKits/FT232RModules.htm"&gt;evaluation modules&lt;/a&gt;, &lt;a href="http://www.mouser.com/Search/ProductDetail.aspx?qs=sGAEpiMZZMvlOED0T0kTWusgAIFi%252bqIU"&gt;buy from Mouser&lt;/a&gt;, &lt;a href="http://www.ftdichip.com/FTDrivers.htm"&gt;drivers&lt;/a&gt; 

        &lt;br /&gt;&amp;#160; &lt;/li&gt;

      &lt;li&gt;&lt;strong&gt;Prolific PL-2303HX 
          &lt;br /&gt;&lt;/strong&gt;These are the chips used in the most popular USB-to-Serial cables.&amp;#160; They are slightly less costly than the FTDI chips in bulk, but are not quite as well supported in the US market.&amp;#160; &lt;br /&gt;Links: &lt;a href="http://www.prolificusa.com/products-usb-to-serial.php"&gt;product info&lt;/a&gt;, &lt;a href="http://www.prolificusa.com/pdf/PL-2303HX.pdf"&gt;datasheet&lt;/a&gt;, &lt;a href="http://www.saelig.com/product/PUSB004.htm"&gt;buy from Saelig&lt;/a&gt;, &lt;a href="http://www.prolific.com.tw/eng/downloads.asp?ID=31"&gt;drivers&lt;/a&gt; 

        &lt;br /&gt;&amp;#160; &lt;/li&gt;

      &lt;li&gt;&lt;strong&gt;TI TUSB3410 
          &lt;br /&gt;&lt;/strong&gt;Another option from Texas Instruments.&amp;#160; I haven’t used this chip.&amp;#160; &lt;a href="http://focus.ti.com/docs/prod/folders/print/tusb3410.html"&gt;Product Info&lt;/a&gt; &lt;/li&gt;
    &lt;/ol&gt;
p.s. For trying it out and prototyping, I personally recommend this particular FTDI evaluation board, the &lt;a href="http://www.ftdichip.com/Products/EvaluationKits/UM232R.htm"&gt;UM232R&lt;/a&gt; since it plugs into typical solderless &lt;a href="http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&amp;amp;productId=20723&amp;amp;catalogId=10001&amp;amp;freeText=20722&amp;amp;app.products.maxperpage=15&amp;amp;storeId=10001&amp;amp;search_type=jamecoall&amp;amp;ddkey=http:StoreCatalogDrillDownView"&gt;protoytpe breadboards&lt;/a&gt; and has most of the pins easily accessible.&amp;#160; Last priced it was &lt;a href="http://www.mouser.com/ProductDetail/FTDI/UM232R/?qs=Xb8IjHhkxj55I/i97zZKYA%3d%3d"&gt;$20 from Mouser&lt;/a&gt;. 

    &lt;br /&gt;

    &lt;br /&gt;&lt;a href="http://www.ftdichip.com/Products/EvaluationKits/UM232R.htm"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="FTDI FT232R 02 UM232R" border="0" alt="FTDI FT232R 02 UM232R" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/coad.metablogapi/6013.FTDI-FT232R-02-UM232R_5F00_3.jpg" width="275" height="190" /&gt;&lt;/a&gt; 

    &lt;br /&gt;&amp;#160; &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Q: How can I get more support?&amp;#160; What are my support options?&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
  &lt;li&gt;Read this FAQ section!&amp;#160; :)&amp;#160; &lt;/li&gt;

  &lt;li&gt;You can try leaving a comment below.&amp;#160; Perhaps someone knows the answer &lt;/li&gt;

  &lt;li&gt;Read the official MS documentation, &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx"&gt;MSDN on SerialPort&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;See if the article &lt;a href="http://en.wikipedia.org/wiki/RS-232"&gt;Wikipedia on RS-232&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Try doing a search and look for other content.&amp;#160; &amp;quot; &lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=SerialPort+C%23"&gt;SerialPort C#&lt;/a&gt;&amp;quot;, &amp;quot;&lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=Serial+com+C%23"&gt;Serial Com C#&lt;/a&gt;&amp;quot;, &amp;quot;&lt;a href="http://www.google.com/search?hl=en&amp;amp;lr=&amp;amp;q=serial+port+.net"&gt;serial port .net&lt;/a&gt;&amp;quot; &lt;/li&gt;

  &lt;li&gt;Post a question in the &lt;a href="http://forums.msdn.microsoft.com/en-US/netfxbcl/threads/"&gt;.NET Base Class Library&lt;/a&gt; in MSDN Forums &lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=39466" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Reverse Enum Lookup</title><link>http://msmvps.com/blogs/coad/archive/2004/06/22/8697.aspx</link><pubDate>Tue, 22 Jun 2004 06:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:8697</guid><dc:creator>coad</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=8697</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/06/22/8697.aspx#comments</comments><description>&lt;p&gt;
Sometimes you may have the string name of an enumeration identifier, and want its enum type.  For example, you write a enum identifier as a string to a file and want to read it back and obtain the original enumeration type.  This takes place when you serialize a class to an XML file and deserialize it back using &lt;samp&gt;XmlSerializer&lt;/samp&gt;.
&lt;p&gt;&lt;code&gt;&lt;table style="border: solid 1px black; background: white;" cellpadding="6"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="display: inline;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;enum&lt;/span&gt;&lt;span style="color: #000000; "&gt; Direction {North, South, East, West};

&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; Direction ParseDirection(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;string&lt;/span&gt;&lt;span style="color: #000000; "&gt; name)
{ &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;return&lt;/span&gt;&lt;span style="color: #000000; "&gt; (Direction) Enum.Parse(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;typeof&lt;/span&gt;&lt;span style="color: #000000; "&gt;(Direction), name, &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;true&lt;/span&gt;&lt;span style="color: #000000; "&gt;); }&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/code&gt;&lt;/p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=8697" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Obtaining Indented XML as a String</title><link>http://msmvps.com/blogs/coad/archive/2004/06/22/8692.aspx</link><pubDate>Tue, 22 Jun 2004 05:55:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:8692</guid><dc:creator>coad</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=8692</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/06/22/8692.aspx#comments</comments><description>&lt;p&gt;Using &lt;samp&gt;XmlDocument.Save(string file)&lt;/samp&gt; produces a file with nicely indented elements.  &lt;samp&gt;XmlDocument.OuterXml&lt;/samp&gt; returns a string without any formatting.  If you want a nicely formatted string (to display to the user, write to console, etc), without directly writing to a file, you must use the &lt;samp&gt;XmlTextWriter&lt;/samp&gt;.&lt;/p&gt;&lt;p&gt;The &lt;samp&gt;using&lt;/samp&gt; statements in the method makes sure the resorces are disposed of sooner than later. Here is the code to return a string of formatted XML from an &lt;samp&gt;XmlDocument&lt;/samp&gt;.  &lt;a href="http://coad.net/Blog/Resources/Obtaining Indented XML as a String.zip"&gt;Download Example Code&lt;/a&gt; (requires Visual Studio 2005)&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;table style="border: solid 1px black; background: white;" cellpadding="6"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="display: inline;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; System.IO;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; System.Xml;

&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;static&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;string&lt;/span&gt;&lt;span style="color: #000000; "&gt; FormatXML(XmlDocument doc)
{ 
  &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Create a stream buffer that can be read as a string&lt;/span&gt;&lt;span style="color: #008000; "&gt;
&lt;/span&gt;&lt;span style="color: #000000; "&gt;  &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; (StringWriter sw &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;new&lt;/span&gt;&lt;span style="color: #000000; "&gt; StringWriter())

    &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Create a specialized writer for XML code&lt;/span&gt;&lt;span style="color: #008000; "&gt;
&lt;/span&gt;&lt;span style="color: #000000; "&gt;    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; (XmlTextWriter xtw &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;new&lt;/span&gt;&lt;span style="color: #000000; "&gt; XmlTextWriter(sw))
    {
      &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Set the writer to use indented (hierarchical) elements&lt;/span&gt;&lt;span style="color: #008000; "&gt;
&lt;/span&gt;&lt;span style="color: #000000; "&gt;      xtw.Formatting &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; System.Xml.Formatting.Indented;

      &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Write the XML document to the stream&lt;/span&gt;&lt;span style="color: #008000; "&gt;
&lt;/span&gt;&lt;span style="color: #000000; "&gt;      doc.WriteTo(xtw);

      &lt;/span&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Return the stream as a string&lt;/span&gt;&lt;span style="color: #008000; "&gt;
&lt;/span&gt;&lt;span style="color: #000000; "&gt;      &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;return&lt;/span&gt;&lt;span style="color: #000000; "&gt; sw.ToString();
    }
}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=8692" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/coad/archive/tags/XML/default.aspx">XML</category></item><item><title>Creating Quick Tests in C#</title><link>http://msmvps.com/blogs/coad/archive/2004/06/18/creating-quick-tests-in-c.aspx</link><pubDate>Fri, 18 Jun 2004 09:51:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:8408</guid><dc:creator>coad</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=8408</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/06/18/creating-quick-tests-in-c.aspx#comments</comments><description>&lt;p style="padding-right:6px;border-top:black 1px solid;padding-left:6px;padding-bottom:6px;padding-top:6px;border-bottom:black 1px solid;"&gt;&lt;strong&gt;Update on 5/2/07:&lt;/strong&gt;&amp;nbsp; This post has nothing to do with Unit Testing (it was written before I was aware of unit testing) but has to do with write little bits of code to try new stuff out.&amp;nbsp; It is also only for VS03.&amp;nbsp; For the current version (VS05), see this post: &lt;a href="http://blogs.msdn.com/noahc/archive/2006/07/14/666015.aspx"&gt;CoadNet VS Project Templates, Quick Code + Console App for C# in VS05&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://coad.net/blog/resources/CoadToolsQuickTest.msi"&gt;CoadTools Quick Test C# Project Template&lt;/a&gt; (setup .msi) for Visual Studio .NET 2003&lt;/p&gt; &lt;p&gt;&lt;b class="head"&gt;Introduction&lt;/b&gt;&lt;br /&gt;Very often I need to test a tidbit of code, do some research on a class, etc. In fact, I was creating several times as many quick code test projects as any other project need. I used to start a Console application, change it to a Windows Application, but still needed to add namespaces, etc. So I created a custom &amp;quot;New Project&amp;quot; template for Visual Studio .NET 2003. To use, just install, load VS.NET, choose &amp;quot;New Project&amp;quot;/&amp;quot;Visaul C# Projects&amp;quot;/&amp;quot;Quick Test&amp;quot;, and you&amp;#39;re good to go.&lt;/p&gt; &lt;p&gt;&lt;b class="head"&gt;The Goal&lt;/b&gt;&lt;br /&gt;The main goal was to minimize the time to test code. Just start VS.NET, choose the &amp;quot;Quick Test&amp;quot; project, and type code. I wanted to send output to the Trace (VS.NET Ouput Window) and have the most common namespaces already included. You can easily modify the template after it is installed to suite your own needs.&lt;/p&gt; &lt;p&gt;&lt;b class="head"&gt;Compare and Contrast&lt;/b&gt;&lt;br /&gt;A popular tool is &lt;a href="http://www.sliver.com/dotnet/SnippetCompiler/"&gt;Snippet Compiler&lt;/a&gt;, which is a stand-alone mini-IDE for testing code. This is a great tool, especially if you do not own VS.NET 2003. When testing, I find that I want the full VS.NET environment, which I&amp;#39;m most familiar with and productive in, and to perform quick MSDN help lookup and take advantage of the full debugging interface. Just a simple custom &amp;quot;New Project&amp;quot; template like this provides all these objectives in a simple manor.&lt;/p&gt; &lt;p&gt;&lt;b class="head"&gt;Saving Code&lt;/b&gt;&lt;br /&gt;When creating a new quick test project, I usually just store the project in &amp;quot;C:\Temp\Test&amp;quot;. This way I keep my tests for future reference and they are out of the way.&lt;/p&gt; &lt;p&gt;&lt;b class="head"&gt;Leave Feedback&lt;/b&gt;&lt;br /&gt;This is completely free. All I ask is that you leave a feedback comment. :)&lt;/p&gt; &lt;table class="Photo" style="border-right:black 1px solid;padding-right:4px;border-top:black 1px solid;padding-left:4px;padding-bottom:4px;font:10pt verdana;border-left:black 1px solid;padding-top:4px;border-bottom:black 1px solid;"&gt;  &lt;tr&gt; &lt;td align="middle"&gt;&lt;img src="http://coad.net/blog/Images/VSNewProjectQuickTestCircled.png" alt="" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="middle"&gt;VS.NET 2003 &amp;quot;New Project&amp;quot; Dialog w/ Quick Test Project&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt; &lt;table class="Photo" style="border-right:black 1px solid;padding-right:4px;border-top:black 1px solid;padding-left:4px;padding-bottom:4px;font:10pt verdana;border-left:black 1px solid;padding-top:4px;border-bottom:black 1px solid;"&gt;  &lt;tr&gt; &lt;td align="middle"&gt;&lt;img src="http://coad.net/blog/Images/VSQuickTestCode.png" alt="" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="middle"&gt;Code Template in VS.NET, Fully Customizable&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt; &lt;p&gt;Screen captures have been brought to you by &lt;a href="http://www.techsmith.com/products/snagit"&gt;SnagIt&lt;/a&gt;. This is my first use of &lt;a href="http://www.techsmith.com/products/snagit"&gt;SnagIt&lt;/a&gt;, a powerful screen capture utility, and it is fantastic! Extremely easy to use (a big plus for me) and it includes additional editing tools.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=8408" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/coad/archive/tags/Tools/default.aspx">Tools</category></item><item><title>Property Event Pattern</title><link>http://msmvps.com/blogs/coad/archive/2004/06/17/8399.aspx</link><pubDate>Fri, 18 Jun 2004 04:59:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:8399</guid><dc:creator>coad</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=8399</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/06/17/8399.aspx#comments</comments><description>&lt;p&gt;&lt;b class="head"&gt;Introduction&lt;/b&gt;&lt;br /&gt;Since the advent of .NET, one of my most frequent and useful patterns is using an event to notify change in state.  Applying this pattern has reduced overall code, improved reliability, and made maintenance and expansion easier.&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;Why? The Context&lt;/b&gt;&lt;br /&gt;Without events, spaghetti code occurs real quickly when one method changes state that other code is dependant on without notifying that the change is made.  This is one of the most frequent causes of coding errors (bugs) in mid-to-large applications that I have seen. Events go a long way in solve this issue.&lt;/p&gt;&lt;p&gt;This should be obvious with public properties that can be changed externally, but must be acted upon by the owner.  Such as the Text property on a label, when changed, the label must be redrawn.&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;Common Example&lt;/b&gt;&lt;br /&gt;This is used extensively on Windows Forms components.  Almost every property has an associated change event.  TextChanged for the Text property, EnableChanged for the Enabled property and so on.&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;Internally Critical&lt;/b&gt;&lt;br /&gt;This pattern becomes more subtle but critical with internal members.  In larger applications, for clarity, I wrap most all class variables in properties with change events.  If the class is designed to be inherited, this becomes all the more important as you can not rely on derived classes to notify your code when they change state.&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;The Solution&lt;/b&gt;&lt;ul style="margin-top: 0px;"&gt;&lt;li&gt;Subscribe to Events&lt;br /&gt;Code that depends on a class' state can subscribe to the appropriate change event to receive notification of when that state changes to take appropriate action.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Event Triggers&lt;br /&gt;The "Event Triggers" allow easy triggering of the event and allow derived classes the option of first notification (before the event occurs).&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Internal Access Through Properties&lt;br /&gt;Even internal members should access the variable through the property to ensure that notification occurs.  In other words, members should not access the class variable directly, only through the property.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;code&gt;&lt;table style="border: solid 1px black; background: white;" cellpadding="6"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="display: inline;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #0000FF; "&gt;#region&lt;/span&gt;&lt;span style="color: #000000; "&gt; Public Events&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;event&lt;/span&gt;&lt;span style="color: #000000; "&gt; EventHandler DevicePortChanged;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#endregion&lt;/span&gt;&lt;span style="color: #000000; "&gt;

&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#region&lt;/span&gt;&lt;span style="color: #000000; "&gt; Property Variables&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;int&lt;/span&gt;&lt;span style="color: #000000; "&gt; m_DevicePort;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#endregion&lt;/span&gt;&lt;span style="color: #000000; "&gt;

&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#region&lt;/span&gt;&lt;span style="color: #000000; "&gt; Public Properties&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;int&lt;/span&gt;&lt;span style="color: #000000; "&gt; DevicePort
{
  &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;get&lt;/span&gt;&lt;span style="color: #000000; "&gt; {&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;return&lt;/span&gt;&lt;span style="color: #000000; "&gt; m_DevicePort;}
  &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;set&lt;/span&gt;&lt;span style="color: #000000; "&gt;
  {
    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;int&lt;/span&gt;&lt;span style="color: #000000; "&gt; saved &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; m_DevicePort;
    m_DevicePort &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; value;
    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;if&lt;/span&gt;&lt;span style="color: #000000; "&gt; (saved &lt;/span&gt;&lt;span style="color: #000000; "&gt;!=&lt;/span&gt;&lt;span style="color: #000000; "&gt; value) OnDevicePortChanged(EventArgs.Empty);
  }
}
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#endregion&lt;/span&gt;&lt;span style="color: #000000; "&gt;

&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#region&lt;/span&gt;&lt;span style="color: #000000; "&gt; Event Triggers&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;protected&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;virtual&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;void&lt;/span&gt;&lt;span style="color: #000000; "&gt; OnDevicePortChanged(EventArgs e)
{ &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;if&lt;/span&gt;&lt;span style="color: #000000; "&gt; (DevicePortChanged &lt;/span&gt;&lt;span style="color: #000000; "&gt;!=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;null&lt;/span&gt;&lt;span style="color: #000000; "&gt;) DevicePortChanged(&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;this&lt;/span&gt;&lt;span style="color: #000000; "&gt;, e); }
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;#endregion&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;References&lt;/b&gt;&lt;ul style="margin-top: 0px;"&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconPropertyUsageGuidelines.asp"&gt;MSDN: Property Usage Guidelines&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/observerpattern.asp"&gt;MSDN: Exploring the Observer Design Pattern&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeproject.com/dotnet/eventstrategy.asp"&gt;.NET Event Handling using the Template Method Design Pattern&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=8399" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Associating a File Extension and Context Menus with an Application in the Registry</title><link>http://msmvps.com/blogs/coad/archive/2004/06/11/8011.aspx</link><pubDate>Fri, 11 Jun 2004 21:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:8011</guid><dc:creator>coad</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=8011</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/06/11/8011.aspx#comments</comments><description>&lt;p&gt;You can easily assign a file extension to open with your application in the registry.&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;Verbal Description&lt;/b&gt;&lt;br /&gt;The extension is added as a key under "HKEY_CLASSES_ROOT" with the (default) value set to the file's type (a string arbitrarily assigned by yourself).  Then you add a key with the file's type also to "HKEY_CLASSES_ROOT" with its (default) value set to the file's type description (that is shown in Exporer).  Under the same key, add they keys "shell/open/command" with the (default) value being the program to execute.  Use "%1" with the quotes to pass the file's name to your app.  You can also assign an icon by adding a "DefaultIcon" key under the file's type key. Then additional context menu items can be added by putting keys the [filetype]/shell/[MenuItem]/Command&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;Example Registry Entries&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;HKEY_CLASSES_ROOT\.npost = NovaBlog.Post&lt;/li&gt;&lt;li&gt;HKEY_CLASSES_ROOT\NovaBlog.Post = NovaBlog Article Posting&lt;/li&gt;&lt;li&gt;HKEY_CLASSES_ROOT\NovaBlog.Post\DefaultIcon = C:\Program Files\NovaBlog\NovaBlox.exe,0&lt;/li&gt;&lt;li&gt;HKEY_CLASSES_ROOT\NovaBlog.Post\shell\Open = &amp;amp;Open&lt;/li&gt;&lt;li&gt;HKEY_CLASSES_ROOT\NovaBlog.Post\shell\Open\Command = C:\Program Files\NovaBlog\NovaBlox.exe "%1"&lt;/li&gt;&lt;li&gt;HKEY_CLASSES_ROOT\NovaBlog.Post\shell\PostNow = &amp;amp;Post the Article Now&lt;/li&gt;&lt;li&gt;HKEY_CLASSES_ROOT\NovaBlog.Post\shell\PostNow\Command = C:\Program Files\NovaBlog\NovaBlox.exe /postnow "%1"&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;p&gt;&lt;b class="head"&gt;C# Code&lt;/b&gt;&lt;br /&gt;
Thankfully there is a Microsoft.Win32 namespace with classes for working with the registry.  This is all there is to it!&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;table style="border: solid 1px black; background: white;" cellpadding="6"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="display: inline;"&gt;&lt;div&gt;&lt;!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt;&lt;span style="color: #008000; "&gt;//&lt;/span&gt;&lt;span style="color: #008000; "&gt; Created by Noah Coad, 6/11/04&lt;/span&gt;&lt;span style="color: #008000; "&gt;
&lt;/span&gt;&lt;span style="color: #000000; "&gt;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; Microsoft.Win32;
&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; System.Windows.Forms;

&lt;/span&gt;&lt;span style="color: #0000FF; "&gt;public&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;static&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;void&lt;/span&gt;&lt;span style="color: #000000; "&gt; CreateRegEntries()
{
  RegistryKey rkey &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; Registry.ClassesRoot;
  rkey.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;.npost&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;).SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;, &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;NovaBlog.Post&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  rkey &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; rkey.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;NovaBlog.Post&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  rkey.SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;, &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;NovaBlog Article Post&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  rkey.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;DefaultIcon&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;).SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;, Application.ExecutablePath &lt;/span&gt;&lt;span style="color: #000000; "&gt;+&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;,0&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  rkey &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; rkey.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;shell&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  
  RegistryKey keycmd &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; rkey.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;Open&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  keycmd.SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;, &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;&amp;amp;amp;Open&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  keycmd.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;Command&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;).SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;,
    &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;\"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt;+&lt;/span&gt;&lt;span style="color: #000000; "&gt; Application.ExecutablePath &lt;/span&gt;&lt;span style="color: #000000; "&gt;+&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;\" \"%1\"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  
  keycmd &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; rkey.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;PostNow&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  keycmd.SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;, &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;&amp;amp;amp;Post Article Now&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
  keycmd.CreateSubKey(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;Command&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;).SetValue(&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;""&lt;/span&gt;&lt;span style="color: #000000; "&gt;,
    &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;\"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #000000; "&gt;+&lt;/span&gt;&lt;span style="color: #000000; "&gt; Application.ExecutablePath &lt;/span&gt;&lt;span style="color: #000000; "&gt;+&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;\" /postnow \"%1\"&lt;/span&gt;&lt;span style="color: #9932CC; "&gt;"&lt;/span&gt;&lt;span style="color: #000000; "&gt;);
}&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=8011" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Programming Practices Policy v3.0 Released</title><link>http://msmvps.com/blogs/coad/archive/2004/05/18/6762.aspx</link><pubDate>Wed, 19 May 2004 02:33:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:6762</guid><dc:creator>coad</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=6762</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/05/18/6762.aspx#comments</comments><description>&lt;p&gt;Now available is a new version of the synopsis of C# coding practices that are being used by the majority of MVPs, professional C# coders, and my associates.  These practices are being used by the development community and this is an abbreviation that I have assembled for colleagues.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.coad.net/noah/LinkHit.asp?LinkID=194"&gt;Programming Practice Policy.pdf v3.0&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=6762" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>C# Team FAQ Blog</title><link>http://msmvps.com/blogs/coad/archive/2004/04/18/5166.aspx</link><pubDate>Mon, 19 Apr 2004 01:37:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:5166</guid><dc:creator>coad</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=5166</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/04/18/5166.aspx#comments</comments><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;The C# team at Microsoft has started a Frequently Asked Questions (FAQ) blog where they answer some interesting topics.  Definitely a good read for C# developers.  I've found it interesting to see the reasoning behind some of the descriptions made in the C# language.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/csharpfaq/"&gt;&lt;font face="Verdana" size="2"&gt;http://blogs.msdn.com/csharpfaq/&lt;/font&gt;&lt;/a&gt;&lt;font face="Verdana" size="2"&gt; &lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=5166" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Two New CoadTools, AdvancedFileProperties &amp; OrderedStringDictionary</title><link>http://msmvps.com/blogs/coad/archive/2004/04/17/5143.aspx</link><pubDate>Sun, 18 Apr 2004 03:37:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:5143</guid><dc:creator>coad</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=5143</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/04/17/5143.aspx#comments</comments><description>&lt;p&gt;&lt;font face="Verdana" size="2"&gt;My protege, Radoslav (Radi) Ivanov (age 16), has published his first code utilitity!  It is an “Advanced File Properties“ reader that retrieves the NTFS extended properties of a file.  It provides a DataTable wrapped method for an included COM DLL.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;I created an “Ordered String Dictionary“ that implements an ArrayList to create a string key/value pair dictionary that keeps the ordering of its elements.  The System.Collections.Specialized StringDictionary uses a HashTable that looses the order of its pairs and NameValueCollection does not support insertion at a specific location.  This class is in the “SpecializedCollections“ CoadTool.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Verdana" size="2"&gt;Free CoadTools&lt;br /&gt;&lt;/font&gt;&lt;a href="http://www.coad.net/products/"&gt;&lt;font face="Verdana" size="2"&gt;http://www.coad.net/products/&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=5143" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/coad/archive/tags/Tools/default.aspx">Tools</category></item><item><title>Assimilate XML RSS Feed from URL in C#</title><link>http://msmvps.com/blogs/coad/archive/2004/04/14/5013.aspx</link><pubDate>Thu, 15 Apr 2004 02:46:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:5013</guid><dc:creator>coad</dc:creator><slash:comments>11</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=5013</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/04/14/5013.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;This piece of code pulls an RSS feed and displays the title of the articles.  It is here to demonstrate just how easy it is to pull XML off the web and utilize the data.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;I use Trace.WriteLine instead of Console.WriteLine so the report is fed to the Visual Studio output window and can be run as either a Console or Windows app, but at least a new Console window is not opened.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt; &lt;/p&gt;
&lt;table class="MsoNormalTable" style="BACKGROUND: white; BORDER-COLLAPSE: collapse; mso-padding-alt: 0in 0in 0in 0in" cellspacing="0" cellpadding="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent" valign="top"&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Xml&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Net&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Text&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Diagnostics&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// -------------------------------&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// RSS XML Feed URL&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;string&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;url&lt;/span&gt; = "http://msmvps.com/coad/rss.aspx";&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// Create an interface to the web&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: purple; FONT-FAMILY: 'Courier New'"&gt;WebClient&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;c&lt;/span&gt; = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: purple"&gt;WebClient&lt;/span&gt;();&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// Download the XML into a string&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;string&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;xml&lt;/span&gt; = &lt;span style="COLOR: purple"&gt;ASCIIEncoding&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Default&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;GetString&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;c&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;DownloadData&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;url&lt;/span&gt;));&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// Document to contain the feed&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: purple; FONT-FAMILY: 'Courier New'"&gt;XmlDocument&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;doc&lt;/span&gt; = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: purple"&gt;XmlDocument&lt;/span&gt;();&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// Parse the xml&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: purple; FONT-FAMILY: 'Courier New'"&gt;doc&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;.&lt;span style="COLOR: purple"&gt;LoadXml&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;xml&lt;/span&gt;);&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// Display each article title&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;foreach&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; (&lt;span style="COLOR: purple"&gt;XmlNode&lt;/span&gt; &lt;span style="COLOR: purple"&gt;node&lt;/span&gt; &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; &lt;span style="COLOR: purple"&gt;doc&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;SelectNodes&lt;/span&gt;("/rss/channel/item/title"))&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: purple"&gt;Trace&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;node&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;InnerText&lt;/span&gt;);&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;/span&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=5013" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/coad/archive/tags/XML/default.aspx">XML</category></item><item><title>Edit File with Shell Registry Settings</title><link>http://msmvps.com/blogs/coad/archive/2004/04/14/5008.aspx</link><pubDate>Wed, 14 Apr 2004 14:37:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:5008</guid><dc:creator>coad</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=5008</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/04/14/5008.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;This snippet of code looks up the registered editor for the file type passed.  If it doesn’t find one, it uses notepad (it was of course designed originally for text files).  &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;Notice: See the cascading if statement both assigning and checking for null.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt; &lt;/p&gt;
&lt;table class="MsoNormalTable" style="BACKGROUND: white; BORDER-COLLAPSE: collapse; mso-padding-alt: 0in 0in 0in 0in" cellspacing="0" cellpadding="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent" valign="top"&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;private&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; &lt;span style="COLOR: purple"&gt;EditFile&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; &lt;span style="COLOR: purple"&gt;FilePath&lt;/span&gt;)&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: green"&gt;// Attempt to locate the system's editor for this file type&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: purple"&gt;RegistryKey&lt;/span&gt; &lt;span style="COLOR: purple"&gt;rkey&lt;/span&gt; = &lt;span style="COLOR: purple"&gt;Registry&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;ClassesRoot&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;OpenSubKey&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;Path&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;GetExtension&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;FilePath&lt;/span&gt;));&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; ((&lt;span style="COLOR: purple"&gt;rkey&lt;/span&gt; != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      ((&lt;span style="COLOR: purple"&gt;rkey&lt;/span&gt; = &lt;span style="COLOR: purple"&gt;Registry&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;ClassesRoot&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;OpenSubKey&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;rkey&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;GetValue&lt;/span&gt;("") + @"\shell\edit\command")) != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; &lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      (&lt;span style="COLOR: purple"&gt;rkey&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;GetValue&lt;/span&gt;("").&lt;span style="COLOR: purple"&gt;ToString&lt;/span&gt;() != &lt;span style="COLOR: purple"&gt;String&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Empty&lt;/span&gt;))&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   {&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: purple"&gt;ProcessStartInfo&lt;/span&gt; &lt;span style="COLOR: purple"&gt;psi&lt;/span&gt; = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: purple"&gt;ProcessStartInfo&lt;/span&gt;();&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: green"&gt;// Don't use the system's shell&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: purple"&gt;psi&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;UseShellExecute&lt;/span&gt; = &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: green"&gt;// Replace the file parameter with this file&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: purple"&gt;psi&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;FileName&lt;/span&gt; = &lt;span style="COLOR: purple"&gt;rkey&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;GetValue&lt;/span&gt;("").&lt;span style="COLOR: purple"&gt;ToString&lt;/span&gt;().&lt;span style="COLOR: purple"&gt;Replace&lt;/span&gt;("%1", &lt;span style="COLOR: purple"&gt;FilePath&lt;/span&gt;);&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: green"&gt;// Begin execution&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: purple"&gt;Process&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Start&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;psi&lt;/span&gt;);&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   }&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: green"&gt;// The system editor could not be located, using Notepad&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; &lt;span style="COLOR: purple"&gt;Process&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Start&lt;/span&gt;("notepad", &lt;span style="COLOR: purple"&gt;FilePath&lt;/span&gt;);&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;/span&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=5008" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Simple C# XSL Transformation</title><link>http://msmvps.com/blogs/coad/archive/2004/04/13/4994.aspx</link><pubDate>Wed, 14 Apr 2004 04:06:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:4994</guid><dc:creator>coad</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/coad/rsscomments.aspx?PostID=4994</wfw:commentRss><comments>http://msmvps.com/blogs/coad/archive/2004/04/13/4994.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;“XSLTransform.cs”&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;                                     &lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;And here is a simple C# translator that takes an XML file sends it through an XSL file transform and saves the output.  It is intended to be used as a console application.  This can be easily used to apply the CSV transform XSL to Vocabulary.xml.&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt; &lt;/p&gt;
&lt;table class="MsoNormalTable" style="BACKGROUND: white; BORDER-COLLAPSE: collapse; mso-padding-alt: 0in 0in 0in 0in" cellspacing="0" cellpadding="0" border="0"&gt;
&lt;tbody&gt;
&lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes"&gt;
&lt;td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid; BACKGROUND-COLOR: transparent" valign="top"&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;font face="Verdana" size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;// Created by Noah Coad, coad.net/noah, noah@coad.net, 4/10/04&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: green; FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;IO&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Xml&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Xml&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Xsl&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;using&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;System&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Diagnostics&lt;/span&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;font size="2"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;namespace&lt;/span&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt; &lt;span style="COLOR: purple"&gt;XSLTransform&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: purple"&gt;Transform&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   {&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: purple"&gt;Transform&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[] &lt;span style="COLOR: purple"&gt;args&lt;/span&gt;)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      {&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: green"&gt;// Make sure at least three command&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: green"&gt;// line arguments are specified&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (&lt;span style="COLOR: purple"&gt;args&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Length&lt;/span&gt; &amp;lt; 3) {&lt;span style="COLOR: purple"&gt;ShowSyntax&lt;/span&gt;(); &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: purple"&gt;XslTransform&lt;/span&gt; &lt;span style="COLOR: purple"&gt;xsl&lt;/span&gt; = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: purple"&gt;XslTransform&lt;/span&gt;();&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: green"&gt;// Attempt to load the XSL&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; {&lt;span style="COLOR: purple"&gt;xsl&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Load&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;args&lt;/span&gt;[1]);}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: purple"&gt;XmlException&lt;/span&gt; &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;) {&lt;span style="COLOR: purple"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;WriteLine&lt;/span&gt;("Could not load XSL transform: " + &lt;span style="COLOR: purple"&gt;args&lt;/span&gt;[1] + "\n\n" + &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Message&lt;/span&gt;); &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: purple"&gt;XsltException&lt;/span&gt; &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;) {&lt;span style="COLOR: purple"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;WriteLine&lt;/span&gt;("Could not process the XSL: " + &lt;span style="COLOR: purple"&gt;args&lt;/span&gt;[1] + "\n\n" + &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Message&lt;/span&gt; + "\nOn line " + &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;LineNumber&lt;/span&gt; + " @ " + &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;LinePosition&lt;/span&gt;); &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: green"&gt;// Attempt to transform the XML&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; {&lt;span style="COLOR: purple"&gt;xsl&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Transform&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;args&lt;/span&gt;[0], &lt;span style="COLOR: purple"&gt;args&lt;/span&gt;[2]);}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;         &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: purple"&gt;XmlException&lt;/span&gt; &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;) {&lt;span style="COLOR: purple"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;WriteLine&lt;/span&gt;("Could not perform transform on: " + "\n\n" + &lt;span style="COLOR: purple"&gt;e&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Message&lt;/span&gt;); &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      }&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      [&lt;span style="COLOR: purple"&gt;STAThread&lt;/span&gt;]&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; &lt;span style="COLOR: purple"&gt;Main&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[] &lt;span style="COLOR: purple"&gt;args&lt;/span&gt;)&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      { &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: purple"&gt;Transform&lt;/span&gt;(&lt;span style="COLOR: purple"&gt;args&lt;/span&gt;); }&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; &lt;span style="COLOR: purple"&gt;ShowSyntax&lt;/span&gt;()&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;      { &lt;span style="COLOR: purple"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: purple"&gt;Write&lt;/span&gt;("XSLTransform Xml-URL Xsl-URL Output.txt"); }&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;   }&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-FAMILY: 'Courier New'"&gt;&lt;font size="2"&gt;}&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;/span&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=4994" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/coad/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/coad/archive/tags/XML/default.aspx">XML</category></item></channel></rss>