The code is using the pinvoke to call win32 imapi2fs api. To add a directory see
Burn Selected Folders/Files in CD-Rom
Dani_S
3,911
Reputation points
Hi,
I have treeview of drive/folders + files as you see .
While pressing on copy command I copied the selected files to temp folder.
I want code that will burn this files with all folder structure not only the files to CD-ROM.
Can you please supply all code ?
Thanks in advance,
1.I found this code in ChatGPT , it handel only files with no folders structure !!
how can i fixed it.
2.Does this code also take will work with impersonation?
using System;
using System.IO;
using System.Runtime.InteropServices;
using IMAPI2.Interop;
namespace CD_Burner
{
class Program
{
static void Main(string[] args)
{
// Set up the IMAPI2 interfaces for writing
IDiscFormat2Data discFormat = new DiscFormat2Data();
IDiscRecorder2 discRecorder = new DiscRecorder2();
IDiscMaster2 discMaster = new DiscMaster2();
try
{
// Initialize the Disc Recorder
string[] availableDevices = discMaster.GetDiscs();
discRecorder = discMaster.Item(0); // Select the first available device
// Prepare the data for burning
string[] filesToBurn = Directory.GetFiles(@"C:\Path\To\Your\Files");
// Create a writeable image of the files
IFileSystemImage fileSystemImage = new FileSystemImage();
foreach (var file in filesToBurn)
{
fileSystemImage.AddFile(file);
}
// Begin the burn process
discFormat.WriteMedia(fileSystemImage, discRecorder);
Console.WriteLine("Burning completed successfully!");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
}