From 70f3923f47f1abdc9fdb541dfe78a90f07b524e2 Mon Sep 17 00:00:00 2001 From: MathanKumarVaradhaRajaPerumal <92992128+MathanKumarVaradhaRajaPerumal@users.noreply.github.com> Date: Thu, 13 Aug 2026 22:32:24 +0530 Subject: [PATCH] Revert "Revert "Updated GitHub examples for split sections to ZIP Output files"" --- .../Split-PowerPoint-by-sections/Program.cs | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Sections/Split-PowerPoint-by-Sections/.NET/Split-PowerPoint-by-sections/Program.cs b/Sections/Split-PowerPoint-by-Sections/.NET/Split-PowerPoint-by-sections/Program.cs index 267190db..4d7cc281 100644 --- a/Sections/Split-PowerPoint-by-Sections/.NET/Split-PowerPoint-by-sections/Program.cs +++ b/Sections/Split-PowerPoint-by-Sections/.NET/Split-PowerPoint-by-sections/Program.cs @@ -1,22 +1,39 @@ -using Syncfusion.Presentation; +// Create a ZIP archive and set the compression level to Best. +using Syncfusion.Presentation; +using Syncfusion.Compression.Zip; -//Opens the source PPTX document. +ZipArchive zipArchive = new ZipArchive(); +zipArchive.DefaultCompressionLevel = Syncfusion.Compression.CompressionLevel.Best; + +// Open the source PowerPoint presentation. IPresentation sourcePptx = Presentation.Open(Path.GetFullPath(@"Data/Template.pptx")); -//Iterates through each section. +// Iterate through each section in the presentation. foreach (ISection section in sourcePptx.Sections) { - //Creates a destination PPTX document. Existing presentations can also be used here. + // Create a new destination presentation for the current section. IPresentation destinationPptx = Presentation.Create(); - // Clone the slides from the section and move to new PPTX document. + + // Clone all slides from the current section and add them to the new presentation. foreach (ISlide slide in section.Slides) { destinationPptx.Slides.Add(slide.Clone(), PasteOptions.SourceFormatting, sourcePptx); } - //Saves the destination PPTX document. - string outputPath = Path.Combine(Path.GetFullPath("Output"), section.Name + "_Slides.pptx"); - destinationPptx.Save(outputPath); + // Save the section presentation to a memory stream. + MemoryStream memoryStream = new MemoryStream(); + destinationPptx.Save(memoryStream); + + // Add the generated presentation to the ZIP archive with the section name as the file name. + string outputPath = Path.Combine(section.Name + "_Slides.pptx"); + zipArchive.AddItem(outputPath, memoryStream, true, Syncfusion.Compression.FileAttributes.Normal); + + // Close the destination presentation. destinationPptx.Close(); } -//Closes the PPTX document. + +// Save the ZIP archive containing all section presentations. +zipArchive.Save(Path.GetFullPath(@"Output/Split-PowerPoint-by-sections.zip")); +// Close the ZIP archive. +zipArchive.Close(); +// Close the source presentation. sourcePptx.Close(); \ No newline at end of file