Printer Friendly Version      Send     
Click to Rate and Give Feedback
Related Articles
We introduce you to the benefits of building composite applications with the Composite Application Guidance for WPF from Microsoft patterns & practices.

By Glenn Block (September 2008)
ADO.NET Data Services provide Web-accessible endpoints that allow you to filter, sort, shape, and page data without having to build that functionality yourself.

By Shawn Wildermuth (September 2008)
See how routed events and routed commands in Windows Presentation Foundation form the basis for communication between the parts of your UI.

By Brian Noyes (September 2008)
Technology changes at a lightening-fast pace. This month Howard Dierking considers how the rapid changes affect developer priorities and magazine focus.

By Howard Dierking (September 2008)
More ...
Articles by this Author
This month Toolbox provides help with error logging, finds an app that helps you write LINQ queries, and explores the non-technical side of development.

By Scott Mitchell (September 2008)
Host a wiki the easy way, get the screen shots you need and mark them up, and read about LINQ this month in Toolbox.

By Scott Mitchell (July 2008)
This month test your web site on many platforms and browsers without setting up a test environment, use mock objects for unit testing, and visit Raymond Chen.

By Scott Mitchell (June 2008)
This month the Toolbox column takes a look at database logging, Joel Spolsky's blog, printing code projects, and ASP.NET reading.

By Scott Mitchell (May 2008)
See how to log Web application errors for better health monitoring, what to read if you’re thinking about LINQ, and which blog Scott recommends reading this month.

By Scott Mitchell (April 2008)
This month, a better design-time experience for Web apps, Scott Guthrie's blog, extending Extend Lutz Roeder's Reflector, and more.

By Scott Mitchell (March 2008)
This month, more of the tools you need to get your job done.

By Scott Mitchell (December 2007)
This time: Windows Forms grids, professional-looking date textboxes, file merging, and more.

By Scott Mitchell (November 2007)
More ...
Popular Articles
Howard Dierking talks to the inventor of C++, Bjarne Stroustrup, about language zealots, the evolution of programming, and what’s in the future of programming.

By Howard Dierking (April 2008)
Efficient parallel applications aren’t born by merely running an old app on a parallel processor machine. Tuning needs to be done if you’re to gain maximum benefit.

By Rahul V. Patil and Boby George (June 2008)
Here the author answers questions regarding the Entity Framework and provides an understanding of how and why it was developed.

By Elisa Flasko (July 2008)
We introduce you to the benefits of building composite applications with the Composite Application Guidance for WPF from Microsoft patterns & practices.

By Glenn Block (September 2008)
More ...
Read the Blog
SQL Server 2008 supports a new data type, HierarchyID, that helps solve some of the problems in modeling and querying hier­archical information. In the September 2008 issue of MSDN Magazine, Kent Tegels introduces you to the ...
Read more!
Many people using SharePoint technologies don't realize that there is auditing support built directly into the Windows SharePoint Services (WSS) 3.0 platform. In the September 2008 issue of MSDN Magazine, Ted Pattison walks you through a ...
Read more!
The September 2008 issue of MSDN Magazine is now available online. Here's what's in the issue: Hierarchy ID: Model ...
Read more!
Silverlight 2 features a rich and robust control model that is the basis for the controls included in the platform and for third-party control packages. You can also use this control model to build controls of your own. In the August 2008 issue of MSDN Magazine, Jeff Prosise describes how to ...
Read more!
In the August 2008 issue of MSDN Magazine, Matt Milner covers several topics regarding development with Windows Workflow Foundation, some that are intended to address specific reader questions, such as how to safely share a persistence database ...
Read more!
LINQ is a powerful tool enabling quick filtering data based on a standard query language. It can tear through a structured set of data using a simple and straightforward syntax. In the August 2008 issue of MSDN Magazine, Jared Parsons demonstrates a ...
Read more!
More ...
Toolbox
Serializing objects, Scott Allen's blog, Site Performance, and more
Scott Mitchell

