Archive for the ‘Speaking’ Category

Staying with the Fire Hose

At the recent Ann Arbor Day of .Net, my colleague David Giard arranged an excellent panel discussion with Jim Holmes, Mike Eaton, Jay Harris, Patrick Steele, and Jason Follas, about keeping current with the stream of constantly evolving technology with which we work (aka the Fire Hose). I felt this was one of the best sessions of the day, the audience was very engaged with the panel. It definitely ended too soon. *Update* David Giard posted a video of the discussion on his Technology and Friends webcast.

One of the discussion points revolved around training. I think a couple points were pretty clear from the discussion:

  1. Companies don’t provide enough or the right training
  2. You own your career, it’s up to you to get the training you need.

One of the discussion points that I wanted to contribute, was that the existence of Day of .Net is partly driven as a reaction by the community to the two points above. We attend these conferences to learn (among other things) just enough about new technologies so we can effectively evaluate them and see if they fit into our day-to-day jobs or personal interests. Traditional training methods (books, classroom training, CTBs) seem to be falling further and further behind as the fire hose continues to flow faster and faster. We are at the conference to get some of the training we need, because it’s not available any other way.

Technical Books

For me, books have always been part of my learning, but more and more they are falling short. Technology is changing faster than publishers can respond. More often than not the book I need isn’t going to be published for a while. Even today (May 2010), look at the number of new developer technologies that are hot in my circles:

  • Silverlight 4
  • Windows Azure
  • Windows Phone 7
  • Android
  • SharePoint 2010
  • .Net 4.0

These are by no means niche technologies. You would be hard pressed to find many books published on them (maybe some around beta releases, those get stale fast and are often of dubious quality due to the rushed nature of the title). I completely understand the lag time, but I think the publishers need to step up and start paying authors as full-time employees so they can commit full time to a book and get it released sooner. Typically book authors are doing this on the side, I am sure that slows down time to market. There are some Microsoft technologies, like Commerce Server, that haven’t seen a new book since 2002. Arguably that’s a much more niche technology (and certainly not as popular as SharePoint for instance), but if a company as large as Microsoft is investing money to develop the product, they have users of the software so there must be some kind of market for those books.

I know lots of folks don’t work on the cutting edge (I spoke to a group of VB6 developers yesterday that didn’t even have Visual Studio installed), so this is less of a problem for them. As a consultant, this is a constant problem for me. Maybe I am am the minority and there isn’t as much market for these books so early? That’s hard for me to say. Either way, I know the publishers are losing my money, because I end up digging up blog posts and finding online articles to meet my need long before the book hits the shelves for me to purchase it.

Day of .Net Slides

I posted my slide deck from my talk (The Demise of Xcopy Deployment) at the terrific Ann Arbor Day of .Net 2010 on SlideShare. Thanks to everyone who attended both my talk and the event. A special thanks to the event organizers for doing a great job.

Creating VPC Networks using Windows 7 as Host

I just want to track these two great posts on how to set up a virtual private network for hosting one or more virtual machines where you may not have an actual network connection. This happens to me when I’m giving presentations (like my upcoming one at Day of .Net!) and the host and guest machines need to be able to talk to one another, even if the host machine is not on any network.

Windows Virtual PC: Network Between Host and VM Using Loopback Adapter

Windows 7 & Network Loopback Adapter Settings

Ann Arbor Day of .Net 2010

I’ll be speaking at the Ann Arbor Day of .Net on Saturday, May 1st, 2010. It’s being held at Washtenaw Community College. Register for the event at http://www.dayofdotnet.org/AnnArbor/Spring2010/Registration.aspx 

Here’s the abstract for my talk:

The Demise of Xcopy Deployment

One of the great features of .Net when it first released was Xcopy deployment. No more .dll registrations, just copy the files to the web server. While this was a great feature for Microsoft developers, new problems emerged, specifically around managing web.config. Sections like connection strings and custom errors need to be managed between environments, which meant many copies of the files or scripts to change them. Other necessary steps, like managing permissions and IIS configuration were still outside the Xcopy process. A recent tool, MSDeploy, is now integrated into Visual Studio 2010 and makes managing these issues easier. Besides web.config, MSDeploy also manages file deployments and synchronization, ACLs, and IIS settings. If your deployments have multiple steps, need ReadMe files, or can’t be done by someone outside your team, you need to learn MSDeploy!

Interview on Debugging

David Giard posted his interview with me for his show, Technology and Friends, talking about debugging and WinDBG.

Debugging with WinDBG

Last week I had the opportunity to talk about debugging and WinDBG at Sogeti. We recorded the session as a Live Meeting and my colleague David Giard was kind enough post the video for me. I have a previous blog post linking to the tools I mentioned during the talk.

