Here's a small sample using NAudio's midi file processing classes to write a simple set of notes to a .mid file.