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:
using Leadtools;
using Leadtools.MediaWriter;
Add the following class level variables::
MediaWriter mediaWriter;
MediaWriterDrive burnerDrive;
Add an event handler to the Form1 Load event and add the following code:
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 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 _ 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.
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.