Out of the blue….

I posted my Day of .Net presentation (PowerPoint slides) on SlideShare. Apparently they have an editorial board that picks presentations to highlight on their home page, and they picked mine! I had no idea they even did this. I tried a new presentation format (thanks to Josh Holmes), and apparently it’s working out well.

[Originally posted at http://www.dotnetjunkies.com/WebLog/davetrux/archive/2008/10/23.aspx]

Posted on:
Posted in Speaking | Comments Off

Day of .Net Presentation Resources

Thanks to everyone who attended my talk! Here’s some links related to the talk:

My PowerPoint Presentation hosted on SlideShare

Debugging Tools for Windows web site / download WinDBG

IIS Resource Kit (TinyGet)

LogParser for querying IIS log files

FireBug

YSlow

John Robbins’ book on .Net 2.0 Debugging

 

Good blog posts on WinDBG

A Big List of Debugging Resources

Getting Started with WinDBG Part I

Getting Started with WinDBG Part II

Debugging Demos

 

[Originally posted at http://www.dotnetjunkies.com/WebLog/davetrux/archive/2008/10/21/536761.aspx]

Posted on:
Posted in Speaking | Comments Off

Speaking at Day of .Net in Ann Arbor, MI

I am giving a talk at the next Day of .Net in Ann Arbor. I am giving a talk entitled “Beyond Breakpoints: Debugging and Troubleshooting”. Basically I will be talking about finding bugs and performance problems, looking at techniques that go further than setting a breakpoint and stepping through some code.

Sessions have been posted and registration is open!

 

[Originally posted at http://www.dotnetjunkies.com/WebLog/davetrux/archive/2008/9/29.aspx]

Posted on:
Posted in Speaking | Comments Off

Building a Basic Excel Document with Open XML

I recently gave a talk about Open XML, and found that there were not many complete code samples out there which described how to build Office 2007 documents using .Net and SpreadsheetML. Most of the examples I ran into were snippets or functions, or just examples of the SpreadsheetML. As one of my demos, I created a C# class which builds a basic spreadsheet. This post describes that class.

There are prerequisite installs required to run this code:

  • .Net 3.0 Framework (System.IO.Packaging is part of WPF)
  • SDK for Open XML Formats, which is currently a CTP, so the code is subject to change if the object model changes at all with the final release (so therefore does the code in this post).
  • Code Snippets that are available for Open XML.

The class (called Spreadsheet) does two basic things:

  1. Create a spreadsheet package
  2. Insert data into a worksheet in the newly created package

The first step is creating the package, which consists of XML files for the SpreadsheetML and XML files which manage the relationships between those files. In an Open XML spreadsheet, the minimal spreadsheet package requires three documents containing SpreadsheetML:

  1. A workbook file
  2. A worksheet file
  3. A relationship file

Additionally, SpreadsheetML uses a concept called “Shared Strings”. SpreadsheetML dictates storing Shared Strings separately from the worksheet in their own document, so the document stores less data if the document re-uses strings. Strings can also be added to the spreadsheet “in-line” and not used Shared Strings storage. For this example labels are stored as Shared Strings to demonstrate the concept, therefore the spreadsheet package also requires a Shared Strings document.

The SDK for Open XML Formats provides a new component, Microsoft.Office.DocumentFormat.OpenXml.dll, that wraps some of the functionality of creating an Open XML document with System.IO.Packaging. Essentially it manages creating the files and the relationships between the files in the package. Once you have created the files and relationships, you still need to create code to insert actual data into the documents. This example uses two steps:

  1. Create the basic XML document using a template of existing XML
  2. Insert data into the existing XML.

The following are the contents of three small XML files created and added to a Templates directory in the solution. These three files are the basis for the required parts of the package:

The workbook template

<?xml version=1.0 encoding=UTF-8 standalone=yes?>

<workbook xmlns=http://schemas.openxmlformats.org/spreadsheetml/2006/main xmlns:r=http://schemas.openxmlformats.org/officeDocument/2006/relationships>

    <sheets>

        <sheet name={1} sheetId=1 r:id={0} />

    </sheets>

</workbook>

Notice that the XML contains .Net placeholders. Later on we can replace these with actual values that can vary at run time.

The worksheet template

<?xml version=1.0 encoding=UTF-8 standalone=yes?>

<worksheet xmlns=http://schemas.openxmlformats.org/spreadsheetml/2006/main >

    <sheetData/>

</worksheet>

The shared strings template

<?xml version=1.0 encoding=UTF-8 standalone=yes?>

<sst xmlns=http://schemas.openxmlformats.org/spreadsheetml/2006/main>

</sst>

These XML templates make up the basic content of the package. The C# class contains a CreateSpreadSheet procedure which will create the basic pieces of the package. The main thing to notice is that  by creating the part object (workbook, shared strings, worksheet), you are only creating the part file, not the content of that part file. The templates above become the content for the parts. There is no need to manage the relationship files directly, the API is doing that automatically.

public void CreateSpreadsheet(string path, string firstSheetName)

{

    using (SpreadsheetDocument doc = SpreadsheetDocument.Create(path, SpreadsheetDocumentType.Workbook))

    {

        //Add the workbook

        WorkbookPart workbook = doc.AddWorkbookPart();

 

        //Create the shared strings part

        SharedStringTablePart stringTable = workbook.AddNewPart<SharedStringTablePart>();

        this.AddPartXml(stringTable, this.ReadXML(@”Templates\SharedStringTemplate.xml”));

 

        //Create a worksheet

        WorksheetPart sheet = workbook.AddNewPart<WorksheetPart>();

 

        //Get the relationship id so the workbook and worksheet can be related

        string sheetId = workbook.GetIdOfPart(sheet);

 

        this.AddPartXml(workbook, this.WorkbookXml(sheetId, firstSheetName));

        this.AddPartXml(sheet, this.ReadXML(@”Templates\WorkSheetTemplate.xml”));

 

        doc.Close();

    }

}

The only interesting part is retrieving the ID of the worksheet part when building the workbook part. To create the content of each part the procedure opens an XML file and streams the content into the file. There are helper functions for this, which are really just standard ways of handling XML in .Net:

protected void AddPartXml(OpenXmlPart part, string xml)

{

    using (Stream stream = part.GetStream())

    {

        byte[] buffer = (new UTF8Encoding()).GetBytes(xml);

        stream.Write(buffer, 0, buffer.Length);

    }

}

 

protected string ReadXML(string fileName)

{

    StreamReader reader = new StreamReader(Environment.CurrentDirectory + @”\” + fileName);

    string contents = reader.ReadToEnd();

 

    return contents;

}

 

protected string WorkbookXml(string sheetId, string sheetName)

{

    string contents = this.ReadXML(@”Templates\WorkbookTemplate.xml”);

 

    return string.Format(contents, sheetId, sheetName);

}

Notice the WorkbookXml procedure has a call to string.Format to replace some placeholders with actual data: the ID of the worksheet part relationship and the name of the worksheet. The name of the worksheet is important later, when we want to add data to the worksheet.

The second step is to actually add data to the worksheet. The class uses two functions available as Code Snippets (XLInsertStringIntoCell, and XLInsertNumberIntoCell). I won’t reproduce the code here as I don’t own it, but essentially the functions open the proper parts and insert the data. These functions take in the file, the sheet name, cell reference and cell value as parameters.

Lastly, I wrote a console app to exercise the Spreadsheet class:

class Program

{

    protected static readonly string fileName = “example.xlsx”;

    protected static readonly string firstSheetName = “Sheet1″;

 

    static void Main(string[] args)

    {

        string path = Environment.CurrentDirectory + @”\” + fileName;

 

        Spreadsheet file = new Spreadsheet();

 

        file.CreateSpreadsheet(path, firstSheetName);

 

        file.XLInsertStringIntoCell(fileName, firstSheetName, “A1″, “Category”);

        file.XLInsertStringIntoCell(fileName, firstSheetName, “B1″, “Value”);

        file.XLInsertStringIntoCell(fileName, firstSheetName, “A2″, “Red”);

        file.XLInsertNumberIntoCell(fileName, firstSheetName, “B2″, 30);

        file.XLInsertStringIntoCell(fileName, firstSheetName, “A3″, “Blue”);

        file.XLInsertNumberIntoCell(fileName, firstSheetName, “B3″, 60);

        file.XLInsertStringIntoCell(fileName, firstSheetName, “A4″, “Green”);

        file.XLInsertNumberIntoCell(fileName, firstSheetName, “B4″, 10);

 

        Console.WriteLine(“Workbook created at “ + path);

 

        Console.ReadKey();

    }

}

Before the comments start to fly, I want to point out a couple things:

  • This bit of code is not that efficient, I realize it opens and closes the package a bunch of times. This is really just to demonstrate what is possible and not what is necessarily the best practice. There are very few code samples available, and I am shooting for simplicity here.
  • I know ExcelPackage is on CodePlex and does a better job of wrapping the APIs involved and is much easier to write code with. Once you have a basic understanding of these APIs you will appreciate for the work being done on that project.

Download the VS 2005 project. Don’t forget to install all the prerequisites listed above before trying the project. I didn’t include the two functions necessary from the Code Snippets in the project either (since I didn’t write that code), you will have to put those in yourself.

Bad Behavior has blocked 55 access attempts in the last 7 days.