Perform the following steps to start a project and to add some code that burns an ISO file or a directory of files to disc.
Start Visual Studio.
Choose File->New->Project… from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Form Application" in the Templates List.
Type the project name as "Burn ISO and CD_DVD Files" in the Project Name field, and then click OK. If desired, type a new location for your project or click the Browse button, and navigate to a new location. Click OK.
In the "Solution Explorer" window, right-click the "References" folder, and choose "Add Reference…" from the context menu. In the "Add Reference" dialog box, click the ".NET" tab and navigate to the LEADTOOLS For .NET ("<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32") folder and select the following DLLs:
With the DLLs selected, click OK to add the above DLLs to the application.
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and add the following controls to the form.
Switch to Form1 code view (right-click Form1 in the Solution Explorer and then choose View Code ) and add the following lines to the beginning of the file:
Imports Leadtools
Imports Leadtools.MediaWriter
using Leadtools;
using Leadtools.MediaWriter;
Add the following class level variables::
Dim mediaWriter as MediaWriter
Dim burnerDrive as MediaWriterDrive
MediaWriter mediaWriter;
MediaWriterDrive burnerDrive;
Add an event handler to the Form1 Load event and add the following code:
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
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;
}
Add an event handler to the _cmbDrives SelectedIndexChanged event and add the following code:
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
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;
}
Add an event handler to the _btnWrite Click event and add the following code:
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
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");
}
Add the following class function.
Private Sub burnerDrive_OnDeviceEvent(ByVal sender As Object, ByVal e As MediaWriterDevNotifyEventArgs)
_btnWrite.Enabled = burnerDrive.Writeable
End Sub
void burnerDrive_OnDeviceEvent(object sender, MediaWriterDevNotifyEventArgs e)
{
_btnWrite.Enabled = burnerDrive.Writeable;
}
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.