Buck Hodges

Visual Studio Online, Team Foundation Server, MSDN

May, 2004

  • Buck Hodges

    Converting a text file from one encoding to another


    The .NET framework handles file encodings very nicely.  Not too long ago, I needed to convert files from one encoding to another for a library that didn't handle the encoding of the original file.  Since someone on an internal alias asked about doing this a couple of weeks ago, I thought it would be useful to post it here.

    The .NET runtime uses Unicode as the encoding for all strings.  The StreamReader and StreamWriter classes in System.IO take an Encoding as a parameter.  So, to convert from one encoding to another, we just need to specify the original encoding and read the file contents into a string followed by writing out the string in the desired encoding.

    The Path class, also in System.IO, provides us with an easy way to create temporary files in the Windows temporary directory.  We can write the results to a temporary file so that if anything goes wrong, the destination file is not overwritten.  Also, it allows the conversion to work when the source and destination are the same file.

    StreamReader allows us to read the source file in blocks so that we don't have any size limitations on the file that need to convert.

    The Main() method below is just a trivial wrapper to call the ConvertFileEncoding()since it wasn't oringally a standalone app.

    // Example: convert test.cs test-conv.cs ascii utf-8

    using System;
    using System.IO;
    using System.Text;
    public class Convert
        public static void Main(String[] args)
            // Print a simple usage statement if the number of arguments is incorrect.
            if (args.Length != 4)
                Console.WriteLine("Usage: {0} inputFile outputFile inputEncoding outputEncoding",
            ConvertFileEncoding(args[0], args[1], Encoding.GetEncoding(args[2]),
        /// <summary>
        /// Converts a file from one encoding to another.
        /// </summary>
        /// <param name="sourcePath">the file to convert</param>
        /// <param name="destPath">the destination for the converted file</param>
        /// <param name="sourceEncoding">the original file encoding</param>
        /// <param name="destEncoding">the encoding to which the contents should be converted</param>
        public static void ConvertFileEncoding(String sourcePath, String destPath,
                                               Encoding sourceEncoding, Encoding destEncoding)
            // If the destination's parent doesn't exist, create it.
            String parent = Path.GetDirectoryName(Path.GetFullPath(destPath));
            if (!Directory.Exists(parent))
            // If the source and destination encodings are the same, just copy the file.
            if (sourceEncoding == destEncoding)
                File.Copy(sourcePath, destPath, true);
            // Convert the file.
            String tempName = null;
                tempName = Path.GetTempFileName();
                using (StreamReader sr = new StreamReader(sourcePath, sourceEncoding, false))
                    using (StreamWriter sw = new StreamWriter(tempName, false, destEncoding))
                        int charsRead;
                        char[] buffer = new char[128 * 1024];
                        while ((charsRead = sr.ReadBlock(buffer, 0, buffer.Length)) > 0)
                            sw.Write(buffer, 0, charsRead);
                File.Move(tempName, destPath);
  • Buck Hodges

    Download the VC++ Toolkit


    Three weeks ago the Microsoft Visual C++ Toolkit 2003 was made available as a free download.  It's the full optimizing compiler.  That's pretty cool.  It doesn't include the IDE, though people have used it to replace the non-optimizing compiler in the VS Standard edition.

  • Buck Hodges

    Visual Studio 2005 Team System (aka Burton)

    The official web site for Visual Studio 2005 Team System is now live, including a Burton blog called AskBurton. I am a developer working on the Burton source control system (Team Foundation), which we code-named Hatteras. Over time I plan to add details about Hatteras and how it works. Here is a good description of Team Foundation from the Team Development page.
    Visual Studio Team Foundation provides integrated source control, work item tracking, reporting, and custom policies that enable your team to efficiently manage change in your software development projects. The components of Team Foundation include work item tracking, source code control, policy support and notifications, and report generating capabilities. By integrating these change management components seamlessly, we unobtrusively inject SCM process and team-specific requirements into the developer’s daily workflow.
    If you are at TechEd, be sure to see presentations by Brian Harry, our product unit manager (PUM), and Doug Neumann, our program manager for Burton source control.
    DEV303 Visual Studio 2005 Enterprise Tools: Enterprise-Class Source Control and Work Item Tracking
    Thursday, May 27 3:15 PM- 4:30 PM, Room 20D
    Speaker(s): Brian Harry
    Track(s): Architecture, Developer Tools and Technologies
    Get an introduction to the new software configuration management system included in the Visual Studio 2005 enterprise tools. See how an integrated and extensible source code control and work item tracking system can boost your team's productivity by significantly streamlining your development processes.
    Hatteras Island, with its famous lighthouse, is part of North Carolina's Outer Banks.
  • Buck Hodges

    Bill Gates' visit to the University of Illinois


    I didn't realize that Microsoft hires more computer science graduates from U of I than any other school.  It's a great school with a lot of bright people (I don't miss the cold January days, though).

    Bill Gates, the chief software architect for Microsoft, chose Illinois for his first stop on a three-day, five campus tour to promote computer science and engineering to students. Illinois is the only public university that is part of this tour. His February 24th talk, titled “Software breakthroughs: Solving the toughest problems in computer science,” was designed to highlight work being done at Microsoft, universities and research labs around the world.

    If you click on Help->About Internet Explorer, you'll see a couple of references to Illinois.

    Based on NCSA Mosaic. NCSA Mosaic(TM); was developed at the National Center for Supercomputing Applications at the University of Illinois at Urbana-Champaign.
    Distributed under a licensing agreement with Spyglass, Inc. [Champaign, IL]

  • Buck Hodges

    Summary of Doug's Managing Software Configurations presentation


    Korby Parnell, our checked-in tech writer, has posted a great summary of Doug's Managing Software Configurations presentation.  He even included highlights from the Q&A.  Check it out and add your comments.

    Rob Caron posted a picture of Doug in action.

  • Buck Hodges

    Doug Neumann on Software Configuration Management with Burton

    Doug's the program manager for Source Control in Visual Studio 2005 Team Server, and his talk will look at doing details of software configuration management with VSTS. Doug's and Brian's talks cover different ground and will really give you a feel for what we're doing.
    DEVC32 How-To: Managing Software Configurations with Visual Studio 2005
    Wednesday, May 26 2:00 PM- 3:15 PM, Cabana 06
    Speaker(s): Douglas Neumann
    Track(s): Developer Tools and Technologies
    Learn about the strategies for working with and managing configurations of source code with Visual Studio 2005. See how branching, merging, and labeling can be applied to implement several standard SCM practices and help you choose the practice that best fits your software development processes.
  • Buck Hodges

    Dev303 summary, more blogs


    Thanks to Rob Caron there are good notes on Brian Harry's presentation.

    DEV303 - Visual Studio Team System: Enterprise-Class Source Control and Work Item Tracking

    Kevin Kelly (also in North Carolina) has started a weblog, opening with “Why Work Item Tracking?”  Ask him if they can add make work items blogs. Or maybe all work items should be blog entries, and products would be blogs.  Then you could subscribe to the bug feeds for your stuff.  :-)

    Blogging in DevDiv continues to reach new heights.  With his opening "Hello, World" post, S. "Soma" Somasegar, corporate vice president of the Developer Division at Microsoft Corporation, has provided you a direct link to the top.

  • Buck Hodges

    Brian Harry's weblog


    So Korby's gotten Brian going.  Check out “A little history on me and the Visual Studio Team System” for how we got here.

Page 1 of 1 (8 items)