LEADTOOLS Multimedia Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.31
How to use the MediaWriter to burn ISO files and DVD images

Take the following steps to start a project and to add some code that burns an ISO file, or a directory of files to disc

  1. Start Visual Studio .NET.
  2. Choose File->New->Project… from the menu.
  3. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
  4. Type the project name as "Burn ISO and CD_DVD Files" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
  5. In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.dll
    • Leadtools.MediaWriter.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and add the following controls to the form.
    • Textbox: Name = _txtInput
    • ComboBox: Name = _cmbDrives
    • Button: Name = _btnWrite, Text = "Write Data"
  7. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:

    [Visual Basic]

                Imports Leadtools
                Imports Leadtools.MediaWriter
                
    

    [C#]

     
                using Leadtools;
                using Leadtools.MediaWriter;
                
    

  8. Add the following class level variables::

    [Visual Basic]

                Dim mediaWriter as MediaWriter
                Dim burnerDrive as MediaWriterDrive
                
    

    [C#]

                MediaWriter mediaWriter;
                MediaWriterDrive burnerDrive;
                
    

  9. Add an event handler to the Form1 Load event and add the following code:

    [Visual Basic]

                Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
                   mediaWriter = New MediaWriter()
                   _cmbDrives.Items.Clear()
                   For Each drive As MediaWriterDrive In mediaWriter.Drives
                      _cmbDrives.Items.Add(drive.Name)
                   Next drive
                   _cmbDrives.SelectedIndex = mediaWriter.CurrentDriveNumber + 1
                End Sub
                
    

    [C#]

                private void Form1_Load(object sender, System.EventArgs e)
                {
                   mediaWriter = new MediaWriter();
                   _cmbDrives.Items.Clear();
                   foreach (MediaWriterDrive drive in mediaWriter.Drives)
                   {
                      _cmbDrives.Items.Add(drive.Name);
                   }
                   _cmbDrives.SelectedIndex = mediaWriter.CurrentDriveNumber + 1;
                }
                
    

  10. Add an event handler to the _cmbDrives SelectedIndexChanged event and add the following code:

    [Visual Basic]

                Private Sub _cmbDrives_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
                   mediaWriter.CurrentDriveNumber = _cmbDrives.SelectedIndex - 1
                   If Not burnerDrive Is Nothing Then
                      burnerDrive.OnDeviceEvent -= burnerDrive_OnDeviceEvent
                   End If
                   burnerDrive = mediaWriter.CurrentDrive
                   'Only add device event for valid drives
                   If burnerDrive.DriveNumber <> -1 Then
                      AddHandler burnerDrive.OnDeviceEvent, AddressOf Of MediaWriterDevNotifyEventArgs
                   End If
                   _btnWrite.Enabled = burnerDrive.Writeable
                End Sub
                
    

    [C#]

                private void _cmbDrives_SelectedIndexChanged(object sender, System.EventArgs e)
                {
                   mediaWriter.CurrentDriveNumber = _cmbDrives.SelectedIndex - 1;
                   if (burnerDrive != null)
                      burnerDrive.OnDeviceEvent -= burnerDrive_OnDeviceEvent; 
                   burnerDrive = mediaWriter.CurrentDrive;
                   //Only add device event for valid drives
                   if (burnerDrive.DriveNumber != -1)
                      burnerDrive.OnDeviceEvent += new EventHandler<MediaWriterDevNotifyEventArgs>(burnerDrive_OnDeviceEvent);
                   _btnWrite.Enabled = burnerDrive.Writeable;
                }
                
    

  11. Add an event handler to the _btnWrite Click event and add the following code:

    [Visual Basic]

                Private void Function btnWrite_Click(ByVal sender As Object, ByVal e As System.EventArgs) As _
                   If String.IsNullOrEmpty(_txtInput.Text) Then
                      MessageBox.Show("You must choose an input file" & Constants.vbFormFeed & "older")
                      Return
                   End If
                   Dim burnDisc As MediaWriterDisc = burnerDrive.CreateDisc()
                   burnDisc.SourcePathName = _txtInput.Text
                   burnDisc.VolumeName = "LEAD Media"
                   burnerDrive.BurnDisc(burnDisc)
                   Me.Text = "Writing"
                   Do While burnerDrive.State = MediaWriterState.StateWriting
                      'Loop until complete
                      Application.DoEvents()
                   Loop
                   this.Text = "Complete";
                   MessageBox.Show("Complete")
                End Function
                
    

    [C#]

                private void _ btnWrite_Click(object sender, System.EventArgs e)
                {
                   if (String.IsNullOrEmpty(_txtInput.Text))
                   {
                      MessageBox.Show("You must choose an input file\folder");
                      return;
                   }
                   MediaWriterDisc burnDisc = burnerDrive.CreateDisc();
                   burnDisc.SourcePathName = _txtInput.Text;
                   burnDisc.VolumeName = "LEAD Media";
                   burnerDrive.BurnDisc(burnDisc);
                   this.Text = "Writing";
                   while (burnerDrive.State == MediaWriterState.StateWriting)
                   {
                      //Loop until complete
                      Application.DoEvents();
                   }
                   this.Text = "Complete";
                   MessageBox.Show("Complete");
                }
                
    

  12. [Visual Basic]

                Private Sub burnerDrive_OnDeviceEvent(ByVal sender As Object, ByVal e As MediaWriterDevNotifyEventArgs)
                   _btnWrite.Enabled = burnerDrive.Writeable
                End Sub
                
    

    [C#]

                void burnerDrive_OnDeviceEvent(object sender, MediaWriterDevNotifyEventArgs e)
                {
                   _btnWrite.Enabled = burnerDrive.Writeable;
                }
                
    

  13. Build, and Run the program to test it.

    Select your burner from the drives list, fill the textbox with the path to a valid ISO image or directory of files, and click the "Write" button.