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.
- Start Visual Studio and create a new Windows Forms Application
- Right click on the 'References' folder and select 'Add Reference.'
- 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.
- 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
- 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);
DirectoryInfo dir = new DirectoryInfo(_burnFolder);
foreach (FileInfo file in dir.GetFiles())
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