Serialize and Deserialize Fixed-Length and Delimited Files
I was recently working on a project where we needed to import several thousand records stored in a comma-delimited file into our Microsoft® .NET Framework application. Not only did our application need to import this data, but it also needed the ability to export data in the same format for use by external programs that still rely on the data in a delimited format.
If you've ever used the .NET Framework built-in XML or binary serialization capabilities, you know how easy it is to save an object's state to disk as an XML or binary file, as well as how easy it is to reload the object from disk back into memory. In a nutshell, you decorate a class with attributes, indicating how the class's properties are to be serialized. Once the class has been decorated, serializing or deserializing an object requires just one line of code.
While the .NET Framework includes serialization formatter classes for serializing objects to XML and binary formats, it does not include formatters for working with comma-delimited files. The good news is that serializing objects to fixed-length and delimited text files is as easy as XML and binary serialization thanks to FileHelpers version 2.0 by Marcos Meli.
To use FileHelpers to serialize an array of class instances to a fixed-length or delimited text file, start by decorating the class's properties with the applicable attributes. When serializing to fixed-length files, there is an attribute to indicate the length of each field; when serializing to delimited files, there's an attribute to indicate the delimiter.
There are also attributes that you can use to indicate the data type and format of the data, whether white space should be trimmed, and whether the field is optional. An appropriately decorated class is referred to as a record class. (In addition to using attributes to specify serialization specifics, FileHelpers also includes an API for programmatically defining the serialization and deserialization rules at run time.)
As you may know, creating the record class can be a tedious process. To help streamline the process and reduce the chance of a syntax error or typo, FileHelpers ships with a Record Class Wizard program. The wizard is a standalone GUI application that prompts for the precise fields in the fixed-length or delimited file and builds the corresponding record class with the appropriate properties and attributes.
As with XML and binary serialization in .NET, once you've created a record class—either by decorating its properties with attributes or by programmatically defining the record class—persisting a collection of such objects to disk or populating a collection of such objects from an existing text file is as easy as calling the library's WriteFile or ReadFile methods.
As the FileHelpers library serializes or deserializes the object or text file, it raises an event immediately before and after each record is processed. These events give you the opportunity to inspect or modify the data or cancel the operation prior to each read or write. FileHelpers includes asynchronous versions of the WriteFile and ReadFile methods, which are useful when working with especially large amounts of data. There's also a file transform engine that assists in transforming the structure of a fixed-length or delimited file.
In addition to classes for serializing the record class to disk, there are also classes for reading and writing records to and from Microsoft Access®, SQL Server®, and Microsoft Excel® data stores. Using these classes requires a bit more code than when serializing to disk. For example, when importing a record class to a SQL Server database you must specify the server's connection information and provide the INSERT statement and values. However, using these classes can shave off a lot of boilerplate data access code.
Price: Free, open source.
Serialize and Deserialize Fixed-Length and Delimited Files (Click the image for a larger view)

Blogs of Note
A common challenge developers face when building data-driven apps centers around database versioning. After the app's initial deployment, and as new feature enhancements are being added, developers will need to make changes to the data model. What's the best way to implement these changes and propagate them through the development, testing, and deploying phases? If you're looking for guidance to project-management questions such as this one, check out the blog by author, speaker, and consultant Scott Allen.
The advice Scott dispenses comes directly from the trenches. Whether it's an entry about unit testing, shrink wrapping an ASP.NET Web application, or getting the most out of Visual Studio®, Scott shares his experiences, what he tried, what worked, what didn't, and traps to avoid. Alongside architecture and project management-focused blog entries, you'll find more nitty-gritty technical posts about LINQ, JavaScript and JavaScript Object Notation (JSON), Windows® Workflow, and Silverlight™.
My favorite aspect of Scott's blog is his ongoing "What's Wrong With This Code" series. In each installment, Scott shares a snippet of code with some faulty logic and invites his readers to try to find and fix the problem. It's a great way to hone your debugging and general problem-solving skills, as well as a way to see the techniques and thought processes used by other developers as they tackle the same problem.
Hone Your Debugging Skills and See Other Techniques on Scott Allen's Blog (Click the image for a larger view)

