C# Team FAQ Blog

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. http://blogs.msdn.com/csharpfaq/

Two New CoadTools, AdvancedFileProperties & OrderedStringDictionary

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. 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. Free CoadToolshttp://www.coad.net/products/

RSS “FEED Validator” Bombs

ARG!  After spending so much time making sure my RSS feeds are valid XML, I have run into a limitation of the seemingly most preeminent RSS feed validator online.   It bombs out right at about 200K.  If the feed is longer, it is invalid.  There is no warning that this limitation is reached.   FEED Validator by Mark Pilgrim and Sam Ruby http://feedvalidator.org/   You can attempt to validate my feed, but if it is over 200K (which it currently is), it will fail.  Validate RSS Feed   However, you can attempt to parse the feed as XML, as … Continue reading RSS “FEED Validator” Bombs

Well Formatted Blog, Can’t Directly Copy from MS Word

Wow!  Well I just had to go back through all my posts and repost them all.  It seams that one can not directly copy and paste from a Microsoft Word document to achieve a nicely formatted blog.   Invalid XML code is the end result causing the RSS feed to break.  This not only affects my blog’s feed, but also the main MSMVPS.org feed.   Thanks to Miha Markic for pointing this out quickly before I had posted much more than the first 10 initial posts!! http://www.rthand.com/   I’ve spent much time checking and rechecking the RSS feed and it … Continue reading Well Formatted Blog, Can’t Directly Copy from MS Word

Assimilate XML RSS Feed from URL in C#

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.   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.     using System.Xml; using System.Net; using System.Text; using System.Diagnostics;   // ——————————-   // RSS XML Feed URL string url = “http://msmvps.com/coad/rss.aspx”;   // Create … Continue reading Assimilate XML RSS Feed from URL in C#

Edit File with Shell Registry Settings

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).    Notice: See the cascading if statement both assigning and checking for null.     private void EditFile(string FilePath) {    // Attempt to locate the system’s editor for this file type    RegistryKey rkey = Registry.ClassesRoot.OpenSubKey(Path.GetExtension(FilePath));    if ((rkey != null) &&       ((rkey = Registry.ClassesRoot.OpenSubKey(rkey.GetValue(“”) + @”\shell\edit\command”)) != null) &&       (rkey.GetValue(“”).ToString() != String.Empty))    {       ProcessStartInfo psi = new ProcessStartInfo();         // Don’t use … Continue reading Edit File with Shell Registry Settings

JScript XML Data Access

“Random Vocabulary Word.js”   This simple JScript demonstrates just how easy it is to access data from an XML file through the Windows Scripting Host and MSHTML 4.0.  You must have “Vocabulary.xml” in the same directory when running.     // Created by Noah Coad, coad.net/noah, 4/13/04   xmlFile = “Vocabulary.xml”;   var xml = new ActiveXObject(“MSXML2.DOMDocument.4.0”); xml.validateOnParse = false; xml.async = false; xml.load(xmlFile);   if (xml.parseError.errorCode != 0)    WScript.Echo(“XML Parse Error : ” + xml.parseError.reason); else {    var root = xml.documentElement;    var oNodeList = root.childNodes;      // Select a random word    var rnd = … Continue reading JScript XML Data Access

Simple C# XSL Transformation

“XSLTransform.cs”                                      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.     // Created by Noah Coad, coad.net/noah, noah@coad.net, 4/10/04   using System; using System.IO; using System.Xml; using System.Xml.Xsl; using System.Diagnostics;   namespace XSLTransform {    class Transform    {       private Transform(string[] args)       {          // Make sure at least three command          // line arguments are specified          … Continue reading Simple C# XSL Transformation

XSL Transform XML to CSV

“VocabularyToCSV.xsl”   Since Comma Separated Value (CSV) files are so common, here is a transformation.  It requires “Vocabulary.xml” and a translator.     <?xml version=”1.0″?>   <!— Created by Noah Coad, coad.net/noah, noah@coad.net, 3/23/04 —>   <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>    <xsl:output method=”text” encoding=”ISO-8859-1″/>    <xsl:strip-space elements=”Set”/>    <xsl:template match=”/Vocabulary”>Word,Description <xsl:apply-templates select=”Set”>          <xsl:sort select=”Word”/>       </xsl:apply-templates>    </xsl:template>      <xsl:template match=”Set”>       <xsl:value-of select=”Word”/>,”<xsl:value-of select=”Desc”/>“<xsl:text> </xsl:text>    </xsl:template> </xsl:stylesheet>    

HTML With XML Data Binding

“Vocabulary.html”   This is used in conjunction with “Vocabulary.xml” to demonstrate IE HTML data binding.  Without any scripting, this will pull data from the XML file and display it in the HTML page.  This is considerably different than the XSLT that converts XML into HTML.  Note that this is also a well-formatted XHTML document.     <?xml version=”1.0″?> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>   <!— Created by Noah Coad, coad.net/noah, noah@coad.net, 3/23/04 —> <!— This is a proper XHTML document. —>   <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>    <head>       <title>Vocabulary Words</title>       <style type=”text/css”>          body            {font: … Continue reading HTML With XML Data Binding