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.

  2. Choose File->New->Project… from the menu.

  3. In the New Project dialog box, choose either "Visual C# Projects" or "VB 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:

    VB
    Imports Leadtools 
    Imports Leadtools.MediaWriter 
    C#
          
    using Leadtools; 
    using Leadtools.MediaWriter; 

  8. Add the following class level variables::

    VB
    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:

    VB
    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:

    VB
    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:

    VB
    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. Add the following class function.

    VB
    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.

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document