Build Faster Web Pages with YSlow and Firebug
In the March 2008 Toolbox column I reviewed Firebug, a free, open source browser extension for Mozilla Firefox that displays information about the visited page's HTML, CSS, JavaScript, and images. Firebug makes it easy for a Web developer to visually inspect and modify the various elements of a Web page. It also displays the size and time required to download any external resources such as images or JavaScript files.
For a more detailed analysis of your page's load time, check out YSlow version 0.9.5, a Mozilla Firefox browser add-on created by Yahoo! that integrates with Firebug. Once installed, YSlow appears as a tab in the Firebug user interface. From the YSlow tab you can view detailed information about the external resources (just as you can from Firebug), statistical information about the page's components, and tips for improving the page's performance.
YSlow's Stats view breaks down the bandwidth consumed by the page's HTML, IFrame content, Flash content, JavaScript files, CSS files, and images, and sums the total size and total number of HTTP requests needed. Furthermore, it details this breakdown when the data has been cached by the browser. The cookies sent to the page, along with the sizes and contents, also are enumerated here.
The most indispensable feature of YSlow is the Performance view, which lists 13 performance tips, such as "Make fewer HTTP requests" and "gzip components." The loaded Web page is evaluated against these 13 metrics and assigned a letter grade for each. If there are specific changes that can improve the page's performance, YSlow lists them here. You can click any of these tips to be whisked to a page with a more detailed explanation of the impact on performance and information on how to implement the performance enhancement.
In addition to its Stats and Performance views, YSlow includes a number of helpful tools. From the YSlow menu you can run the page's JavaScript through Douglas Crockford's JSLint program, which parses the script for common problems. There are also tools to view the page's entire JavaScript or CSS content on a single page, regardless of how many external files into which the JavaScript and CSS are split. And there's a tool for displaying YSlow's Performance, Stats, and external resources views in a single, formatted Web page, which makes it easy to print or e-mail the results.
Price: Free.
YSlow's Detailed Analysis of Web Pages (Click the image for a larger view)

From the Bookshelf
As a freelance developer and consultant, I work with clients who have existing apps but need help in adding new features. Some applications are written in C#, others in Visual Basic®, so I need to have a mastery of both languages. Visual Basic is easy to pick up; its prose-like syntax and straightforward semantics have helped make it one of the most popular programming languages in the world. But there's a wide gulf between knowing Visual Basic and mastering it.
To help bolster my Visual Basic skills, I picked up Accelerated VB 2008 (Apress, 2008) by Guy Fouché and Trey Nash. This book dispenses with the typical page-filling content found in most computer trade books and replaces it with distilled information and code examples that get right to the point. Because of this terse style, however, Accelerated VB 2008 is not for beginners who are interested in learning Visual Basic, but it's ideal for intermediate developers who are either looking to bolster their understanding of Visual Basic or who are in need of a good desk reference.
The first several chapters focus on core Visual Basic language concepts, including types and typing rules; classes, methods, properties, and fields; interfaces; delegates and events; and exception handling. Subsequent chapters look at working with higher-level constructs, such as strings, arrays, collections, and generics. There's also chapters on threading and LINQ.
I especially liked the Visual Basic 2008 Best Practices chapter, which offers guidance for developers creating new classes. The chapter includes discussions on designing classes that can be cloned, converted to other types, and ordered.
If you' are an intermediate developer looking to hone your Visual Basic skills, or are in need of a Visual Basic language desk reference, pick up Accelerated VB 2008.
Price: $39.99.

Send your questions and comments for Scott to toolsmm@microsoft.com.

Scott Mitchell, author of numerous books and founder of 4GuysFromRolla.com, is an MVP who has been working with Microsoft Web technologies since 1998. Scott is an independent consultant, trainer, and writer. Reach him at Mitchell@4guysfromrolla.com or via his blog at ScottOnWriting.NET.

© 2008 Microsoft Corporation and CMP Media, LLC. All rights reserved; reproduction in part or in whole without permission is prohibited.
Page view tracker