Burn CDs right from your .NET code…


Anson Horton gave me this cool .NET component and source code last night so I’ve uploaded it to microsoft.com for your burning fun


The XPBurnComponent allows your .NET applications to burn files to CDR/W discs on a Window XP® or Windows 2003 Server system. This component does not work for systems which have a different OS installed; though it will detect that case and give a reasonable error message. This component talks directly to the system’s IMAPI interfaces and doesn’t use the Windows XP CD burning wizard, so it’s possible to create your own snazzy UI for burning CDs.

Though the component is a UserControl, I wouldn’t recommend that you put it in the toolbox. Instead, simply reference it and use it like you would use any other framework type (the constructor can potentially throw exceptions, so for robust handling you should wrap it in a try…catch). The documentation and source for the component is included in the download.

You can download the component, developer documentation, and source from here. Send any feedback, comments, or bug reports to ansonh@microsoft.com.

In a few hours it should be happily living at http://msdn.microsoft.com/vcsharp/team/code/xpburn/default.aspx (future home of samples and any ongoing updates) but the download on its own is available now from http://download.microsoft.com/download/6/9/c/69c5d1b7-e3ac-4986-99f1-0c55dc374d66/xpburn.msi

Comments (39)

  1. Bjorn Reppen says:

    Great!

    BTW: Don’t you all hate those .msi files?

  2. aimee says:

    this is verry cool

  3. Vito Pantaleo says:

    Hello!, give me a ex.. ?

  4. Bernhard says:

    When will the code be updated to support naming of cd’s?

  5. Pherat says:

    ();//initialise component

    XPBurn XPB = new XPBurn();

    //Add file you want to burn, and Name of Cd

    XPB.AddFile(@"somthing.txt","MYCDName")

    /*Burn CD Parameter1=simultate or burn – type true to burn

    Parameter2=Eject Cd after burn..type true to eject Cd*/

    XPB.RecordDisk(true,true);

  6. Dan says:

    Trying to burn without a CD inserted throws an exception from a thread (when calling SetActiveDiscRecorder). Trying to burn more than one file from the same directory does the same (when calling CreateStorageDirectory).

  7. ashley says:

    this website is ausom

  8. Tom Harris says:

    Has anyone played with the XPBurn tools Event Notification? I keep getting signatures don’t match errors.

  9. shahriyar says:

    hi

    how can use progressbar whit this component ?

    yank you

  10. Ed says:

    Dan,

    In reply to your message 3/9/2004 8:51 AM:

    "Trying to burn without a CD inserted throws an exception from a thread (when calling SetActiveDiscRecorder)."

    — There are properties such as isWritable, isUsable, isReadable, etc, that you can use to determine if there not only is a cd in the drive but if it is usable.

    "Trying to burn more than one file from the same directory does the same (when calling CreateStorageDirectory)."

    — Although the documentation says otherwise, you must specify the path to the "nameoncd". Otherwise you are correct you can only burn one file from any source folder. You must specify the full path for both the "filename" and "nameoncd" and it works. Checking the source code, this is pretty redundant becuase the first thing the code does with the path you specify for the "nameoncd" is remove the path.

  11. Ed says:

    Pherat,

    In reply to your message 2/29/2004 4:18 PM:

    "

    //Add file you want to burn, and Name of Cd

    XPB.AddFile(@"somthing.txt","MYCDName")

    "

    — should be XPB.AddFile(@"c:somthing.txt", (@"c:somthing.txt")

    "

    /*Burn CD Parameter1=simultate or burn – type true to burn

    Parameter2=Eject Cd after burn..type true to eject Cd*/

    XPB.RecordDisk(true,true);

    "

    — the first parameter is simulation, so to burn you sould put false.

  12. Ed says:

    oops, how did that ( get in there…

    XPB.AddFile(@"c:somthing.txt", @"c:somthing.txt");

  13. Hugo Hallman says:

    Hello.

    Thank you very much for this seemingly great library. (Haven’t tested it yet)

  14. Ron says:

    We have run some tests with this DLL with strange results. Firstly, if you fail to spot any media, disk or drive problems before doing a RecordDisk, it screws up the disk (marks it as having zero free space) and sometimes locks the resource on the drive.

    But more interestingly, we are able to write to one drive on one PC but not another on a second PC using the same code.

    The problem seems to be that on the second PC, it reads all disk as having zero Free Disk Space, even though they are blank.

    I would be interested if anyone has had similar problems, or knows any solutions.

    Thanks

  15. VJ says:

    How to use the status bar/progress bar with this component

  16. Marc says:

    Any VB.NET sample, even short is welcome…

  17. chris says:

    this is an awesome place to burn cd’s

  18. chris says:

    you guys are great.

  19. nick says:

    im glad that you can do stuff like this

  20. nick says:

    im glad that you can do stuff like this

  21. TM says:

    My question is how can I burn multiple sessions with XPburn.

    Thanks!

  22. jbb92 says:

    This dll calls the IDiscMaster::SetActiveDiscRecorder method that doesn’t work on my PC.

    SetActiveDiscRecorder always returns the exception HRESULT:0x80040225 (IMAPI_E_StashInUse).

    MSDN says that SetActiveDiscRecorder relies on exclusive access to MSDiscStashObj but I don’t how to do that.

    I would be interested if anyone has had similar problems, or knows any solutions.

    Thanks

  23. jbb92 says:

    Microsoft found a solution to my problem :

    "I’m sorry to hear about the problems you’re having. This is definitely a bug in the component. What probably happened is that an exception occurred during the execution of your program. The exception meant that certain cleanup didn’t happen, so imapi.exe is still running. If you run task manager on your machine, you’ll probably see that imapi.exe is running. Kill the process, then try your program again. It should work. I plan to release an update this weekend, and this is one of the problems I intend to fix."

  24. EDWARD says:

    THANK YOU

  25. txt says:

    Very useful component. Where can I get the updated version of the component?

    Thanks

  26. Simon says:

    If anyone’s interested, short article on how to use this example library to write Audio discs from WAV: http://www.sichbo.ca/DotNetCode/1201

  27. Aris says:

    How can I modify the source code so that when the burning process is finished, to delete the files that I have burned from my hard disk?

  28. Paul says:

    "I plan to release an update this weekend, and this is one of the problems I intend to fix"

    Did the new version get released yet?

  29. lb says:

    I have been trying to use this component for a simple burning program I am writing in C#. So far I have just been trying to add two files to a cd and call RecordDisc(false, true) to just mock the burning process. Unfortunately I keep getting this error…

    An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in xpburncomponent.dll

    Additional information: StartIndex cannot be less than zero.

    After I stop the program and run it again, IMAPI is left running in the background so it throws another error until I manually kill that process and then I am back to the ArgumentOutOfRangeException. Any ideas? The component seems so simple and everyone has had such great experiences with it according to all of the posts above, I can’t figure out what I am doing wrong!

    Thanks.

  30. RM says:

    Great place for IMAPI stuff. Has anyone tried using events and event handlers? It would be helpful if someone posts a sample which trps event notifications from IMAPI and shows the progress of the write.

  31. rm says:

    I am able to successfully burn the files to the CD. But after a few cycles, I have started seeing COMException 0x8004021C – IMPAI_E_DISCFULL. Physically I can see that there is enough space for the next burn. But it keeps throwing this error. Even when tried to copy the files to the CD from the Windows explorer, I see the same error. Is anyone experiencing similar problem after a few files are burnt?

  32. hunter k says:

    heyi want to burn some cds

  33. melinda says:

    cool

  34. LEJ says:

    From 6/23…

    "I plan to release an update this weekend, and this is one of the problems I intend to fix."

    Has this been/going to be released? The imapi.exe process isn’t getting terminated and is causing problems.

  35. Anson Horton says:

    Hey Guys,

    Sorry for not getting an update out sooner. I thought I was going to be able to take care of it a few weekends ago, but it turns out to be a more difficult problem then I anticipated. I do have an updated component that solves the problem of ‘duplicate keys’/specifying a different nameOnCD then filename. The update also adds the ability to set the volume name; however, it doesn’t solve the file locking or imapi.exe still loaded issue. I’ll post it soon.

    -Anson

  36. Vinoth says:

    How can make use of this dll from ASP.net page such that it detect client’s CD R/W drive and burns the file that the client gives from his hard drive? Any pointers would be appreaciated.

    -Vinoth