Tuesday, 02 March 2010
This is just a very short example of writing files to a CD or DVD using C# on Windows XP. For this I will use the XP Burn Component provided by Microsoft. This is a class library that you can use from C# or any other .Net language to write files to disc, simply down load the MSI file from the XP Burn web site and follow these steps.
  1. Start Visual Studio and create a new Windows Forms Application
  2. Right click on the 'References' folder and select 'Add Reference.'
  3. Browse to the location of the XPBurnComponent.dll file, for me I had chose all the default settings during the installation options and the dll was located under 'My Documents' folder in MSDN\XPBurn. AddReference
  4. Once you have added the dll to your project you can begin using the classes it contains by adding a using directive for the XPBurn namespace

    using XPBurn;

  5. Writing files to the disc is now very easy al you have to do is create an instance of XPBurnCD, call the AddFile method to add files to the disc and the RecordDisc method to actually write the files to the disc. This sample method shows adding files in a directory and writing these to disc.

    XPBurnCD cd = new XPBurnCD(); cd.BurnComplete += new NotifyCompletionStatus(BurnComplete); MessageBox.Show(cd.BurnerDrive); DirectoryInfo dir = new DirectoryInfo(_burnFolder); foreach (FileInfo file in dir.GetFiles()) { cd.AddFile(file.FullName, file.Name); } cd.RecordDisc(false, false);


The XPBurnCD class has a number of events that you can use to monitor the progress of the burn process. In the above example I have used the NotifyCompletionStatus so that I can display a message to the user when all the files have been written to the disc. For more information on the classes, methods and properties that XPBurn has take a look at the help file 'XPBurnDocs.chm' which is installed in the same directory as 'XPBurnComponent.dll'.

You can download my Visual Studio 2010 sample application